From 2f59686fb3c53fc5d0f884e821db5a0b1f4bee72 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Tue, 17 Jun 2014 15:40:47 +0200 Subject: Translate LED id’s based on orientation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit And fix orientation change detection. --- ui.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'ui.c') 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: -- cgit v1.2.3