diff --git a/.settings/org.eclipse.cdt.core.prefs b/.settings/org.eclipse.cdt.core.prefs index 5facf81..79a2c9a 100644 --- a/.settings/org.eclipse.cdt.core.prefs +++ b/.settings/org.eclipse.cdt.core.prefs @@ -184,10 +184,10 @@ environment/project/io.sloeber.core.toolChain.release.1583508753/A.EXTRA.TIME.DT environment/project/io.sloeber.core.toolChain.release.1583508753/A.EXTRA.TIME.DTS/value=3600 environment/project/io.sloeber.core.toolChain.release.1583508753/A.EXTRA.TIME.LOCAL/delimiter=\: environment/project/io.sloeber.core.toolChain.release.1583508753/A.EXTRA.TIME.LOCAL/operation=replace -environment/project/io.sloeber.core.toolChain.release.1583508753/A.EXTRA.TIME.LOCAL/value=1554895981 +environment/project/io.sloeber.core.toolChain.release.1583508753/A.EXTRA.TIME.LOCAL/value=1555711355 environment/project/io.sloeber.core.toolChain.release.1583508753/A.EXTRA.TIME.UTC/delimiter=\: environment/project/io.sloeber.core.toolChain.release.1583508753/A.EXTRA.TIME.UTC/operation=replace -environment/project/io.sloeber.core.toolChain.release.1583508753/A.EXTRA.TIME.UTC/value=1554888781 +environment/project/io.sloeber.core.toolChain.release.1583508753/A.EXTRA.TIME.UTC/value=1555704155 environment/project/io.sloeber.core.toolChain.release.1583508753/A.EXTRA.TIME.ZONE/delimiter=\: environment/project/io.sloeber.core.toolChain.release.1583508753/A.EXTRA.TIME.ZONE/operation=replace environment/project/io.sloeber.core.toolChain.release.1583508753/A.EXTRA.TIME.ZONE/value=3600 @@ -466,10 +466,10 @@ environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.BOARD_NA environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.BOARD_NAME/value=NodeMCU 1.0 (ESP-12E Module) environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.COM_PORT/delimiter=\: environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.COM_PORT/operation=replace -environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.COM_PORT/value=/dev/ttyUSB4 +environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.COM_PORT/value=/dev/ttyUSB0 environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.ECLIPSE_LOCATION/delimiter=\: environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.ECLIPSE_LOCATION/operation=replace -environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.ECLIPSE_LOCATION/value=${eclipse_home}////////// +environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.ECLIPSE_LOCATION/value=${eclipse_home}//////////////////// environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.EXTRA.ALL/delimiter=\: environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.EXTRA.ALL/operation=replace environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.EXTRA.ALL/value= diff --git a/configuration.cpp b/configuration.cpp index 219adb4..b562d1a 100644 --- a/configuration.cpp +++ b/configuration.cpp @@ -9,7 +9,7 @@ tConfigBlock configBlock; -const uint32_t MAGIC = 3235774470; +const uint32_t MAGIC = 3235774471; const char* CONFIG_SSID = "espconfig"; extern ESP8266WebServer webServer; diff --git a/productionMode.cpp b/productionMode.cpp index 344411d..e19c792 100644 --- a/productionMode.cpp +++ b/productionMode.cpp @@ -6,6 +6,10 @@ */ + +// #define FASTLED +#define ADAFRUIT_NEOPIXEL + #include "defines.h" #define MQTT_MAX_PACKET_SIZE 256 @@ -18,8 +22,15 @@ #include #include +#ifdef FASTLED #define FASTLED_ESP8266_NODEMCU_PIN_ORDER #include +#endif + +#ifdef ADAFRUIT_NEOPIXEL +#include +#endif + #include "configuration.h" @@ -35,9 +46,20 @@ WiFiClientSecure espClient; PubSubClient client(espClient); - +#ifdef FASTLED CRGB leds[NUM_OF_LEDs]; +#endif +#ifdef ADAFRUIT_NEOPIXEL +typedef struct { + uint8_t r; + uint8_t g; + uint8_t b; +} CRGB; + + +Adafruit_NeoPixel pixels(NUM_OF_LEDs, D1, NEO_RGB + NEO_KHZ400); +#endif void setup_wifi() { delay(10); @@ -170,21 +192,38 @@ void callback(char* topic, byte* payload, unsigned int length) { // set brightness b = strtol(tokens[0], NULL, 10); for (uint8_t i = 0; i < NUM_OF_LEDs; i++) { +#ifdef FASTLED leds[i].r = b; leds[i].g = b; leds[i].b = b; +#endif +#ifdef ADAFRUIT_NEOPIXEL + pixels.setPixelColor(i, pixels.Color(b, b, b)); +#endif } +#ifdef FASTLED FastLED.show(); +#endif +#ifdef ADAFRUIT_NEOPIXEL + pixels.show(); +#endif + break; case 2: // set brightness for one LED n = strtol(tokens[0], NULL, 10); b = strtol(tokens[1], NULL, 10); if (n >= 0 && n < NUM_OF_LEDs) { +#ifdef FASTLED leds[n].r = b; leds[n].g = b; leds[n].b = b; FastLED.show(); +#endif +#ifdef ADAFRUIT_NEOPIXEL + pixels.setPixelColor(n, pixels.Color(b, b, b)); + pixels.show(); +#endif } break; } @@ -197,17 +236,33 @@ void callback(char* topic, byte* payload, unsigned int length) { // on, off, color word for all LEDs colors = evaluationColorWord(tokens[0]); for (uint8_t i = 0; i < NUM_OF_LEDs; i++) { +#ifdef FASTLED leds[i] = colors; +#endif +#ifdef ADAFRUIT_NEOPIXEL + pixels.setPixelColor(i, pixels.Color(colors.r, colors.g, colors.b)); +#endif } +#ifdef FASTLED FastLED.show(); +#endif +#ifdef ADAFRUIT_NEOPIXEL + pixels.show(); +#endif break; case 2: // token0 = LED number, token1 = color n = strtol(tokens[0], NULL, 10); if (n >= 0 && n < NUM_OF_LEDs) { colors = evaluationColorWord(tokens[1]); +#ifdef FASTLED leds[n] = colors; FastLED.show(); +#endif +#ifdef ADAFRUIT_NEOPIXEL + pixels.setPixelColor(n, pixels.Color(colors.r, colors.g, colors.b)); + pixels.show(); +#endif } break; case 3: @@ -216,11 +271,21 @@ void callback(char* topic, byte* payload, unsigned int length) { green = strtol(tokens[1], NULL, 10); blue = strtol(tokens[2], NULL, 10); for (uint8_t i = 0; i < NUM_OF_LEDs; i++) { +#ifdef FASTLED leds[i].r = red; leds[i].g = green; leds[i].b = blue; +#endif +#ifdef ADAFRUIT_NEOPIXEL + pixels.setPixelColor(i, pixels.Color(red, green, blue)); +#endif } +#ifdef FASTLED FastLED.show(); +#endif +#ifdef ADAFRUIT_NEOPIXEL + pixels.show(); +#endif break; case 4: // token0 = LED number, token1 = red, token2 = green, token3 = blue @@ -229,10 +294,16 @@ void callback(char* topic, byte* payload, unsigned int length) { red = strtol(tokens[1], NULL, 10); green = strtol(tokens[2], NULL, 10); blue = strtol(tokens[3], NULL, 10); +#ifdef FASTLED leds[n].r = red; leds[n].g = green; leds[n].b = blue; FastLED.show(); +#endif +#ifdef ADAFRUIT_NEOPIXEL + pixels.setPixelColor(n, pixels.Color(red, green, blue)); + pixels.show(); +#endif } break; } @@ -291,7 +362,13 @@ void setupProduction() { setup_wifi(); client.setServer(configBlock.mqttBroker, configBlock.mqttPort); - FastLED.addLeds(leds, NUM_OF_LEDs); +#ifdef FASTLED + // FastLED.addLeds(leds, NUM_OF_LEDs); + FastLED.addLeds(leds, NUM_OF_LEDs); +#endif +#ifdef ADAFRUIT_NEOPIXEL + pixels.begin(); +#endif }