commit bf5e39efb6069090786e72252f1cd8688d1dc9fd Author: Dirk Jahnke Date: Thu Jul 13 06:18:04 2017 +0200 Initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..c1b0aa3 --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# NeoPixel based app to control model railroad houses lightnings + +## Overview + +This app is based on the example mjs_base and addds service to control model house lightnings, based on the current clock (of fastclock). + +## How to install this app + +- Install and start [mos tool](https://mongoose-os.com/software.html) +- Switch to the Project page, find and import this app, build and flash it: + +

+ +

diff --git a/fs/index.html b/fs/index.html new file mode 100644 index 0000000..5f37107 --- /dev/null +++ b/fs/index.html @@ -0,0 +1,5 @@ + + +

Welcome to the empty project

+ + diff --git a/fs/init.js b/fs/init.js new file mode 100644 index 0000000..ac1f626 --- /dev/null +++ b/fs/init.js @@ -0,0 +1,42 @@ +load('api_config.js'); +load('api_gpio.js'); +load('api_mqtt.js'); +load('api_sys.js'); +load('api_timer.js'); +load("api_neopixel.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 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'; + let message = getInfo(); + let ok = MQTT.pub(topic, message, 1); + 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(); + diff --git a/mos.yml b/mos.yml new file mode 100644 index 0000000..4879d33 --- /dev/null +++ b/mos.yml @@ -0,0 +1,46 @@ +version: "1.0" +arch: esp8266 +author: mongoose-os +description: NeoPixel app to control model railroad house lightnings +mongoose_os_version: ${mos_version} +sources: +- src +filesystem: +- fs +extra_files: [] +ffi_symbols: [] +libs: + # common mgos libs + - origin: https://github.com/mongoose-os-libs/http-server + - origin: https://github.com/mongoose-os-libs/i2c + - origin: https://github.com/mongoose-os-libs/ota-http-server + - origin: https://github.com/mongoose-os-libs/rpc-loopback + - origin: https://github.com/mongoose-os-libs/rpc-mqtt + - origin: https://github.com/mongoose-os-libs/rpc-service-config + - origin: https://github.com/mongoose-os-libs/rpc-service-fs + - origin: https://github.com/mongoose-os-libs/rpc-service-gpio + - origin: https://github.com/mongoose-os-libs/rpc-service-i2c + - origin: https://github.com/mongoose-os-libs/rpc-service-ota + - origin: https://github.com/mongoose-os-libs/rpc-uart + - origin: https://github.com/mongoose-os-libs/spi + - origin: https://github.com/mongoose-os-libs/vfs-dev-spi-flash + + # libs necessary for the current app + - origin: https://github.com/mongoose-os-libs/aws + - origin: https://github.com/mongoose-os-libs/mjs +config_schema: + - ["i2c.enable", true] +build_vars: + MGOS_ENABLE_ONEWIRE: 1 +cflags: [] +cxxflags: [] +cdefs: {} +tags: +- c +libs_version: ${mos_version} +modules_version: ${mos_version} +conds: [] +manifest_version: "" +skeleton_version: 2017-05-18 +deps: [] +libs_handled: [] diff --git a/mos_esp32.yml b/mos_esp32.yml new file mode 100644 index 0000000..0b0d069 --- /dev/null +++ b/mos_esp32.yml @@ -0,0 +1,5 @@ +libs: + - origin: https://github.com/mongoose-os-libs/atca + - origin: https://github.com/mongoose-os-libs/dns-sd + - origin: https://github.com/mongoose-os-libs/gcp + - origin: https://github.com/mongoose-os-libs/rpc-service-atca diff --git a/mos_esp8266.yml b/mos_esp8266.yml new file mode 100644 index 0000000..0b0d069 --- /dev/null +++ b/mos_esp8266.yml @@ -0,0 +1,5 @@ +libs: + - origin: https://github.com/mongoose-os-libs/atca + - origin: https://github.com/mongoose-os-libs/dns-sd + - origin: https://github.com/mongoose-os-libs/gcp + - origin: https://github.com/mongoose-os-libs/rpc-service-atca diff --git a/src/conf_schema.yaml b/src/conf_schema.yaml new file mode 100644 index 0000000..55c4f9c --- /dev/null +++ b/src/conf_schema.yaml @@ -0,0 +1,4 @@ +[ + ["mqtt.server", "cubieboard4:1883"], + ["i2c.enable", true], +] diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..98ef83f --- /dev/null +++ b/src/main.c @@ -0,0 +1,35 @@ +#include + +#include "common/platform.h" +#include "common/cs_file.h" +#include "fw/src/mgos_app.h" +#include "fw/src/mgos_gpio.h" +#include "fw/src/mgos_sys_config.h" +#include "fw/src/mgos_timers.h" +#include "fw/src/mgos_hal.h" +#include "fw/src/mgos_dlsym.h" +#include "mjs.h" + +#if CS_PLATFORM == CS_P_ESP8266 +#define LED_GPIO 2 /* On ESP-12E there is a blue LED connected to GPIO2 */ +#elif CS_PLATFORM == CS_P_ESP32 +#define LED_GPIO 21 /* No LED on DevKitC, use random GPIO close to GND pin */ +#elif CS_PLATFORM == CS_P_CC3200 +#define LED_GPIO 64 /* The red LED on LAUNCHXL */ +#elif(CS_PLATFORM == CS_P_STM32) && defined(BSP_NUCLEO_F746ZG) +/* Nucleo-144 F746 */ +#define LED_GPIO STM32_PIN_PB7 /* Blue LED */ +#elif(CS_PLATFORM == CS_P_STM32) && defined(BSP_DISCO_F746G) +/* Discovery-0 F746 */ +#define LED_GPIO STM32_PIN_PI1 /* Green LED */ +#else +#error Unknown platform +#endif + +int get_led_gpio_pin(void) { + return LED_GPIO; +} + +enum mgos_app_init_result mgos_app_init(void) { + return MGOS_APP_INIT_SUCCESS; +}