Skip to content

Commit f4f7432

Browse files
committed
🚧 WIP, dsx - added message
1 parent c10dca5 commit f4f7432

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

src/components/ds18x20/controller.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,18 @@ bool DS18X20Controller::Handle_Ds18x20Add(pb_istream_t *stream) {
2424
WS_DEBUG_PRINTLN("ERROR: Unable to decode Ds18x20Add message");
2525
return false;
2626
}
27-
// Pass the decoded message to the hardware
28-
// TODO: Brent you were here and looking at this:
29-
// https://github.com/pstolarz/OneWireNg/blob/master/examples/arduino/DallasTemperature/DallasTemperature.ino#L125
27+
// Extract the OneWire pin from the message
28+
uint8_t pin_name = atoi(_DS18X20_model->GetDS18x20AddMsg()->onewire_pin + 1);
29+
30+
// Initialize the DS18X20Hardware object
31+
DS18X20Hardware new_dsx_driver(pin_name);
32+
new_dsx_driver.setResolution(
33+
_DS18X20_model->GetDS18x20AddMsg()->sensor_resolution);
34+
35+
// Add the DS18X20Hardware object to the vector of hardware objects
36+
_DS18X20_pins.push_back(new_dsx_driver);
37+
38+
// TODO: We should publish back an Added message to the broker
3039

3140
return true;
3241
}

src/components/ds18x20/model.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,27 @@ bool DS18X20Model::DecodeDS18x20Add(pb_istream_t *stream) {
2626
// Attempt to decode the stream into a Ds18x20Add message
2727
return pb_decode(stream, wippersnapper_ds18x20_Ds18x20Add_fields,
2828
&_msg_DS18x20Add);
29+
}
30+
31+
wippersnapper_ds18x20_Ds18x20Add *DS18X20Model::GetDS18x20AddMsg() {
32+
return &_msg_DS18x20Add;
33+
}
34+
35+
bool DS18X20Model::EncodeDS18x20Added(char *onewire_pin, bool is_init) {
36+
// Fill the Ds18x20Added message
37+
_msg_DS18x20Added = wippersnapper_ds18x20_Ds18x20Added_init_zero;
38+
_msg_DS18x20Added.is_initialized = is_init;
39+
strcpy(_msg_DS18x20Added.onewire_pin, onewire_pin);
40+
41+
// Encode the Ds18x20Added message
42+
size_t sz_aio_event_msg;
43+
if (!pb_get_encoded_size(&sz_aio_event_msg,
44+
wippersnapper_ds18x20_Ds18x20Added_fields,
45+
&_msg_DS18x20Added))
46+
return false;
47+
48+
uint8_t buf[sz_aio_event_msg];
49+
pb_ostream_t msg_stream = pb_ostream_from_buffer(buf, sizeof(buf));
50+
return pb_encode(&msg_stream, wippersnapper_ds18x20_Ds18x20Added_fields,
51+
&_msg_DS18x20Added);
2952
}

src/components/ds18x20/model.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@ class DS18X20Model {
2929
// Ds18x20Add Message
3030
bool DecodeDS18x20Add(pb_istream_t *stream);
3131
wippersnapper_ds18x20_Ds18x20Add *GetDS18x20AddMsg();
32+
// Ds18x20Remove Message
33+
bool EncodeDS18x20Added(char *onewire_pin, bool is_init);
3234

3335
private:
3436
wippersnapper_ds18x20_Ds18x20Add
3537
_msg_DS18x20Add; ///< wippersnapper_ds18x20_Ds18x20Add message
38+
wippersnapper_ds18x20_Ds18x20Added
39+
_msg_DS18x20Added; ///< wippersnapper_ds18x20_Ds18x20Added message
3640
};
3741
#endif // WS_DIGITALIO_MODEL_H

0 commit comments

Comments
 (0)