From a6abcfa716cf6252efd94ba3628a4ea71a08d0e8 Mon Sep 17 00:00:00 2001 From: Jérémy Dufour Date: Fri, 2 May 2008 12:42:50 +0200 Subject: * digital/io/src - add a function to know when we are near the end of the match --- digital/io/src/chrono.c | 18 ++++++++++++++++++ digital/io/src/chrono.h | 10 ++++++++++ 2 files changed, 28 insertions(+) (limited to 'digital') diff --git a/digital/io/src/chrono.c b/digital/io/src/chrono.c index 8a719860..051f8670 100644 --- a/digital/io/src/chrono.c +++ b/digital/io/src/chrono.c @@ -54,6 +54,14 @@ */ #define CHRONO_WAIT_BEFORE_RESET 1000 +/** + * Number of overflow to count before saying we are near the end of the match. + * You can compute it using the following formula: + * CHRONO_OVERFLOW_MAX * seconds / 90 + */ +#define CHRONO_OVERFLOW_COUNT_NEAR_END_MATCH \ + ((uint8_t) (CHRONO_OVERFLOW_MAX * 65 / 90)) + /** * Match is finished. * This variable will be set to 1 when the match is over. @@ -174,3 +182,13 @@ chrono_end_match (uint8_t block) #endif ; } + +/* Are we near the end of the match. */ +uint8_t +chrono_near_end_match (void) +{ + /* If we have overflow a certain number of time */ + if (chrono_ov_count_ >= CHRONO_OVERFLOW_COUNT_NEAR_END_MATCH) + return 1; + return 0; +} diff --git a/digital/io/src/chrono.h b/digital/io/src/chrono.h index fc715d6d..f8a5a308 100644 --- a/digital/io/src/chrono.h +++ b/digital/io/src/chrono.h @@ -64,4 +64,14 @@ chrono_is_match_over (void); void chrono_end_match (uint8_t block); +/** + * Are we near the end of the match. + * This function tell you when there is not much time remaining. + * @return + * - 0 not near the end of the match + * - 1 near the end of the match + */ +uint8_t +chrono_near_end_match (void); + #endif /* chrono_h */ -- cgit v1.2.3