From f6059e5bb298e2cdc5916f0271d835664f03904a Mon Sep 17 00:00:00 2001 From: Lukas Bachschwell Date: Sun, 17 Jun 2018 22:40:10 +0200 Subject: [PATCH] Lighmodes working --- src/lights.h | 8 +++++++- src/receiver.cpp | 13 +++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/lights.h b/src/lights.h index 2c33974..f8868c1 100644 --- a/src/lights.h +++ b/src/lights.h @@ -3,7 +3,7 @@ #define NUM_LEDS 40 #define PIN_STRIP 17 bool shouldUpdateLights = false; -int lightMode = 0; +uint8_t lightMode = 0; Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM_LEDS, PIN_STRIP, NEO_GRB + NEO_KHZ800); @@ -60,21 +60,27 @@ void lightBackFront() { void updateLights() { if(lightActive) { + Serial.println("light active"); switch(lightMode) { case 0: lightBackFront(); + Serial.println("normal"); break; case 1: lightBlinkers(true); // left + Serial.println("blink"); break; case 2: lightBlinkers(false); // right + Serial.println("plink"); break; case 3: lightPolice(); + Serial.println("plice"); break; } }else { + Serial.println("light inactive"); lightOff(); } diff --git a/src/receiver.cpp b/src/receiver.cpp index 55f27f2..a28065f 100644 --- a/src/receiver.cpp +++ b/src/receiver.cpp @@ -53,7 +53,7 @@ uint8_t sendSpeedDecimals = 0; long lastPacket = 0; bool isConnected = false; - +uint8_t oldOptions = 0; #define FANS_AUTO 0 #define FANS_ON 1 #define FANS_OFF 2 @@ -63,13 +63,14 @@ int fanMode = FANS_AUTO; #include "lights.h" void setBoardOptions(uint8_t options) { - if(lightActive != (options >> 4) & 1) { - lightActive = (options >> 4) & 1; + if(options != oldOptions) { + oldOptions = options; shouldUpdateLights = true; + Serial.println("true2"); } lightMode = options & 3; - + lightActive = (options >> 3) & 1; fanMode = (options >> 2) & 3; } @@ -130,7 +131,8 @@ void OnDataRecv(const uint8_t *mac_addr, const uint8_t *data, int data_len) { // Could check mac here for some security writeServos(recData[0], recData[1]); setBoardOptions(recData[2]); - + Serial.print("recieved: "); + Serial.println(recData[2], BIN); display.clear(); char buf[25]; sprintf(buf, "1: %i | 2: %i", recData[0], recData[1]); @@ -311,7 +313,6 @@ void setup() { Serial.println("ESPNow Init Failed"); ESP.restart(); } - esp_now_set_self_role(ESP_NOW_ROLE_COMBO); // Once ESPNow is successfully Init, we will register for recv CB to // get recv packer info.