Stabilized new implementation and trimmed to maximum useful speed.
This commit is contained in:
@@ -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}
|
||||
]
|
||||
|
27
fs/api_dlite.js
Normal file
27
fs/api_dlite.js
Normal file
@@ -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)');
|
85
fs/init.js
85
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<configNumLeds; ++i) {
|
||||
switchMod = i - 6 * Math.floor(i/6);
|
||||
/*if (switchMod === 0) strip.setPixel(i, 10, 10, 10);
|
||||
if (switchMod === 1) strip.setPixel(i, 10, 10, 10);
|
||||
if (switchMod === 2) strip.setPixel(i, 10, 100, 0);
|
||||
if (switchMod === 3) strip.setPixel(i, 0, 10, 0);
|
||||
if (switchMod === 4) strip.setPixel(i, 0, 10, 10);
|
||||
if (switchMod === 5) strip.setPixel(i, 0, 0, 10);*/
|
||||
if (switchMod === 0) NeoPixel_set(i, 10, 10, 10);
|
||||
if (switchMod === 1) NeoPixel_set(i, 10, 10, 10);
|
||||
if (switchMod === 2) NeoPixel_set(i, 10, 100, 0);
|
||||
@@ -117,24 +79,19 @@ function showLedTestPattern() {
|
||||
if (switchMod === 5) NeoPixel_set(i, 0, 0, 10);
|
||||
if (switchMod < 0 || switchMod > 5) print("WRONG -- should never reach this in switch statement!");
|
||||
}
|
||||
//strip.show();
|
||||
NeoPixel_show();
|
||||
}
|
||||
|
||||
function allLedOn() {
|
||||
let i;
|
||||
for (i=0; i<configNumLeds; ++i) {
|
||||
//strip.setPixel(i, 10, 10, 10);
|
||||
NeoPixel_set(i, 10, 10, 10);
|
||||
}
|
||||
//strip.show();
|
||||
NeoPixel_show();
|
||||
}
|
||||
|
||||
function allLedOff() {
|
||||
//strip.clear();
|
||||
NeoPixel_clear();
|
||||
//strip.show();
|
||||
NeoPixel_show();
|
||||
}
|
||||
|
||||
@@ -203,8 +160,6 @@ function loadAnimDefs() {
|
||||
}
|
||||
|
||||
function initialize() {
|
||||
// initialize LEDs
|
||||
// ===============
|
||||
print('***** Start initialization', getInfo());
|
||||
let i;
|
||||
|
||||
@@ -216,7 +171,6 @@ function initialize() {
|
||||
loadColorDefs();
|
||||
loadLedDefs();
|
||||
loadAnimDefs();
|
||||
|
||||
// Initialize LED State Engine
|
||||
LEDStateEngine_init(pin, numberOfLeds);
|
||||
}
|
||||
@@ -227,7 +181,6 @@ function initialize() {
|
||||
print('NumLEDs:', numberOfLeds);
|
||||
print('Ticks:', getTicks());
|
||||
print('Tick duration:', tickDuration, 'ms');
|
||||
print('LED Update Cycle:', updateCycle, 'ms');
|
||||
print('Brightness:', brightnessAdjustment, '%');
|
||||
print('LED', 'Color', 'R', 'G', 'B', 'Tick', 'Level', 'Room', 'Id');
|
||||
print('---', '-----', '---', '---', '-----', '---', '-----', '----', '--');
|
||||
@@ -237,34 +190,22 @@ function initialize() {
|
||||
}
|
||||
}
|
||||
|
||||
Timer.set(3000, false, function() {
|
||||
Timer.set(1500, false, function() {
|
||||
initialize();
|
||||
allLedOn();
|
||||
print('***** Starting timer to delay test pattern generation');
|
||||
/*print('***** Wait 1 second for other tasks to startup', getInfo());
|
||||
Timer.set(1000, false, function() {
|
||||
Timer.set(1000, false, function() {*/
|
||||
allLedOff();
|
||||
print('***** LED test pattern', getInfo());
|
||||
showLedTestPattern();
|
||||
print('***** Start LED state engine and LED-update timer', getInfo());
|
||||
LEDStateEngine_start();
|
||||
/*
|
||||
Timer.set(updateCycle, true, function () {
|
||||
let i;
|
||||
for (i=0; i<numberOfLeds; ++i) {
|
||||
strip.setPixel(i, adjustBrightness(LEDState_getRed(i)), adjustBrightness(LEDState_getGreen(i)), adjustBrightness(LEDState_getBlue(i)));
|
||||
}
|
||||
strip.show();
|
||||
}, null);*/
|
||||
/*}, null);
|
||||
}, null);*/
|
||||
allLedOff();
|
||||
print('***** LED test pattern', getInfo());
|
||||
showLedTestPattern();
|
||||
print('***** Start LED state engine and LED-update timer', getInfo());
|
||||
LEDStateEngine_start();
|
||||
Timer.set(10000, true, function() {
|
||||
print("Timer: minTickTime =", LEDStateEngine_getMinTickTime(), ", maxTickTime =", LEDStateEngine_getMaxTickTime());
|
||||
}, null);
|
||||
}, null);
|
||||
print('***** End of init.js, sub tasks still running', getInfo());
|
||||
|
||||
|
||||
/* ------ RPC Handlers ------- */
|
||||
|
||||
print('**** Adding RPC handlers');
|
||||
RPC.addHandler('led.setBrightness', function(args) {
|
||||
// print(args);
|
||||
if (args !== undefined && args.level !== undefined) {
|
||||
@@ -352,3 +293,5 @@ RPC.addHandler('led.putAnimations', function(args) {
|
||||
return { error: 'animations: {led, mode, ticks} is required' };
|
||||
}
|
||||
}, null);
|
||||
|
||||
print('***** End of init.js, sub tasks still running', getInfo());
|
||||
|
Reference in New Issue
Block a user