BV 1-wire: don't search when data line is not high

This commit is contained in:
King Kévin 2018-06-16 11:06:24 +02:00
parent 867aef09e3
commit b92273bc3e
1 changed files with 10 additions and 2 deletions

View File

@ -334,7 +334,8 @@ static void busvoodoo_onewire_rom_search(void* argument)
gpio_set_mode(GPIO(ONEWIRE_MASTER_PORT), GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO(ONEWIRE_MASTER_PIN)); // remove power from data line
}
if (!gpio_get(GPIO(ONEWIRE_MASTER_PORT), GPIO(ONEWIRE_MASTER_PIN))) {
printf("WARNING: data line does not seem to be pulled up\n");
printf("WARNING: the data line needs to be pulled up\n");
return;
}
bool presence = onewire_master_reset(); // send reset pulse and detect slave presence
printf("slave presence %sdetected\n", presence ? "" : "not ");
@ -346,13 +347,20 @@ static void busvoodoo_onewire_rom_search(void* argument)
do { // search until all has been found
busvoodoo_led_blue_pulse(BUSVOODOO_LED_PULSE); // pulse blue LED to show we are scanning
next = onewire_master_rom_search(&code, alarm); // search for the code
if (0==code && !gpio_get(GPIO(ONEWIRE_MASTER_PORT), GPIO(ONEWIRE_MASTER_PIN))) { // searching for ROM codes does not work when the line is not pulled up
printf("not able to search for ROM codes when the data line is not pulled up\n");
break;
}
if (next) {
presence = onewire_master_reset(); // send reset pulse and detect slave presence for the next slave
}
printf("0x%016X\n", code);
codes++; // remember we found a code
} while (presence && next);
} while (presence && next && !user_input_available);
printf("%U ROM code(s)%s found\n", codes, alarm ? " with alarm" : "");
if (user_input_available) { // user interrupted flow
user_input_get(); // discard user input
}
}
if (busvoodoo_onewire_power) {
gpio_set_mode(GPIO(ONEWIRE_MASTER_PORT), GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(ONEWIRE_MASTER_PIN)); // provide power on data line