@@ -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)) {
0 commit comments