Skip to content

Commit 61a3800

Browse files
authored
Merge pull request #380 from brentru/fix-esp8266-led-state
Fix Adafruit Feather HUZZAH ESP8266 builtin LED behavior
2 parents 157d942 + e01c00e commit 61a3800

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

src/Wippersnapper.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,6 +1998,7 @@ void Wippersnapper::pingBroker() {
19981998
}
19991999
// blink status LED every STATUS_LED_KAT_BLINK_TIME millis
20002000
if (millis() > (_prvKATBlink + STATUS_LED_KAT_BLINK_TIME)) {
2001+
WS_DEBUG_PRINTLN("KAT BLINK!");
20012002
statusLEDBlink(WS_LED_STATUS_KAT);
20022003
_prvKATBlink = millis();
20032004
}

src/components/digitalIO/Wippersnapper_DigitalGPIO.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,15 @@ void Wippersnapper_DigitalGPIO::initDigitalPin(
7373
WS_DEBUG_PRINT("Configured digital output pin on D");
7474
WS_DEBUG_PRINTLN(pinName);
7575
pinMode(pinName, OUTPUT);
76+
// Initialize LOW
77+
#if defined(ARDUINO_ESP8266_ADAFRUIT_HUZZAH)
78+
// The Adafruit Feather ESP8266's built-in LED is reverse wired so setting
79+
// the pin LOW will turn the LED on.
80+
digitalWrite(STATUS_LED_PIN, !0);
81+
#else
82+
pinMode(pinName, OUTPUT);
7683
digitalWrite(pinName, LOW); // initialize LOW
84+
#endif
7785
} else if (
7886
direction ==
7987
wippersnapper_pin_v1_ConfigurePinRequest_Direction_DIRECTION_INPUT) {
@@ -173,7 +181,16 @@ void Wippersnapper_DigitalGPIO::digitalWriteSvc(uint8_t pinName, int pinValue) {
173181
WS_DEBUG_PRINT(pinName);
174182
WS_DEBUG_PRINT(" to ");
175183
WS_DEBUG_PRINTLN(pinValue);
184+
185+
// Write to the GPIO pin
186+
#if defined(ARDUINO_ESP8266_ADAFRUIT_HUZZAH)
187+
// The Adafruit Feather ESP8266's built-in LED is reverse wired so setting the
188+
// pin LOW will turn the LED on.
189+
if (pinName == 0)
190+
digitalWrite(pinName, !pinValue);
191+
#else
176192
digitalWrite(pinName, pinValue);
193+
#endif
177194
}
178195

179196
/**********************************************************/

src/components/statusLED/Wippersnapper_StatusLED.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,19 @@ bool statusLEDInit() {
6767
#endif
6868

6969
#ifdef USE_STATUS_LED
70-
pinMode(STATUS_LED_PIN, OUTPUT); // Initialize LED
71-
digitalWrite(STATUS_LED_PIN, 0); // Turn OFF LED
72-
WS.lockStatusLED = true; // set global pin "lock" flag
70+
pinMode(STATUS_LED_PIN,
71+
OUTPUT); // Initialize LED
72+
73+
// Turn OFF LED
74+
#if defined(ARDUINO_ESP8266_ADAFRUIT_HUZZAH)
75+
// The Adafruit Feather ESP8266's built-in LED is reverse
76+
// wired so setting the pin LOW will turn the LED on.
77+
digitalWrite(STATUS_LED_PIN, !0);
78+
#else
79+
digitalWrite(STATUS_LED_PIN, 0);
80+
#endif
81+
82+
WS.lockStatusLED = true; // set global pin "lock" flag
7383
is_success = true;
7484
#endif
7585
return is_success;
@@ -195,8 +205,15 @@ void statusLEDFade(uint32_t color, int numFades = 3) {
195205
pinMode(STATUS_LED_PIN, OUTPUT);
196206
#endif
197207

208+
// turn OFF ESP8266's status LED
209+
#if defined(ARDUINO_ESP8266_ADAFRUIT_HUZZAH)
210+
// The Adafruit Feather ESP8266's built-in LED is reverse wired
211+
// clear status LED color
212+
setStatusLEDColor(BLACK ^ 1);
213+
#else
198214
// clear status LED color
199215
setStatusLEDColor(BLACK);
216+
#endif
200217
}
201218

202219
/****************************************************************************/
@@ -275,6 +292,12 @@ void statusLEDBlink(ws_led_status_t statusState) {
275292
setStatusLEDColor(ledColor);
276293
delay(100);
277294
setStatusLEDColor(BLACK);
295+
#if defined(ARDUINO_ESP8266_ADAFRUIT_HUZZAH)
296+
// The Adafruit Feather ESP8266's built-in LED is reverse wired
297+
setStatusLEDColor(BLACK ^ 1);
298+
#else
299+
setStatusLEDColor(BLACK);
300+
#endif
278301
delay(100);
279302
blinkNum--;
280303
}

0 commit comments

Comments
 (0)