First version with demo mode

This commit is contained in:
2017-07-13 11:31:50 +02:00
parent bf5e39efb6
commit a8206eb465
4 changed files with 186 additions and 20 deletions

View File

@@ -2,23 +2,17 @@ load('api_config.js');
load('api_gpio.js');
load('api_mqtt.js');
load('api_sys.js');
load('api_rpc.js');
load('api_timer.js');
load("api_neopixel.js");
load("animateLights.js");
// Helper C function get_led_gpio_pin() in src/main.c returns built-in LED GPIO
let led = ffi('int get_led_gpio_pin()')();
let onBoardLed = ffi('int get_led_gpio_pin()')();
let getInfo = function() {
return JSON.stringify({total_ram: Sys.total_ram(), free_ram: Sys.free_ram()});
};
// Blink built-in LED every second
GPIO.set_mode(led, GPIO.MODE_OUTPUT);
Timer.set(1000 /* 1 sec */, true /* repeat */, function() {
let value = GPIO.toggle(led);
print(value ? 'Tick' : 'Tock', 'uptime:', Sys.uptime(), getInfo());
}, null);
// Publish to MQTT topic on a button press. Button is wired to GPIO pin 0
GPIO.set_button_handler(0, GPIO.PULL_UP, GPIO.INT_EDGE_NEG, 200, function() {
let topic = '/devices/' + Cfg.get('device.id') + '/events';
@@ -27,16 +21,12 @@ GPIO.set_button_handler(0, GPIO.PULL_UP, GPIO.INT_EDGE_NEG, 200, function() {
print('Published:', ok ? 'yes' : 'no', 'topic:', topic, 'message:', message);
}, null);
function initNeopixel() {
let pin = 2, numPixels = 20, colorOrder = NeoPixel.GRB;
let strip = NeoPixel.create(pin, numPixels, colorOrder);
strip.setPixel(0 / pixel /, 12, 34, 56);
strip.show();
strip.clear();
strip.setPixel(1 / pixel /, 12, 34, 56);
strip.show();
}
initNeopixel();
// Blink built-in LED every second
GPIO.set_mode(onBoardLed, GPIO.MODE_OUTPUT);
// Tick-Tock generation
Timer.set(1000 /* 1 sec */, true /* repeat */, function() {
let value = GPIO.toggle(onBoardLed);
print(value ? 'Tick' : 'Tock', 'uptime:', Sys.uptime(), getInfo());
}, null);