diff --git a/fs/animations.cfg b/fs/animations.cfg index 8d76cd7..e679dab 100644 --- a/fs/animations.cfg +++ b/fs/animations.cfg @@ -1,16 +1,16 @@ [ - {"led": 0, "mode": "on", "ticks": 2}, - {"led": 0, "mode": "off", "ticks": 2}, - {"led": 1, "mode": "on", "ticks": 4}, - {"led": 1, "mode": "off", "ticks": 4}, - {"led": 2, "mode": "on", "ticks": 8}, - {"led": 2, "mode": "off", "ticks": 8}, - {"led": 3, "mode": "on", "ticks": 16}, - {"led": 3, "mode": "off", "ticks": 16}, - {"led": 4, "mode": "on", "ticks": 32}, - {"led": 4, "mode": "off", "ticks": 32}, - {"led": 5, "mode": "on", "ticks": 64}, - {"led": 5, "mode": "off", "ticks": 64}, - {"led": 6, "mode": "on", "ticks": 128}, - {"led": 6, "mode": "off", "ticks": 128} + {"led": 0, "mode": "on", "ticks": 4}, + {"led": 0, "mode": "off", "ticks": 4}, + {"led": 1, "mode": "on", "ticks": 8}, + {"led": 1, "mode": "off", "ticks": 8}, + {"led": 2, "mode": "on", "ticks": 16}, + {"led": 2, "mode": "off", "ticks": 16}, + {"led": 3, "mode": "on", "ticks": 32}, + {"led": 3, "mode": "off", "ticks": 32}, + {"led": 4, "mode": "on", "ticks": 64}, + {"led": 4, "mode": "off", "ticks": 64}, + {"led": 5, "mode": "on", "ticks": 128}, + {"led": 5, "mode": "off", "ticks": 128}, + {"led": 6, "mode": "on", "ticks": 256}, + {"led": 6, "mode": "off", "ticks": 256} ] diff --git a/fs/api_dlite.js b/fs/api_dlite.js new file mode 100644 index 0000000..1c3eda1 --- /dev/null +++ b/fs/api_dlite.js @@ -0,0 +1,27 @@ +let onBoardLed = ffi('int get_led_gpio_pin(void)')(); +let addColor = ffi('void addColor(char *,int,int,int)'); +let LEDDefinition_addByName = ffi('void LEDDefinition_addByName(char *, char *, char *, char *)'); +let addAnimationStep = ffi('void addAnimationStep(int, char *, int)'); +let LEDMode_on=1, LEDMode_off=2, LEDMode_blink=3, LEDMode_tv=4, LEDMode_fire=5; +let LEDStateEngine_init = ffi('void LEDStateEngine_init(int, int)'); +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 printColor = ffi('void printColor(char *)'); +let NeoPixel_show = ffi('void NeoPixel_show(void)'); +let NeoPixel_clear = ffi('void NeoPixel_clear(void)'); +let NeoPixel_set = ffi('void NeoPixel_set(int,int,int,int)'); +let LEDStateEngine_getMinTickTime = ffi('double LEDStateEngine_getMinTickTime(void)'); +let LEDStateEngine_getMaxTickTime = ffi('double LEDStateEngine_getMaxTickTime(void)'); diff --git a/fs/init.js b/fs/init.js index fc9350c..661a90e 100644 --- a/fs/init.js +++ b/fs/init.js @@ -5,13 +5,10 @@ load('api_net.js'); load('api_sys.js'); load('api_rpc.js'); load('api_timer.js'); -load("api_math.js"); -load("api_file.js"); -load("api_neopixel.js"); - +load('api_file.js'); +load('api_dlite.js'); // Helper C function get_led_gpio_pin() in src/main.c returns built-in LED GPIO -let onBoardLed = ffi('int get_led_gpio_pin(void)')(); let button = Cfg.get('pins.button'); let topic = '/devices/' + Cfg.get('device.id') + '/events'; @@ -58,41 +55,12 @@ Net.setStatusEventHandler(function(ev, arg) { print('==> NET:', ev, evs); }, null); -// Initialize LED controller -let addColor = ffi('void addColor(char *,int,int,int)'); -let LEDDefinition_addByName = ffi('void LEDDefinition_addByName(char *, char *, char *, char *)'); -let addAnimationStep = ffi('void addAnimationStep(int, char *, int)'); -let LEDMode_on=1, LEDMode_off=2, LEDMode_blink=3, LEDMode_tv=4, LEDMode_fire=5; -let LEDStateEngine_init = ffi('void LEDStateEngine_init(int, int)'); -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 printColor = ffi('void printColor(char *)'); -let NeoPixel_show = ffi('void NeoPixel_show(void)'); -let NeoPixel_clear = ffi('void NeoPixel_clear(void)'); -let NeoPixel_set = ffi('void NeoPixel_set(int,int,int,int)'); - let pin = Cfg.get('led.pin'); let configNumLeds = Cfg.get('led.count'); -let colorOrder = NeoPixel.GRB; -//let strip = NeoPixel.create(pin, configNumLeds, colorOrder); let colorFile = Cfg.get('led.colorFile'); let animationFile = Cfg.get('led.animationFile'); let lampsFile = Cfg.get('led.lampsFile'); let useDefaults = Cfg.get('led.useDefaults'); -let updateCycle = Cfg.get('led.updateCycle'); let tickDuration = Cfg.get('led.tickDuration'); let brightnessAdjustment = Cfg.get('led.brightness'); let numberOfLeds = configNumLeds, numberOfLedDefs = 0; // from config files, count led definition entries @@ -103,12 +71,6 @@ function showLedTestPattern() { let switchMod; for (i=0; i 5) print("WRONG -- should never reach this in switch statement!"); } - //strip.show(); NeoPixel_show(); } function allLedOn() { let i; for (i=0; i maxTickTime) maxTickTime = usedTime; + if (usedTime < minTickTime) minTickTime = usedTime; } +double LEDStateEngine_getMinTickTime() { return minTickTime; } +double LEDStateEngine_getMaxTickTime() { return maxTickTime; } static uint8_t adjustBrightness(uint8_t value) { return (value * mgos_sys_config_get_led_brightness()/100); } static void updateLedDisplay(LEDState *state) { - // strip.setPixel(i, adjustBrightness(LEDState_getRed(i)), adjustBrightness(LEDState_getGreen(i)), adjustBrightness(LEDState_getBlue(i))); - // strip.setPixel(i, adjustBrightness(LEDState_getRed(i)), adjustBrightness(LEDState_getGreen(i)), adjustBrightness(LEDState_getBlue(i))); NeoPixel_set(state->index, adjustBrightness(state->currentColor.red), adjustBrightness(state->currentColor.green), adjustBrightness(state->currentColor.blue)); } diff --git a/src/LEDState.h b/src/LEDState.h index 790d5eb..558ee2d 100644 --- a/src/LEDState.h +++ b/src/LEDState.h @@ -38,6 +38,9 @@ extern void LEDStateEngine_addComment(char *comment); extern LEDState *LEDStateEngine_getLedState(int n); extern void LEDStateEngine_tick(); extern uint16_t LEDStateEngine_getNumberOfLeds(); +extern double LEDStateEngine_getMinTickTime(); +extern double LEDStateEngine_getMaxTickTime(); + /* LEDState */ extern void LEDState_init(int n, LEDDefinition *ledDefinition);