Browse Source

Lighmodes working

Lukas Bachschwell 9 months ago
parent
commit
f6059e5bb2
2 changed files with 14 additions and 7 deletions
  1. 7
    1
      src/lights.h
  2. 7
    6
      src/receiver.cpp

+ 7
- 1
src/lights.h View File

@@ -3,7 +3,7 @@
3 3
 #define NUM_LEDS 40
4 4
 #define PIN_STRIP 17
5 5
 bool shouldUpdateLights = false;
6
-int lightMode = 0;
6
+uint8_t lightMode = 0;
7 7
 
8 8
 Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM_LEDS, PIN_STRIP, NEO_GRB + NEO_KHZ800);
9 9
 
@@ -60,21 +60,27 @@ void lightBackFront() {
60 60
 
61 61
 void updateLights() {
62 62
   if(lightActive) {
63
+    Serial.println("light active");
63 64
     switch(lightMode) {
64 65
     case 0:
65 66
       lightBackFront();
67
+      Serial.println("normal");
66 68
       break;
67 69
     case 1:
68 70
       lightBlinkers(true); // left
71
+      Serial.println("blink");
69 72
       break;
70 73
     case 2:
71 74
       lightBlinkers(false); // right
75
+      Serial.println("plink");
72 76
       break;
73 77
     case 3:
74 78
       lightPolice();
79
+      Serial.println("plice");
75 80
       break;
76 81
     }
77 82
   }else {
83
+    Serial.println("light inactive");
78 84
     lightOff();
79 85
   }
80 86
 

+ 7
- 6
src/receiver.cpp View File

@@ -53,7 +53,7 @@ uint8_t sendSpeedDecimals = 0;
53 53
 long lastPacket = 0;
54 54
 
55 55
 bool isConnected = false;
56
-
56
+uint8_t oldOptions = 0;
57 57
 #define FANS_AUTO 0
58 58
 #define FANS_ON 1
59 59
 #define FANS_OFF 2
@@ -63,13 +63,14 @@ int fanMode = FANS_AUTO;
63 63
 
64 64
 #include "lights.h"
65 65
 void setBoardOptions(uint8_t options) {
66
-  if(lightActive != (options >> 4) & 1) {
67
-    lightActive = (options >> 4) & 1;
66
+  if(options != oldOptions) {
67
+    oldOptions = options;
68 68
     shouldUpdateLights = true;
69
+    Serial.println("true2");
69 70
   }
70 71
 
71 72
   lightMode = options & 3;
72
-
73
+  lightActive = (options >> 3) & 1;
73 74
   fanMode = (options >> 2) & 3;
74 75
 }
75 76
 
@@ -130,7 +131,8 @@ void OnDataRecv(const uint8_t *mac_addr, const uint8_t *data, int data_len) {
130 131
   // Could check mac here for some security
131 132
   writeServos(recData[0], recData[1]);
132 133
   setBoardOptions(recData[2]);
133
-
134
+  Serial.print("recieved: ");
135
+  Serial.println(recData[2], BIN);
134 136
   display.clear();
135 137
   char buf[25];
136 138
   sprintf(buf, "1: %i | 2: %i", recData[0], recData[1]);
@@ -311,7 +313,6 @@ void setup() {
311 313
     Serial.println("ESPNow Init Failed");
312 314
     ESP.restart();
313 315
   }
314
-  esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
315 316
 
316 317
   // Once ESPNow is successfully Init, we will register for recv CB to
317 318
   // get recv packer info.

Loading…
Cancel
Save