Skip to content

Commit 6e5051b

Browse files
authored
Merge pull request #413 from brentru/esp8266-dio-bug
Fix Feather ESP8266 Digital Output Bug
2 parents 99562bb + 853c320 commit 6e5051b

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

src/Wippersnapper.cpp

+7-15
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ bool cbDecodePinConfigMsg(pb_istream_t *stream, const pb_field_t *field,
325325

326326
/**************************************************************************/
327327
/*!
328-
@brief Decodes repeated PinEvents messages.
328+
@brief Decodes repeated PinEvents (digital pin write) messages.
329329
@param stream
330330
Input stream to read from.
331331
@param field
@@ -335,10 +335,10 @@ bool cbDecodePinConfigMsg(pb_istream_t *stream, const pb_field_t *field,
335335
@returns True if successfully decoded, False otherwise.
336336
*/
337337
/**************************************************************************/
338-
bool cbDecodePinEventMsg(pb_istream_t *stream, const pb_field_t *field,
339-
void **arg) {
338+
bool cbDecodeDigitalPinWriteMsg(pb_istream_t *stream, const pb_field_t *field,
339+
void **arg) {
340340
bool is_success = true;
341-
WS_DEBUG_PRINTLN("cbDecodePinEventMsg");
341+
WS_DEBUG_PRINTLN("cbDecodeDigitalPinWriteMsg");
342342

343343
// Decode stream into a PinEvent
344344
wippersnapper_pin_v1_PinEvent pinEventMsg =
@@ -348,17 +348,9 @@ bool cbDecodePinEventMsg(pb_istream_t *stream, const pb_field_t *field,
348348
is_success = false;
349349
}
350350

351+
// execute callback
351352
char *pinName = pinEventMsg.pin_name + 1;
352-
if (pinEventMsg.pin_name[0] == 'D') { // digital pin event
353-
WS._digitalGPIO->digitalWriteSvc(atoi(pinName),
354-
atoi(pinEventMsg.pin_value));
355-
} else if (pinEventMsg.pin_name[0] == 'A') { // analog pin event
356-
// TODO
357-
WS_DEBUG_PRINTLN("ERROR: Analog PinEvent unimplemented!");
358-
} else {
359-
WS_DEBUG_PRINTLN("ERROR: Unable to decode pin event name.");
360-
is_success = false;
361-
}
353+
WS._digitalGPIO->digitalWriteSvc(atoi(pinName), atoi(pinEventMsg.pin_value));
362354

363355
return is_success;
364356
}
@@ -412,7 +404,7 @@ bool cbSignalMsg(pb_istream_t *stream, const pb_field_t *field, void **arg) {
412404
wippersnapper_pin_v1_PinEvents msg =
413405
wippersnapper_pin_v1_PinEvents_init_zero;
414406
// set up callback
415-
msg.list.funcs.decode = cbDecodePinEventMsg;
407+
msg.list.funcs.decode = cbDecodeDigitalPinWriteMsg;
416408
msg.list.arg = field->pData;
417409
// decode each PinEvents sub-message
418410
if (!pb_decode(stream, wippersnapper_pin_v1_PinEvents_fields, &msg)) {

src/components/digitalIO/Wippersnapper_DigitalGPIO.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,12 @@ void Wippersnapper_DigitalGPIO::digitalWriteSvc(uint8_t pinName, int pinValue) {
186186
#if defined(ARDUINO_ESP8266_ADAFRUIT_HUZZAH)
187187
// The Adafruit Feather ESP8266's built-in LED is reverse wired so setting the
188188
// pin LOW will turn the LED on.
189-
if (pinName == 0)
189+
if (pinName == 0) {
190+
WS_DEBUG_PRINTLN("Invert!");
190191
digitalWrite(pinName, !pinValue);
192+
} else {
193+
digitalWrite(pinName, pinValue);
194+
}
191195
#else
192196
digitalWrite(pinName, pinValue);
193197
#endif

0 commit comments

Comments
 (0)