From b79d6dfd48a7d565958dc7af5e6df808460e1465 Mon Sep 17 00:00:00 2001 From: Dirk Jahnke Date: Tue, 5 Dec 2017 12:40:37 +0100 Subject: [PATCH] Added C-implementation for NeoPixel. Changed a few colors/animation settings for demo purposes. Signed-off-by: Dirk Jahnke --- fs/animations.cfg | 28 ++++++++-------- fs/colors.cfg | 10 +++--- fs/lamps.cfg | 4 +-- src/NeoPixel.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+), 20 deletions(-) create mode 100644 src/NeoPixel.c diff --git a/fs/animations.cfg b/fs/animations.cfg index 025d3fa..8d76cd7 100644 --- a/fs/animations.cfg +++ b/fs/animations.cfg @@ -1,16 +1,16 @@ [ - {"led": 0, "mode": "on", "ticks": 10}, - {"led": 0, "mode": "off", "ticks": 10}, - {"led": 1, "mode": "on", "ticks": 20}, - {"led": 1, "mode": "off", "ticks": 20}, - {"led": 2, "mode": "on", "ticks": 40}, - {"led": 2, "mode": "off", "ticks": 40}, - {"led": 3, "mode": "on", "ticks": 80}, - {"led": 3, "mode": "off", "ticks": 80}, - {"led": 4, "mode": "on", "ticks": 160}, - {"led": 4, "mode": "off", "ticks": 160}, - {"led": 5, "mode": "on", "ticks": 320}, - {"led": 5, "mode": "off", "ticks": 320}, - {"led": 6, "mode": "on", "ticks": 640}, - {"led": 6, "mode": "off", "ticks": 640} + {"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} ] diff --git a/fs/colors.cfg b/fs/colors.cfg index d4567c0..b5e4991 100644 --- a/fs/colors.cfg +++ b/fs/colors.cfg @@ -1,10 +1,12 @@ [ {"name": "off", "red": 0, "green": 0, "blue": 0}, - {"name": "candle", "red": 50, "green": 40, "blue": 10}, + {"name": "candle", "red": 30, "green": 15, "blue": 4}, {"name": "red", "red": 50, "green": 5, "blue": 5}, {"name": "green", "red": 5, "green": 50, "blue": 5}, - {"name": "blue", "red": 5, "green": 5, "blue": 50}, - {"name": "warmWhite", "red": 80, "green": 80, "blue": 40}, + {"name": "blue", "red": 5, "green": 5, "blue": 80}, + {"name": "yellow", "red": 50, "green": 50, "blue": 5}, + {"name": "violet", "red": 50, "green": 5, "blue": 80}, + {"name": "warmWhite", "red": 90, "green": 90, "blue": 30}, {"name": "coldWhite", "red": 80, "green": 80, "blue": 100}, {"name": "brightWhite", "red": 255, "green": 255, "blue": 255} -] \ No newline at end of file +] diff --git a/fs/lamps.cfg b/fs/lamps.cfg index ff299b4..5d641d7 100644 --- a/fs/lamps.cfg +++ b/fs/lamps.cfg @@ -4,6 +4,6 @@ {"level": "EG", "room": "Bad", "id": "eg-bad", "onColor": "red"}, {"level": "EG", "room": "Kueche", "id": "eg-kueche", "onColor": "green"}, {"level": "EG", "room": "Flur", "id": "eg-flur", "onColor": "blue"}, - {"level": "OG", "room": "Wohnzimmer", "id": "og-wozi", "onColor": "candle"}, - {"level": "OG", "room": "Buero", "id": "og-office", "onColor": "coldWhite"} + {"level": "OG", "room": "Wohnzimmer", "id": "og-wozi", "onColor": "yellow"}, + {"level": "OG", "room": "Buero", "id": "og-office", "onColor": "violet"} ] diff --git a/src/NeoPixel.c b/src/NeoPixel.c new file mode 100644 index 0000000..9b29980 --- /dev/null +++ b/src/NeoPixel.c @@ -0,0 +1,81 @@ +#include "mgos_bitbang.h" +#include "mgos_gpio.h" +#include "mgos_system.h" + +enum NeoPixel_ColorOrder { + RGB = 0, + GRB = 1, + BGR = 2, +}; + +#define MAX_LEDS 100 +static uint8_t NeoPixel_pin = 0; +static uint8_t NeoPixel_numPixels = 0; +static uint8_t NeoPixel_leds[3 * MAX_LEDS]; +static NeoPixel_ColorOrder NeoPixel_colorOrder = RGB; + +// ## **`NeoPixel_create(pin, numPixels, order)`** +// Create and return a NeoPixel strip object. Example: +// ```javascript +// let pin = 5, numPixels = 16, 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(); +// ``` +void NeoPixel_create(uint8_t, pin, uint8_t numPixels, enum NeoPixel_ColorOrder order) { + mgos_gpio_init(); + NeoPixel_pin = pin; + NeoPixel_numPixels = numPixels; + NeoPixel_colorOrder = order; + // GPIO.set_mode(pin, GPIO.MODE_OUTPUT); + mgos_gpio_set_mode(pin, MGOS_GPIO_MODE_OUTPUT); + // GPIO.write(pin, 0); // Keep in reset. + mgos_gpio_write(pin, false); + NeoPixel_clear(); +} + +// ## **`NeoPixel_clear()`** +// Clear in-memory values of the pixels. +void NeoPixel_clear() { + for (int i=0; i