Skip to content

Commit

Permalink
Merge pull request #125 from RoboSchmied/RoboSchmied-refactor_i2cdetect
Browse files Browse the repository at this point in the history
refactoring i2cdetect makes it 2 times faster (on goke)
  • Loading branch information
dimerr authored Apr 1, 2024
2 parents d72a145 + fc8ff7a commit f53f740
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/i2cspi.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ static int i2cdetect(int argc, char **argv, bool script_mode) {
unsigned char i2c_addr;

printf(" 0 1 2 3 4 5 6 7 8 9 a b c d e f\n");
int fd = prepare_i2c_sensor(0x00);
i2c_addr = 0xff; // will be 0x00 after first increment
do {
++i2c_addr;
int fd = prepare_i2c_sensor(i2c_addr);
int res = i2c_read_register(fd, i2c_addr, 0, SELECT_WIDE(0), 1);

if (i2c_addr % 16 == 0)
Expand All @@ -221,10 +221,10 @@ static int i2cdetect(int argc, char **argv, bool script_mode) {
printf("| \n");
}

close_sensor_fd(fd);
hal_cleanup();
} while (i2c_addr != 0xff);

close_sensor_fd(fd);
hal_cleanup();
printf("\n");

return EXIT_SUCCESS;
Expand Down

0 comments on commit f53f740

Please sign in to comment.