summaryrefslogtreecommitdiff
path: root/digital/beacon/src
diff options
context:
space:
mode:
authorFlorent Duchon2012-04-22 22:37:43 +0200
committerFlorent Duchon2012-05-04 00:06:27 +0200
commitada3d26e47f5a568cb1dd6196d622a33623138d2 (patch)
tree14e39f038eb6ed424ff01da40d8cf187b7829b60 /digital/beacon/src
parent5b1422b28f7691ac8f2ff3f8b59479d95741426c (diff)
digital/beacon: add codewheel representation states
Diffstat (limited to 'digital/beacon/src')
-rw-r--r--digital/beacon/src/codewheel.c15
-rw-r--r--digital/beacon/src/codewheel.h20
2 files changed, 35 insertions, 0 deletions
diff --git a/digital/beacon/src/codewheel.c b/digital/beacon/src/codewheel.c
index 32b45b37..84ca69f6 100644
--- a/digital/beacon/src/codewheel.c
+++ b/digital/beacon/src/codewheel.c
@@ -28,10 +28,14 @@
#include "debug_avr.h"
#include "codewheel.h"
+codewheel_s codewheel;
/* This function initializes the codewheel optical sensors and associated interrupt */
void codewheel_init(void)
{
+ /* Set codewheel state*/
+ codewheel_set_state(CODEWHEEL_INIT);
+
/* Select external clock on rising edge for timer 3 */
TCCR3B |= (1<<CS30)|(1<<CS31)|(1<<CS32);
@@ -46,6 +50,17 @@ void codewheel_init(void)
sei();
}
+/* This function returns the codewheel state */
+TCodewheel_state codewheel_get_state(void)
+{
+ return codewheel.state;
+}
+
+/* This function modify the codewheel state */
+void codewheel_set_state(TCodewheel_state state)
+{
+ codewheel.state = state;
+}
/* This function returns the wheel position */
uint16_t codewheel_get_value(void)
diff --git a/digital/beacon/src/codewheel.h b/digital/beacon/src/codewheel.h
index a0ff00bd..57b4a7b5 100644
--- a/digital/beacon/src/codewheel.h
+++ b/digital/beacon/src/codewheel.h
@@ -28,9 +28,29 @@
#define CODEWHEEL_CPR 499
+typedef enum
+{
+ CODEWHEEL_INIT,
+ CODEWHEEL_REQUEST_REBASE,
+ CODEWHEEL_REBASED
+} TCodewheel_state;
+
+typedef struct
+{
+ TCodewheel_state state;
+ uint16_t rebase_offset;
+} codewheel_s;
+
/* This function initializes the codewheel optical sensors and associated interrupt */
void codewheel_init(void);
+
+/* This function returns the codewheel state */
+TCodewheel_state codewheel_get_state(void);
+
+/* This function modify the codewheel state */
+void codewheel_set_state(TCodewheel_state state);
+
/* This function returns the wheel position */
uint16_t codewheel_get_value(void);