Skip to content

Commit

Permalink
Wait for stable voltage level only if pull-ups were switched on now.
Browse files Browse the repository at this point in the history
  • Loading branch information
breaker27 committed Jun 5, 2014
1 parent a3eea43 commit a39a990
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions firmware/shc_envsensor/shc_envsensor.c
Expand Up @@ -206,17 +206,23 @@ void init_di_sensor(void)
void measure_digital_input(void)
{
uint8_t i;
bool wait_pullups = false;

for (i = 0; i < 8; i++)
{
if ((di[i].pull_up)&&(di[i].mode!=DIGITALINPUTMODE_ONCHANGE))
if ((di[i].pull_up) && (di[i].mode != DIGITALINPUTMODE_ONCHANGE))
{
setPullUp(di[i].port, di[i].pin);
wait_pullups = true;
}
}

_delay_ms(50); // wait a little bit to let the voltage level settle down

// wait a little bit to let the voltage level settle down in case pullups were just switched on
if (wait_pullups)
{
_delay_ms(10);
}

for (i = 0; i < 8; i++)
{
if (di[i].port != DI_UNUSED)
Expand All @@ -239,7 +245,7 @@ void measure_digital_input(void)

for (i = 0; i < 8; i++)
{
if ((di[i].pull_up)&&(di[i].mode!=DIGITALINPUTMODE_ONCHANGE))
if ((di[i].pull_up) && (di[i].mode != DIGITALINPUTMODE_ONCHANGE))
{
clearPullUp(di[i].port, di[i].pin);
}
Expand Down

0 comments on commit a39a990

Please sign in to comment.