From 54a6ee1cd1d3977477ddbd273d31821fc58ac61c Mon Sep 17 00:00:00 2001 From: Dirk Jahnke Date: Mon, 27 Nov 2017 06:47:27 +0100 Subject: [PATCH] Animation works with default animation --- bak/animateLights-bak.js | 352 ------------------------------------- bak/animateLights.js | 371 --------------------------------------- bak/animationConfig.js | 30 ---- bak/api_ledlights.js | 10 -- bak/init-bak.js | 57 ------ bak/lights.cfg | 29 --- bak/test.js | 33 ---- fs/init.js | 125 ++++++++++++- mos.yml | 5 +- src/LEDDefinition.c | 26 +++ src/LEDDefinition.h | 8 +- src/LEDState.c | 66 +++++-- src/LEDState.h | 9 +- src/main.c | 13 +- 14 files changed, 216 insertions(+), 918 deletions(-) delete mode 100644 bak/animateLights-bak.js delete mode 100755 bak/animateLights.js delete mode 100644 bak/animationConfig.js delete mode 100644 bak/api_ledlights.js delete mode 100644 bak/init-bak.js delete mode 100755 bak/lights.cfg delete mode 100644 bak/test.js diff --git a/bak/animateLights-bak.js b/bak/animateLights-bak.js deleted file mode 100644 index 461735d..0000000 --- a/bak/animateLights-bak.js +++ /dev/null @@ -1,352 +0,0 @@ -/* animateLights.js - * LED animation for house lightning - */ - -load('api_rpc.js'); -load("api_neopixel.js"); -load("api_file.js"); - -let floor = ffi('double floor(double)'); - -let colors = { - black: {r:0, g:0, b:0}, - red: {r:255, g:0, b:0}, - green: {r:0, g:255, b:0}, - blue: {r:0, g:0, b:255}, - yellow: {r:255, g:255, b:0}, - orange: {r:255, g:127, b:0}, - purple: {r:255, g:0, b:255}, - white: {r:255, g:255, b:255}, - dimmedWhite: {r:50, g:50, b:50} -}; - - -let LightAnimation = { - numberOfBulbs: 22, - ledPin: 2, - that: this, - running: false, - mode: "demo", // "demo", "stop", "animate" - generalBrightness: 30, // percentage, value 0..100 - description: "Default house lightning", - defaultColor: colors.dimmedWhite, - defaultMode: "demo", - tickResolution: 100, // number of milliseconds between ticks - currentTick: 0, - animationConfig: {}, // overwritten when loading animationConfig.js - colorSequence: [ - colors.dimmedWhite, - colors.red, - colors.green, - colors.blue, - colors.yellow, - colors.orange, - colors.purple, - colors.red, - colors.red, - colors.green, - colors.green, - colors.white, - colors.white - ], - adjustBrightness: function (value) { return floor(value / LightAnimation.generalBrightness); }, - changeMode: function (newMode) { - if (newMode === "animate") { - LightAnimation.running = true; - LightAnimation.mode = "start-animate"; // through transient mode start-animate to animate - } else - if (newMode === "stop") { - LightAnimation.running = true; // first we want to turn off LEDs, thus needs stop-mode but running - LightAnimation.mode = "stop"; - } else - if (newMode === "demo") { - LightAnimation.mode = "demo"; - LightAnimation.running = true; - } else - if (newMode === "cycle") { - LightAnimation.mode = "cycle"; - LightAnimation.running = true; - } else - { - print("IGNORED: changeMode called with invalid mode = ", newMode); - } - }, - updateAnimationConfig: function (config) { - LightAnimation.animationConfig = JSON.parse(config); - return LightAnimation.verifyAnimationConfig(); - }, - verifyAnimationConfig: function() { - if (LightAnimation.animationConfig.comment === undefined) { - return {error: 'config is incomplete or invalid / comment not found'}; - } - if (LightAnimation.animationConfig.lights === undefined) { - return {error: 'config is incomplete or invalid / lights definition not found'}; - } - if (LightAnimation.animationConfig.lights[0] === undefined) { - return {error: 'config is incomplete or invalid / lights is not an array?'}; - } - let i; - for (i=0; i= LEDstate[i].nextTick) { - // update this animated bulb - } - // strip.setPixel called in animateBulb - // strip.setPixel(i, LightAnimation.adjustBrightness(LEDstate[i].currentRed), LightAnimation.adjustBrightness(LEDstate[i].currentGreen), LightAnimation.adjustBrightness(LEDstate[i].currentBlue)); - } - strip.show(); - } else print("*** Unknown LightAnimation.mode =", LightAnimation.mode); - } -} - - -return; // @TODO - -// Show start pattern for 3 seconds, then switch to default colors -Timer.set(3000 /* msec */, true /* repeat */, function() { - for (i=0; i= LEDstate[i].nextTick) { - // update this animated bulb - } - // strip.setPixel called in animateBulb - // strip.setPixel(i, LightAnimation.adjustBrightness(LEDstate[i].currentRed), LightAnimation.adjustBrightness(LEDstate[i].currentGreen), LightAnimation.adjustBrightness(LEDstate[i].currentBlue)); - } - strip.show(); - } else print("*** Unknown LightAnimation.mode =", LightAnimation.mode); - } -} - -// Garbage collection before startup, full=true --> reclaim RAM to OS -gc(true); - -print("Initialize timer, start in 5 seconds"); -// Show start pattern for 5 seconds, then switch to default colors -Timer.set(5000 /* msec */, false /* repeat */, function() { - print("START animation"); - for (i=0; i', message); -}, null); -*/ - -// Monitor network connectivity. -Net.setStatusEventHandler(function(ev, arg) { - let evs = '???'; - if (ev === Net.STATUS_DISCONNECTED) { - evs = 'DISCONNECTED'; - } else if (ev === Net.STATUS_CONNECTING) { - evs = 'CONNECTING'; - } else if (ev === Net.STATUS_CONNECTED) { - evs = 'CONNECTED'; - } else if (ev === Net.STATUS_GOT_IP) { - evs = 'GOT_IP'; - } - print('== Net event:', ev, evs); -}, null); diff --git a/bak/lights.cfg b/bak/lights.cfg deleted file mode 100755 index e958b80..0000000 --- a/bak/lights.cfg +++ /dev/null @@ -1,29 +0,0 @@ -{ "comment": "lights.cfg / JSON", - "lights": [ - { "level":"EG", "room":"Wohnzimmer", "on":[200,200,200], "id":"EG-WoZi" }, - { "level":"EG", "room":"Bad", "on":[150,150,150], "id":"EG-Bad" }, - { "level":"EG", "room":"Schlafzimmer", "on":[130,130,130], "id":"EG-Schlafen" }, - { "level":"EG", "room":"Buero 0.1", "on":[150,150,130], "id":"EG-Buero-1" }, - { "level":"EG", "room":"Buero 0.2", "on":[150,150,130], "id":"EG-Buero-2" }, - { "level":"OG1", "room":"Buero 1.1", "on":[150,150,130], "id":"OG1-Buero-1" }, - { "level":"OG1", "room":"Buero 1.2", "on":[150,150,130], "id":"OG1-Buero-2" }, - { "level":"OG1", "room":"Buero 1.3", "on":[150,150,130], "id":"OG1-Buero-3" }, - { "level":"OG1", "room":"Buero 1.4", "on":[150,150,130], "id":"OG1-Buero-4" }, - { "level":"OG2", "room":"Buero 2.1", "on":[150,150,130], "id":"OG2-Buero-1" }, - { "level":"OG2", "room":"Buero 2.2", "on":[150,150,130], "id":"OG2-Buero-2" }, - { "level":"OG2", "room":"Buero 2.3", "on":[150,150,130], "id":"OG2-Buero-3" }, - { "level":"OG2", "room":"Buero 2.4", "on":[150,150,130], "id":"OG2-Buero-4" } - ], - "animation": [ - { "lightsIndex": 2, "stepType": "on", "time": 1, "comment": "Fr. S. wacht auf" }, - { "lightsIndex": 2, "stepType": "off", "time": 55, "comment": "Fr. S. geht ins Bad" }, - { "lightsIndex": 1, "stepType": "on", "time": 56, "comment": "Fr. S. duscht" }, - { "lightsIndex": 2, "stepType": "on", "time": 250, "comment": "Fr. S. zieht sich an" }, - { "lightsIndex": 0, "stepType": "on", "time": 350, "comment": "Fr. S. setzt einen Kaffee auf und raeumt auf" }, - { "lightsIndex": 1, "stepType": "off", "time": 355, "comment": "Fr. S. ist fertig im Bad" }, - { "lightsIndex": 2, "stepType": "off", "time": 400, "comment": "Fr. S. ist fertig im Schlafzimmer" }, - { "lightsIndex": 0, "stepType": "off", "time": 500, "comment": "Fr. S. hat gefruehstueckt und verlaesst die Wohnung" }, - { "lightsIndex": 3, "stepType": "on", "time": 520, "comment": "Fr. S. ist im Buero" }, - { "lightsIndex": 4, "stepType": "on", "time": 700, "comment": "Fr. S. ist im Buero" } - ] -} \ No newline at end of file diff --git a/bak/test.js b/bak/test.js deleted file mode 100644 index 7ea97b0..0000000 --- a/bak/test.js +++ /dev/null @@ -1,33 +0,0 @@ -let x = { - "animation": - [ - {"comment":"Frau Schlemmer wacht auf","time":1,"stepType":"on","lightsIndex":2}, - {"comment":"Frau Schlemmer geht ins Bad","time":55,"stepType":"off","lightsIndex":2}, - {"comment":"Frau Schlemmer duscht","time":56,"stepType":"on","lightsIndex":1}, - {"comment":"Frau Schlemmer zieht sich an","time":250,"stepType":"on","lightsIndex":2}, - {"comment":"Frau Schlemmer setzt einen Kaffee auf und r\xc3\x83\xc2\x83\xc3\x82\xc2\xa4umt auf","time":350,"stepType":"on","lightsIndex":0}, - {"comment":"Frau Schlemmer ist fertig im Bad","time":355,"stepType":"off","lightsIndex":1}, - {"comment":"Frau Schlemmer ist fertig im Schlafzimmer","time":400,"stepType":"off","lightsIndex":2}, - {"comment":"Frau Schlemmer hat gefr\xc3\x83\xc2\x83\xc3\x82\xc2\xbchst\xc3\x83\xc2\x83\xc3\x82\xc2\xbcckt und verl\xc3\x83\xc2\x83\xc3\x82\xc2\xa4sst die Wohnung","time":500,"stepType":"off","lightsIndex":0}, - {"comment":"Frau Schlemmer ist im B\xc3\x83\xc2\x83\xc3\x82\xc2\xbcro","time":520,"stepType":"on","lightsIndex":3},{"comment":"Frau Schlemmer ist im B\xc3\x83\xc2\x83\xc3\x82\xc2\xbcro","time":700,"stepType":"on","lightsIndex":4} - ], - "lights": - [ - {"id":"EG-WoZi","on":[200,200,200],"room":"Wohnzimmer","level":"EG"}, - {"id":"EG-Bad","on":[150,150,150],"room":"Bad","level":"EG"}, - {"id":"EG-Schlafen","on":[130,130,130],"room":"Schlafzimmer","level":"EG"}, - {"id":"EG-Buero-1","on":[150,150,130],"room":"Buero 0.1","level":"EG"}, - {"id":"EG-Buero-2","on":[150,150,130],"room":"Buero 0.2","level":"EG"}, - {"id":"OG1-Buero-1","on":[150,150,130],"room":"Buero 1.1","level":"OG1"}, - {"id":"OG1-Buero-2","on":[150,150,130],"room":"Buero 1.2","level":"OG1"}, - {"id":"OG1-Buero-3","on":[150,150,130],"room":"Buero 1.3","level":"OG1"}, - {"id":"OG1-Buero-4","on":[150,150,130],"room":"Buero 1.4","level":"OG1"}, - {"id":"OG2-Buero-1","on":[150,150,130],"room":"Buero 2.1","level":"OG2"}, - {"id":"OG2-Buero-2","on":[150,150,130],"room":"Buero 2.2","level":"OG2"}, - {"id":"OG2-Buero-3","on":[150,150,130],"room":"Buero 2.3","level":"OG2"}, - {"id":"OG2-Buero-4","on":[150,150,130],"room":"Buero 2.4","level":"OG2"} - ], - "comment":"lights.cfg / JSON" -}; - -let LEDstate= [{"targetBlue":0,"targetGreen":0,"targetRed":0,"currentBlue":0,"currentGreen":0,"currentRed":0,"clockEndMinutes":59,"clockEndHours":23,"modeStep":0,"numLEDCtrl":0,"currentLEDCtrl":0,"mode":"onoff","rampTickDelta":0,"nextTick":0,"index":0},{"targetBlue":0,"targetGreen":0,"targetRed":0,"currentBlue":0,"currentGreen":0,"currentRed":0,"clockEndMinutes":59,"clockEndHours":23,"modeStep":0,"numLEDCtrl":0,"currentLEDCtrl":0,"mode":"onoff","rampTickDelta":0,"nextTick":0,"index":0},{"targetBlue":0,"targetGreen":0,"targetRed":0,"currentBlue":0,"currentGreen":0,"currentRed":0,"clockEndMinutes":59,"clockEndHours":23,"modeStep":0,"numLEDCtrl":0,"currentLEDCtrl":0,"mode":"onoff","rampTickDelta":0,"nextTick":0,"index":0},{"targetBlue":0,"targetGreen":0,"targetRed":0,"currentBlue":0,"currentGreen":0,"currentRed":0,"clockEndMinutes":59,"clockEndHours":23,"modeStep":0,"numLEDCtrl":0,"currentLEDCtrl":0,"mode":"onoff","rampTickDelta":0,"nextTick":0,"index":0},{"targetBlue":0,"targetGreen":0,"targetRed":0,"currentBlue":0,"currentGreen":0,"currentRed":0,"clockEndMinutes":59,"clockEndHours":23,"modeStep":0,"numLEDCtrl":0,"currentLEDCtrl":0,"mode":"onoff","rampTickDelta":0,"nextTick":0,"index":0},{"targetBlue":0,"targetGreen":0,"targetRed":0,"currentBlue":0,"currentGreen":0,"currentRed":0,"clockEndMinutes":59,"clockEndHours":23,"modeStep":0,"numLEDCtrl":0,"currentLEDCtrl":0,"mode":"onoff","rampTickDelta":0,"nextTick":0,"index":0},{"targetBlue":0,"targetGreen":0,"targetRed":0,"currentBlue":0,"currentGreen":0,"currentRed":0,"clockEndMinutes":59,"clockEndHours":23,"modeStep":0,"numLEDCtrl":0,"currentLEDCtrl":0,"mode":"onoff","rampTickDelta":0,"nextTick":0,"index":0},{"targetBlue":0,"targetGreen":0,"targetRed":0,"currentBlue":0,"currentGreen":0,"currentRed":0,"clockEndMinutes":59,"clockEndHours":23,"modeStep":0,"numLEDCtrl":0,"currentLEDCtrl":0,"mode":"onoff","rampTickDelta":0,"nextTick":0,"index":0},{"targetBlue":0,"targetGreen":0,"targetRed":0,"currentBlue":0,"currentGreen":0,"currentRed":0,"clockEndMinutes":59,"clockEndHours":23,"modeStep":0,"numLEDCtrl":0,"currentLEDCtrl":0,"mode":"onoff","rampTickDelta":0,"nextTick":0,"index":0},{"targetBlue":0,"targetGreen":0,"targetRed":0,"currentBlue":0,"currentGreen":0,"currentRed":0,"clockEndMinutes":59,"clockEndHours":23,"modeStep":0,"numLEDCtrl":0,"currentLEDCtrl":0,"mode":"onoff","rampTickDelta":0,"nextTick":0,"index":0},{"targetBlue":0,"targetGreen":0,"targetRed":0,"currentBlue":0,"currentGreen":0,"currentRed":0,"clockEndMinutes":59,"clockEndHours":23,"modeStep":0,"numLEDCtrl":0,"currentLEDCtrl":0,"mode":"onoff","rampTickDelta":0,"nextTick":0,"index":0}] ; diff --git a/fs/init.js b/fs/init.js index 393d911..dc135b2 100644 --- a/fs/init.js +++ b/fs/init.js @@ -5,16 +5,16 @@ load('api_net.js'); load('api_sys.js'); load('api_rpc.js'); load('api_timer.js'); +load("api_math.js"); +load("api_neopixel.js"); -let led = Cfg.get('pins.led'); // Helper C function get_led_gpio_pin() in src/main.c returns built-in LED GPIO -// let onBoardLed = ffi('int get_led_gpio_pin()')(); - +let onBoardLed = ffi('int get_led_gpio_pin(void)')(); let button = Cfg.get('pins.button'); let topic = '/devices/' + Cfg.get('device.id') + '/events'; -print('LED GPIO:', led, 'button GPIO:', button); +print('LED GPIO:', onBoardLed, 'button GPIO:', button); let getInfo = function() { return JSON.stringify({ @@ -24,11 +24,13 @@ let getInfo = function() { }; // Blink built-in LED every second -GPIO.set_mode(led, GPIO.MODE_OUTPUT); -Timer.set(5000 /* 1 sec */, true /* repeat */, function() { - let value = GPIO.toggle(led); +/* +GPIO.set_mode(onBoardLed, GPIO.MODE_OUTPUT); +Timer.set(5000, true, function() { + let value = GPIO.toggle(onBoardLed); print(value ? 'Tick' : 'Tock', 'uptime:', Sys.uptime(), getInfo()); }, null); +*/ // Publish to MQTT topic on a button press. Button is wired to GPIO pin 0 /* @@ -61,5 +63,114 @@ let addAnimationStep = ffi('void addAnimationStep(int, int, int)'); let LEDMode_on=1, LEDMode_off=2, LEDMode_blink=3, LEDMode_tv=4, LEDMode_fire=5; let LEDStateEngine_start = ffi('void startLEDStateEngine(void)'); let LEDStateEngine_pause = ffi('void pauseLEDStateEngine(void)'); +let LEDState_getRed = ffi('int LEDState_getLedRed(int)'); +let LEDState_getGreen = ffi('int LEDState_getLedGreen(int)'); +let LEDState_getBlue = ffi('int LEDState_getLedBlue(int)'); +let LEDState_getColorName = ffi('char * LEDState_getLedColorName(int)'); +let LEDState_getNextTick = ffi('int LEDState_getNextTick(int)'); +let LEDState_getCurrentTick = ffi('int LEDState_getCurrentTick(int)'); +let LEDDefinition_getLevel = ffi('char *LEDDefinition_getLevel(int)'); +let LEDDefinition_getRoom = ffi('char *LEDDefinition_getRoom(int)'); +let LEDDefinition_getId = ffi('char *LEDDefinition_getId(int)'); +let LEDDefinition_getOnColorRed = ffi('int LEDDefinition_getOnColorRed(int)'); +let LEDDefinition_getOnColorGreen = ffi('int LEDDefinition_getOnColorGreen(int)'); +let LEDDefinition_getOnColorBlue = ffi('int LEDDefinition_getOnColorBlue(int)'); +let getTicks = ffi('int getTicks(void)'); + +let pin = Cfg.get('led.pin'), numPixels = Cfg.get('led.count'), colorOrder = NeoPixel.GRB; +let strip = NeoPixel.create(pin, numPixels, colorOrder); + +/* Create test pattern */ +function createLedTestPattern() { + let i; + let switchMod; + for (i=0; i 5) print("WRONG -- should never reach this in switch statement!"); + /* + switch (switchMod) { + case 0: + strip.setPixel(i, 100, 100, 100); + break; + case 1: + strip.setPixel(i, 100, 0, 0); + break; + case 2: + strip.setPixel(i, 100, 100, 0); + break; + case 3: + strip.setPixel(i, 0, 100, 0); + break; + case 4: + strip.setPixel(i, 0, 100, 100); + break; + case 5: + strip.setPixel(i, 0, 0, 100); + break; + default: + print("WRONG -- should never reach this in switch statement!"); + } + */ + // strip.setPixel(i, 100, 100, 100); + } + strip.show(); +} + +function allLedOn() { + let i; + for (i=0; i MAX_LEDS) { @@ -13,13 +16,14 @@ void LEDStateEngine_setNumberOfLeds(int numberOfLeds) { numberOfLeds = MAX_LEDS; } theLEDStateEngine.numberOfLeds = numberOfLeds; + LOG(LL_INFO, ("LEDStateEngine initialized: numLEDs=%d, MAX_LEDS=%d", numberOfLeds, MAX_LEDS)); } void LEDStateEngine_init(int numberOfLeds) { LEDStateEngine_setNumberOfLeds(numberOfLeds); theLEDStateEngine.comment = ""; for (int i=0; iindex < 0 ||*/ state->index >= theLEDStateEngine.numberOfLeds) - return; // ignore LED entries, that are not setup correctly - state->currentTick++; + LEDState *state = LEDStateEngine_getLedState(ledNum); + state->currentTick = state->currentTick + 1; + // LOG(LL_INFO,("LEDState_tick(%d) %d", ledNum, state->currentTick)); if (state->currentTick == state->nextTick) { // perform/initiate next state change + //LOG(LL_INFO, ("State change for led %d", ledNum)); state->currentAnimationStep = AnimationConfig_getNextAnimationStepForLED(ledNum, state->currentAnimationStep); state->nextTick = state->currentTick + theAnimationConfig.animationStep[state->currentAnimationStep].durationTicks; state->mode = theAnimationConfig.animationStep[state->currentAnimationStep].ledMode; switch (state->mode) { case LEDMode_on: - state->currentColor = state->onColor; + state->currentColor = state->ledDefinition->onColor; // state->onColor; break; case LEDMode_off: state->currentColor = offColor; @@ -79,35 +85,57 @@ static int verifyLedNumber(int n) { return n; } -void LEDstate_initDefault(int n, LEDMode defaultMode) { +void LEDState_initDefault(int n, LEDMode defaultMode) { n = verifyLedNumber(n); - LEDState *state = &theLEDStateEngine.ledState[n]; - state->index = n; - state->mode = defaultMode; - state->nextTick = 0; - state->ledDefinition = LEDDefinition_get(n); -} - -void LEDstate_init(int n, LEDDefinition *ledDefinition) { - n = verifyLedNumber(n); - LEDstate_initDefault(n, LEDMode_off); LEDState *state = LEDStateEngine_getLedState(n); state->index = n; + state->mode = defaultMode; + state->currentTick = -10; + state->nextTick = 0; + state->ledDefinition = LEDDefinition_get(n); + state->currentAnimationStep = AnimationConfig_getNextAnimationStepForLED(n, 0); +} + +void LEDState_init(int n, LEDDefinition *ledDefinition) { + n = verifyLedNumber(n); + LEDState_initDefault(n, LEDMode_off); + LEDState *state = LEDStateEngine_getLedState(n); state->ledDefinition = ledDefinition; - state->onColor = ledDefinition->onColor; + // state->onColor = ledDefinition->onColor; + state->onColor.name = ledDefinition->onColor.name; + state->onColor.red = ledDefinition->onColor.red; + state->onColor.green = ledDefinition->onColor.green; + state->onColor.blue = ledDefinition->onColor.blue; } int LEDState_getLedRed(int ledNum) { + ledNum = verifyLedNumber(ledNum); LEDState *state = LEDStateEngine_getLedState(ledNum); return state->currentColor.red; } int LEDState_getLedGreen(int ledNum) { + ledNum = verifyLedNumber(ledNum); LEDState *state = LEDStateEngine_getLedState(ledNum); return state->currentColor.green; } int LEDState_getLedBlue(int ledNum) { + ledNum = verifyLedNumber(ledNum); LEDState *state = LEDStateEngine_getLedState(ledNum); return state->currentColor.blue; } - +char * LEDState_getLedColorName(int ledNum) { + ledNum = verifyLedNumber(ledNum); + LEDState *state = LEDStateEngine_getLedState(ledNum); + return state->currentColor.name; +} +int LEDState_getCurrentTick(int ledNum) { + ledNum = verifyLedNumber(ledNum); + LEDState *state = LEDStateEngine_getLedState(ledNum); + return state->currentTick; +} +int LEDState_getNextTick(int ledNum) { + ledNum = verifyLedNumber(ledNum); + LEDState *state = LEDStateEngine_getLedState(ledNum); + return state->nextTick; +} diff --git a/src/LEDState.h b/src/LEDState.h index 1319374..209075f 100644 --- a/src/LEDState.h +++ b/src/LEDState.h @@ -28,6 +28,8 @@ typedef struct LEDStateEngine_t { char *comment; } LEDStateEngine; +extern int getTicks(void); + /* LEDStateEngine */ extern void LEDStateEngine_init(int numberOfLeds); extern void LEDStateEngine_addComment(char *comment); @@ -37,11 +39,14 @@ extern void LEDStateEngine_tick(); extern uint16_t LEDStateEngine_getNumberOfLeds(); /* LEDState */ -extern void LEDstate_init(int n, LEDDefinition *ledDefinition); -extern void LEDstate_initDefault(int n, LEDMode defaultMode); +extern void LEDState_init(int n, LEDDefinition *ledDefinition); +extern void LEDState_initDefault(int n, LEDMode defaultMode); extern void LEDState_tick(int ledNum); extern int LEDState_getLedRed(int ledNum); extern int LEDState_getLedGreen(int ledNum); extern int LEDState_getLedBlue(int ledNum); +extern char * LEDState_getLedColorName(int ledNum); +extern int LEDState_getCurrentTick(int ledNum); +extern int LEDState_getNextTick(int ledNum); #endif diff --git a/src/main.c b/src/main.c index aede589..323f1c9 100644 --- a/src/main.c +++ b/src/main.c @@ -37,9 +37,9 @@ int get_led_gpio_pin(void) { LEDStateEngine ledStateEngine; static bool stateEngineRunning = false; -static void timer_cb() { +static void stateEngineTickTimer() { if (stateEngineRunning) { - LOG(LL_INFO, ("tick")); + // LOG(LL_INFO, ("digg")); LEDStateEngine_tick(); } else { LOG(LL_INFO, ("--paused--")); @@ -47,12 +47,13 @@ static void timer_cb() { } static void delayed_boot() { - mgos_set_timer(100, true, timer_cb, NULL); // every 0.1 second call timer_cb + LOG(LL_INFO, ("*** Start timer for LED state engine ticks")); + mgos_set_timer(100, true, stateEngineTickTimer, NULL); // every 0.1 second call timer_cb } enum mgos_app_init_result mgos_app_init(void) { - int numberOfLeds = 20; /*mgos_sys_config_get_led_count()*/ - bool loadDefaultData = true; /*mgos_sys_config_get_led_useDefaults()*/ + int numberOfLeds = mgos_sys_config_get_led_count(); + bool loadDefaultData = mgos_sys_config_get_led_useDefaults(); LEDColor_init(loadDefaultData); LEDDefinition_init(numberOfLeds, loadDefaultData); @@ -88,7 +89,9 @@ void addAnimationStep(int ledIndex, int ledMode, int duration) { void startLEDStateEngine(void) { stateEngineRunning = true; + LOG(LL_INFO, ("LEDStateEngine started")); } void pauseLEDStateEngine(void) { stateEngineRunning = false; + LOG(LL_INFO, ("LEDStateEngine stopped")); }