Skip to content

Commit

Permalink
Merge pull request #380 from brentru/fix-esp8266-led-state
Browse files Browse the repository at this point in the history
Fix Adafruit Feather HUZZAH ESP8266 builtin LED behavior
  • Loading branch information
brentru authored Dec 2, 2022
2 parents 157d942 + e01c00e commit 61a3800
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Wippersnapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1998,6 +1998,7 @@ void Wippersnapper::pingBroker() {
}
// blink status LED every STATUS_LED_KAT_BLINK_TIME millis
if (millis() > (_prvKATBlink + STATUS_LED_KAT_BLINK_TIME)) {
WS_DEBUG_PRINTLN("KAT BLINK!");
statusLEDBlink(WS_LED_STATUS_KAT);
_prvKATBlink = millis();
}
Expand Down
17 changes: 17 additions & 0 deletions src/components/digitalIO/Wippersnapper_DigitalGPIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,15 @@ void Wippersnapper_DigitalGPIO::initDigitalPin(
WS_DEBUG_PRINT("Configured digital output pin on D");
WS_DEBUG_PRINTLN(pinName);
pinMode(pinName, OUTPUT);
// Initialize LOW
#if defined(ARDUINO_ESP8266_ADAFRUIT_HUZZAH)
// The Adafruit Feather ESP8266's built-in LED is reverse wired so setting
// the pin LOW will turn the LED on.
digitalWrite(STATUS_LED_PIN, !0);
#else
pinMode(pinName, OUTPUT);
digitalWrite(pinName, LOW); // initialize LOW
#endif
} else if (
direction ==
wippersnapper_pin_v1_ConfigurePinRequest_Direction_DIRECTION_INPUT) {
Expand Down Expand Up @@ -173,7 +181,16 @@ void Wippersnapper_DigitalGPIO::digitalWriteSvc(uint8_t pinName, int pinValue) {
WS_DEBUG_PRINT(pinName);
WS_DEBUG_PRINT(" to ");
WS_DEBUG_PRINTLN(pinValue);

// Write to the GPIO pin
#if defined(ARDUINO_ESP8266_ADAFRUIT_HUZZAH)
// The Adafruit Feather ESP8266's built-in LED is reverse wired so setting the
// pin LOW will turn the LED on.
if (pinName == 0)
digitalWrite(pinName, !pinValue);
#else
digitalWrite(pinName, pinValue);
#endif
}

/**********************************************************/
Expand Down
29 changes: 26 additions & 3 deletions src/components/statusLED/Wippersnapper_StatusLED.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,19 @@ bool statusLEDInit() {
#endif

#ifdef USE_STATUS_LED
pinMode(STATUS_LED_PIN, OUTPUT); // Initialize LED
digitalWrite(STATUS_LED_PIN, 0); // Turn OFF LED
WS.lockStatusLED = true; // set global pin "lock" flag
pinMode(STATUS_LED_PIN,
OUTPUT); // Initialize LED

// Turn OFF LED
#if defined(ARDUINO_ESP8266_ADAFRUIT_HUZZAH)
// The Adafruit Feather ESP8266's built-in LED is reverse
// wired so setting the pin LOW will turn the LED on.
digitalWrite(STATUS_LED_PIN, !0);
#else
digitalWrite(STATUS_LED_PIN, 0);
#endif

WS.lockStatusLED = true; // set global pin "lock" flag
is_success = true;
#endif
return is_success;
Expand Down Expand Up @@ -195,8 +205,15 @@ void statusLEDFade(uint32_t color, int numFades = 3) {
pinMode(STATUS_LED_PIN, OUTPUT);
#endif

// turn OFF ESP8266's status LED
#if defined(ARDUINO_ESP8266_ADAFRUIT_HUZZAH)
// The Adafruit Feather ESP8266's built-in LED is reverse wired
// clear status LED color
setStatusLEDColor(BLACK ^ 1);
#else
// clear status LED color
setStatusLEDColor(BLACK);
#endif
}

/****************************************************************************/
Expand Down Expand Up @@ -275,6 +292,12 @@ void statusLEDBlink(ws_led_status_t statusState) {
setStatusLEDColor(ledColor);
delay(100);
setStatusLEDColor(BLACK);
#if defined(ARDUINO_ESP8266_ADAFRUIT_HUZZAH)
// The Adafruit Feather ESP8266's built-in LED is reverse wired
setStatusLEDColor(BLACK ^ 1);
#else
setStatusLEDColor(BLACK);
#endif
delay(100);
blinkNum--;
}
Expand Down

0 comments on commit 61a3800

Please sign in to comment.