In case the runtime calculated at the end of the loop is greater
than 9900 ms, the calculated sleeptime underflows. Being it an
unsigned long, the resulting value would be about 2^32
milliseconds (about 50 days). This value is used as parameter
in a delay() function to wait for the next acqusition cycle, if
AC-AC adapter is used.
Even in case of battery powered system, the time calculated
inside the Sleepy::loseSomeTime() function could underflow if
sleeptime is smaller than 500 ms. Being the parameter a word,
the resulting value would be about 2^16 (about 65 seconds).
This patch avoids both the underflows.
In case of underflow, a delay(0) or a Sleepy::loseSomeTime(0)
is executed, bringing the system to immediately start the next
acquisition cycle.
In case the runtime calculated at the end of the loop is greater than 9900 ms, the calculated sleeptime underflows. Being it an unsigned long, the resulting value would be about 2^32 milliseconds (about 50 days). This value is used as parameter in a delay() function to wait for the next acqusition cycle, if AC-AC adapter is used. Even in case of battery powered system, the time calculated inside the Sleepy::loseSomeTime() function could underflow if sleeptime is smaller than 500 ms. Being the parameter a word, the resulting value would be about 2^16 (about 65 seconds).
This patch avoids both the underflows. In case of underflow, a delay(0) or a Sleepy::loseSomeTime(0) is executed, bringing the system to immediately start the next acquisition cycle.
Signed-off-by: Roberto Bonacina roby.bonacina@gmail.com