1919#include "sensors.h"
2020#include "tools.h"
2121
22+ #define MAX_i2c_NUMBER 5
23+
2224static read_register_t sensor_read_register ;
2325static write_register_t sensor_write_register ;
2426
@@ -971,7 +973,7 @@ static int detect_possible_sensors(sensor_ctx_t *ctx, int fd,
971973
972974static bool get_sensor_id_i2c (sensor_ctx_t * ctx ) {
973975 bool detected = false;
974- int fd = open_i2c_sensor_fd ();
976+ int fd = open_i2c_sensor_fd (i2c_adapter_nr );
975977 if (fd == -1 )
976978 return false;
977979
@@ -1045,10 +1047,12 @@ static bool get_sensor_id_spi(sensor_ctx_t *ctx) {
10451047}
10461048
10471049bool getsensorid (sensor_ctx_t * ctx ) {
1050+
1051+ int current_i2c_adapter_nr ;
10481052 if (!getchipname ())
10491053 return NULL ;
10501054 // there is no platform specific i2c/spi access layer
1051- if (!open_i2c_sensor_fd )
1055+ if (!open_i2c_sensor_fd ( i2c_adapter_nr ) )
10521056 return NULL ;
10531057
10541058 // Use common settings as default
@@ -1064,8 +1068,44 @@ bool getsensorid(sensor_ctx_t *ctx) {
10641068 bool spi_detected = get_sensor_id_spi (ctx );
10651069 if (spi_detected ) {
10661070 strcpy (ctx -> control , "spi" );
1071+ return spi_detected ;
1072+ }
1073+ puts ("try hard sensor search" );
1074+
1075+ current_i2c_adapter_nr = i2c_adapter_nr ;
1076+
1077+ for (int i = 0 ; i <= MAX_i2c_NUMBER ; i ++ ) {
1078+ if (i == current_i2c_adapter_nr ) {
1079+ continue ; // Skip the current value
10671080 }
1068- return spi_detected ;
1081+ // printf("Checking adapter: %d\n", i);
1082+ i2c_adapter_nr = i ;
1083+ // printf("try i2c_%d \n", i2c_adapter_nr);
1084+
1085+ if (!open_i2c_sensor_fd (i2c_adapter_nr ))
1086+ return NULL ;
1087+
1088+ // Use common settings as default
1089+ ctx -> data_width = 1 ;
1090+ ctx -> reg_width = 2 ;
1091+
1092+ i2c_detected = get_sensor_id_i2c (ctx );
1093+ if (i2c_detected ) {
1094+ strcpy (ctx -> control , "i2c" );
1095+ return true;
1096+ }
1097+
1098+ spi_detected = get_sensor_id_spi (ctx );
1099+ if (spi_detected ) {
1100+ strcpy (ctx -> control , "spi" );
1101+ return spi_detected ;
1102+ }
1103+ puts ("sensor not detected again1" );
1104+
1105+
1106+ }
1107+
1108+
10691109}
10701110
10711111#ifndef STANDALONE_LIBRARY
0 commit comments