summaryrefslogtreecommitdiff
path: root/digital/io
diff options
context:
space:
mode:
authorJérémy Dufour2008-05-02 12:42:50 +0200
committerJérémy Dufour2008-05-02 12:42:50 +0200
commita6abcfa716cf6252efd94ba3628a4ea71a08d0e8 (patch)
tree170e7fde4367f9d10ba63b510f6f128fd393bcb0 /digital/io
parent59f672a1c598dade740f92b9daa040db2dc5d46f (diff)
* digital/io/src
- add a function to know when we are near the end of the match
Diffstat (limited to 'digital/io')
-rw-r--r--digital/io/src/chrono.c18
-rw-r--r--digital/io/src/chrono.h10
2 files changed, 28 insertions, 0 deletions
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
@@ -55,6 +55,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 */