File tree Expand file tree Collapse file tree 3 files changed +39
-3
lines changed Expand file tree Collapse file tree 3 files changed +39
-3
lines changed Original file line number Diff line number Diff line change @@ -24,9 +24,18 @@ bool DS18X20Controller::Handle_Ds18x20Add(pb_istream_t *stream) {
24
24
WS_DEBUG_PRINTLN (" ERROR: Unable to decode Ds18x20Add message" );
25
25
return false ;
26
26
}
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
30
39
31
40
return true ;
32
41
}
Original file line number Diff line number Diff line change @@ -26,4 +26,27 @@ bool DS18X20Model::DecodeDS18x20Add(pb_istream_t *stream) {
26
26
// Attempt to decode the stream into a Ds18x20Add message
27
27
return pb_decode (stream, wippersnapper_ds18x20_Ds18x20Add_fields,
28
28
&_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);
29
52
}
Original file line number Diff line number Diff line change @@ -29,9 +29,13 @@ class DS18X20Model {
29
29
// Ds18x20Add Message
30
30
bool DecodeDS18x20Add (pb_istream_t *stream);
31
31
wippersnapper_ds18x20_Ds18x20Add *GetDS18x20AddMsg ();
32
+ // Ds18x20Remove Message
33
+ bool EncodeDS18x20Added (char *onewire_pin, bool is_init);
32
34
33
35
private:
34
36
wippersnapper_ds18x20_Ds18x20Add
35
37
_msg_DS18x20Add; // /< wippersnapper_ds18x20_Ds18x20Add message
38
+ wippersnapper_ds18x20_Ds18x20Added
39
+ _msg_DS18x20Added; // /< wippersnapper_ds18x20_Ds18x20Added message
36
40
};
37
41
#endif // WS_DIGITALIO_MODEL_H
You can’t perform that action at this time.
0 commit comments