From 63d3d2985216a080a1bab91e3f34bfa1f57cf77b Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Sun, 11 Sep 2016 20:33:38 +0200 Subject: [PATCH] second edition nearly working --- docs/tea.txt | 2 ++ src/display.c | 25 ++++++++++++++----------- src/eggTimer.c | 16 ++++++---------- src/gpio.h | 2 +- src/gpioCfg.c | 2 +- src/main.c | 32 +++----------------------------- src/powerDown.c | 23 +++++++++++++++++++++++ src/powerDown.h | 14 ++++++++++++++ 8 files changed, 64 insertions(+), 52 deletions(-) create mode 100644 src/powerDown.c create mode 100644 src/powerDown.h diff --git a/docs/tea.txt b/docs/tea.txt index 11e7f8e..3e7fe28 100644 --- a/docs/tea.txt +++ b/docs/tea.txt @@ -7,6 +7,8 @@ P2.2 G P2.1 C P2.0 1 P1.5 2 +P1.2 3 +P1.1 LED P1.0 T diff --git a/src/display.c b/src/display.c index f552e72..204cc0d 100644 --- a/src/display.c +++ b/src/display.c @@ -47,15 +47,15 @@ const tPin *NUMBERS[] = { NUMBER0, NUMBER1, NUMBER2, NUMBER3, NUMBER4, NUMBER5, NUMBER6, NUMBER7, NUMBER8, NUMBER9, ALL_PATTERN, H_PATTERN, I_PATTERN, EMPTY_PATTERN }; -const tPin DIGITS[] = { DIGIT_0, DIGIT_1, PINS_END }; +const tPin DIGITS[] = { DIGIT_0, DIGIT_1, DIGIT_2, PINS_END }; -uint8_t digitValues[2] = { EMPTY_ID, EMPTY_ID }; +uint8_t digitValues[] = { EMPTY_ID, EMPTY_ID, EMPTY_ID }; void displayInit(void *handleArg) { - for (tPin d = DIGIT_0; d <= DIGIT_1; d++) { + for (tPin d = DIGIT_0; d <= DIGIT_2; d++) { gpioSetPin(d, LOW); for (tPin s = SEG_A; s <= SEG_G; s++) { gpioSetPin(s, HIGH); @@ -80,20 +80,23 @@ static void showNumber(uint8_t n) { } void displaySetValue(uint8_t v) { - if (v >= 100) { - digitValues[1] = H_ID; - digitValues[0] = I_ID; - } else { - digitValues[1] = v / 10; - digitValues[0] = v - digitValues[1] * 10; - } + uint32_t a,b,c,d; + a = v; + b = a / 100; + c = (a - b * 100) / 10; + d = a - c * 10 - b * 100; + b = (b == 0) ? EMPTY_ID : b; + c = (c == 0) ? EMPTY_ID : c; + digitValues[2] = (uint8_t)b; + digitValues[1] = (uint8_t)c; + digitValues[0] = (uint8_t)d; } void displayExec(void *handleArg) { static uint8_t activeDigit = 0; activeDigit++; - if (activeDigit == 2) { + if (activeDigit == 3) { activeDigit = 0; } diff --git a/src/eggTimer.c b/src/eggTimer.c index f3f1538..8ff3bdd 100644 --- a/src/eggTimer.c +++ b/src/eggTimer.c @@ -16,11 +16,12 @@ #include "button.h" #include "gpio.h" #include "PontCoopScheduler.h" +#include "powerDown.h" const uint32_t EGG_TIMER_CYCLE = 1000; const uint32_t LED_CYCLE = 250; -const uint32_t POWER_DOWN_DELAY = 120000; +const uint32_t MY_POWER_DOWN_DELAY = 120000; const uint8_t COOKING_TIME = 120; uint8_t restCookingTime; @@ -28,14 +29,8 @@ bool timerRunning; bool timerStarted; -void eggTimerPowerDown(void *handleArg) { - P1DIR = 0; - P2DIR = 0; - P1OUT = 0; - P2OUT = 0; - ADC10CTL0 = 0; - LPM4; -} + + void eggTimerStart(void *handleArg) { if (! timerStarted) { @@ -62,7 +57,8 @@ void eggTimerExec(void *handleArg) { if (restCookingTime == 0) { // activate alarm schAdd(eggTimerAlarm, NULL, 0, LED_CYCLE); - schAdd(eggTimerPowerDown, NULL, POWER_DOWN_DELAY, 0); + schDel(powerDown, NULL); + schAdd(powerDown, NULL, MY_POWER_DOWN_DELAY, 0); timerRunning = false; } } diff --git a/src/gpio.h b/src/gpio.h index eaddff1..cf0c114 100644 --- a/src/gpio.h +++ b/src/gpio.h @@ -49,9 +49,9 @@ typedef enum { SEG_G, DIGIT_0, DIGIT_1, + DIGIT_2, BUTTON_1, LED_1, - POWER, PINS_END } tPin; diff --git a/src/gpioCfg.c b/src/gpioCfg.c index dba83b5..172f8d2 100644 --- a/src/gpioCfg.c +++ b/src/gpioCfg.c @@ -18,7 +18,7 @@ tPinCfg pinCfg[PINS_END] = { {PORT2, BIT2, PIN_OUT, LOW}, //G {PORT2, BIT0, PIN_OUT, HIGH}, //0 {PORT1, BIT5, PIN_OUT, HIGH}, //1 + {PORT1, BIT2, PIN_OUT, HIGH}, //2 {PORT1, BIT0, PIN_IN_PULLUP, LOW}, // BUTTON_1 {PORT1, BIT1, PIN_OUT, LOW}, // LED_1 - {PORT1, BIT2, PIN_OUT, HIGH}, // POWER }; diff --git a/src/main.c b/src/main.c index e8bfc69..0b9e565 100644 --- a/src/main.c +++ b/src/main.c @@ -20,21 +20,10 @@ #include "eggTimer.h" #include "button.h" #include "gpio.h" +#include "powerDown.h" -void powerDown(void *handleArg) { - P1OUT = 0; - P1DIR = 0xff; - P1REN = 0; - P2OUT = 0; - P2DIR = 0xff; - P2REN = 0; - ADC10CTL0 = 0; - - LPM4; - while (1); -} int main() { WDTCTL = WDTPW | WDTHOLD; @@ -50,18 +39,8 @@ int main() { timeInit(); schInit(); + schAdd(powerDown, NULL, 600000, 0); - schAdd(eggTimerAlarm, NULL, 0, 37); - schAdd(powerDown, NULL, 5000, 0); - - - - - - - - -#if 0 // interrupts are required for delay function in displayInit(); __enable_interrupt(); displayInit(NULL); @@ -78,17 +57,12 @@ int main() { schAdd(eggTimerExec, NULL, 0, EGG_TIMER_CYCLE); schAdd(buttonExec, NULL, 0, BUTTON_CYCLE); -#endif + __enable_interrupt(); while (1) { schExec(); LPM3; - - // put it into the idle loop, it is not time critical - // but should get as much time as possible to avoid - // flicker - //displayExec(NULL); } } diff --git a/src/powerDown.c b/src/powerDown.c new file mode 100644 index 0000000..ac1edf6 --- /dev/null +++ b/src/powerDown.c @@ -0,0 +1,23 @@ +/* + * powerDown.c + * + * Created on: Sep 11, 2016 + * Author: wn + */ + + +#include + + +void powerDown(void *handleArg) { + P1OUT = 0; + P1DIR = 0xff; + P1REN = 0; + P2OUT = 0; + P2DIR = 0xff; + P2REN = 0; + ADC10CTL0 = 0; + + LPM4; + while (1); +} diff --git a/src/powerDown.h b/src/powerDown.h new file mode 100644 index 0000000..121c51c --- /dev/null +++ b/src/powerDown.h @@ -0,0 +1,14 @@ +/* + * powerDown.h + * + * Created on: Sep 11, 2016 + * Author: wn + */ + +#ifndef POWERDOWN_H_ +#define POWERDOWN_H_ + +void powerDown(void *handleArg); + + +#endif /* POWERDOWN_H_ */