aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2014-06-17 15:40:47 +0200
committerLars-Dominik Braun <lars@6xq.net>2014-06-17 15:40:47 +0200
commit2f59686fb3c53fc5d0f884e821db5a0b1f4bee72 (patch)
treeabb09274e955d3bfa5df060719e7afdf99ecde50
parentd664b474657eff9988c14b40e5d050dc5571f778 (diff)
downloadhourglass-2f59686fb3c53fc5d0f884e821db5a0b1f4bee72.tar.gz
hourglass-2f59686fb3c53fc5d0f884e821db5a0b1f4bee72.tar.bz2
hourglass-2f59686fb3c53fc5d0f884e821db5a0b1f4bee72.zip
Translate LED id’s based on orientation
And fix orientation change detection.
-rw-r--r--ui.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/ui.c b/ui.c
index 0c2bb2c..3ecdfca 100644
--- a/ui.c
+++ b/ui.c
@@ -48,34 +48,44 @@ static void processSensors () {
checkGyro = !checkGyro;
}
+/* Translate LED ids based on horizon, id 0 is always at the bottom of the
+ * device */
+static uint8_t horizonLed (uint8_t i) {
+ if (h == HORIZON_NEG) {
+ return i;
+ } else {
+ return 5-i;
+ }
+}
+
/*
* We use the following LED coding (top to bottom):
* 1-5 minutes: (off) (5m ) (4m ) (3m ) (2m ) (1m )
* 5-60 minutes: (on ) (50m) (40m) (30m) (20m) (10m)
*/
static void updateLeds () {
- /* XXX: orientation */
if (seconds <= 5*60) {
const uint8_t minutes = seconds / 60;
for (uint8_t i = 0; i < minutes; i++) {
- pwmSetBlink (i, PWM_BLINK_ON);
+ pwmSetBlink (horizonLed (i), PWM_BLINK_ON);
}
/* 10 second steps */
- pwmSetBlink (minutes, (seconds - minutes*60)/10);
+ pwmSetBlink (horizonLed (minutes), (seconds - minutes*60)/10);
for (uint8_t i = minutes+1; i < 6; i++) {
- pwmSetBlink (i, PWM_BLINK_OFF);
+ pwmSetBlink (horizonLed (i), PWM_BLINK_OFF);
}
} else {
const uint8_t tenminutes = seconds/60/10;
for (uint8_t i = 0; i < tenminutes; i++) {
- pwmSetBlink (i, PWM_BLINK_ON);
+ pwmSetBlink (horizonLed (i), PWM_BLINK_ON);
}
/* 2 minute steps */
- pwmSetBlink (tenminutes, (seconds - tenminutes*10*60)/60/2);
+ pwmSetBlink (horizonLed (tenminutes),
+ (seconds - tenminutes*10*60)/60/2);
for (uint8_t i = tenminutes+1; i < 5; i++) {
- pwmSetBlink (i, PWM_BLINK_OFF);
+ pwmSetBlink (horizonLed (i), PWM_BLINK_OFF);
}
- pwmSetBlink (5, PWM_BLINK_ON);
+ pwmSetBlink (horizonLed (5), PWM_BLINK_ON);
}
}
@@ -192,6 +202,7 @@ void uiLoop () {
} else {
horizonChanged = false;
}
+ h = newh;
switch (mode) {
case UIMODE_INIT: