Skip to content

Commit 4a2ccac

Browse files
committed
🚧 WIP, digitalio - Implement remove pin API
1 parent fbaadb9 commit 4a2ccac

File tree

5 files changed

+48
-3
lines changed

5 files changed

+48
-3
lines changed

src/Wippersnapper_V2.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,6 @@ bool cbDecodeBrokerToDevice(pb_istream_t *stream, const pb_field_t *field,
347347
case wippersnapper_signal_BrokerToDevice_digitalio_remove_tag:
348348
WS_DEBUG_PRINTLN("-> DigitalIO Remove Message Type");
349349
break;
350-
case wippersnapper_signal_BrokerToDevice_digitalio_event_tag:
351-
WS_DEBUG_PRINTLN("-> DigitalIO Event Message Type");
352-
break;
353350
case wippersnapper_signal_BrokerToDevice_digitalio_write_tag:
354351
WS_DEBUG_PRINTLN("-> DigitalIO Write Message Type");
355352
if (!WsV2.digital_io_controller->WriteDigitalIOPin(stream)) {

src/components/digitalIO/controller.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,36 @@ bool DigitalIOController::AddDigitalIOPin(pb_istream_t *stream) {
128128
return true;
129129
}
130130

131+
/***********************************************************************/
132+
/*!
133+
@brief Removes a digital pin from the controller, if it exists
134+
@param stream
135+
The nanopb input stream.
136+
@return True if the digital pin was successfully removed.
137+
*/
138+
/***********************************************************************/
139+
bool DigitalIOController::RemoveDigitalIOPin(pb_istream_t *stream) {
140+
// Attempt to decode the DigitalIORemove message
141+
if (!_dio_model->DecodeDigitalIORemove(stream)) {
142+
WS_DEBUG_PRINTLN("ERROR: Unable to decode DigitalIORemove message!");
143+
return false;
144+
}
145+
146+
// Get the pin's name
147+
int pin_name = atoi(_dio_model->GetDigitalIOAddMsg()->pin_name + 1);
148+
149+
// Bail out if the pin does not exist within controller
150+
if (GetPinIdx(pin_name) == -1) {
151+
WS_DEBUG_PRINTLN(
152+
"ERROR: Unable to find digital output pin on the controller!");
153+
return false;
154+
}
155+
156+
// Deinitialize the pin
157+
_dio_hardware->deinit(pin_name);
158+
return true;
159+
}
160+
131161
/***********************************************************************/
132162
/*!
133163
@brief Get the index of a digital output pin

src/components/digitalIO/controller.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class DigitalIOController {
5353
// Decoder-related Functions
5454
bool AddDigitalIOPin(pb_istream_t *stream);
5555
bool WriteDigitalIOPin(pb_istream_t *stream);
56+
bool RemoveDigitalIOPin(pb_istream_t *stream);
5657
// Encoder-related Functions
5758
void Update();
5859
bool EncodePublishPinEvent(uint8_t pin_name, bool pin_value);

src/components/digitalIO/model.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@ wippersnapper_digitalio_DigitalIOAdd *DigitalIOModel::GetDigitalIOAddMsg() {
4343
return &_msg_dio_add;
4444
}
4545

46+
/***********************************************************************/
47+
/*!
48+
@brief Parses a DigitalIORemove message.
49+
@return DigitalIORemove message object.
50+
*/
51+
/***********************************************************************/
52+
bool DigitalIOModel::DecodeDigitalIORemove(pb_istream_t *stream) {
53+
// Zero-out the DigitalIORemove message struct. to ensure we don't have any
54+
// old data
55+
_msg_dio_remove = wippersnapper_digitalio_DigitalIORemove_init_default;
56+
57+
// Decode the stream into a DigitalIORemove message
58+
return pb_decode(stream, wippersnapper_digitalio_DigitalIORemove_fields,
59+
&_msg_dio_remove);
60+
}
61+
4662
/***********************************************************************/
4763
/*!
4864
@brief Gets a DigitalIORemove message.

src/components/digitalIO/model.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class DigitalIOModel {
3030
bool DecodeDigitalIOAdd(pb_istream_t *stream);
3131
wippersnapper_digitalio_DigitalIOAdd *GetDigitalIOAddMsg();
3232
// DigitalIORemove
33+
bool DecodeDigitalIORemove(pb_istream_t *stream);
3334
wippersnapper_digitalio_DigitalIORemove *GetDigitalIORemove();
3435
// DigitalIOWrite
3536
bool DecodeDigitalIOWrite(pb_istream_t *stream);

0 commit comments

Comments
 (0)