Initial commit
This commit is contained in:
commit
bf5e39efb6
|
@ -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:
|
||||
|
||||
<p align="center">
|
||||
<img src="https://mongoose-os.com/images/app1.gif" width="75%">
|
||||
</p>
|
|
@ -0,0 +1,5 @@
|
|||
<html>
|
||||
<body>
|
||||
<h1>Welcome to the empty project</h1>
|
||||
</body>
|
||||
</html>
|
|
@ -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();
|
||||
|
|
@ -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: []
|
|
@ -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
|
|
@ -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
|
|
@ -0,0 +1,4 @@
|
|||
[
|
||||
["mqtt.server", "cubieboard4:1883"],
|
||||
["i2c.enable", true],
|
||||
]
|
|
@ -0,0 +1,35 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#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;
|
||||
}
|
Loading…
Reference in New Issue