File tree Expand file tree Collapse file tree 5 files changed +20
-8
lines changed Expand file tree Collapse file tree 5 files changed +20
-8
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,10 @@ bool DS18X20Controller::Handle_Ds18x20Add(pb_istream_t *stream) {
66
66
if (is_initialized) {
67
67
WS_DEBUG_PRINTLN (" Sensor found on OneWire bus and initialized" );
68
68
69
+ // Set the sensor's pin name (non-logical)
70
+ new_dsx_driver->setOneWirePinName (
71
+ _DS18X20_model->GetDS18x20AddMsg ()->onewire_pin );
72
+
69
73
// Set the sensor's resolution
70
74
new_dsx_driver->SetResolution (
71
75
_DS18X20_model->GetDS18x20AddMsg ()->sensor_resolution );
@@ -190,7 +194,7 @@ void DS18X20Controller::update() {
190
194
191
195
// We got a temperature value from the hardware, let's create a new
192
196
// sensor_event
193
- _DS18X20_model->InitDS18x20EventMsg ();
197
+ _DS18X20_model->InitDS18x20EventMsg (temp_dsx_driver. getOneWirePinName () );
194
198
195
199
// Are we reading the temperature in Celsius, Fahrenheit, or both?
196
200
if (temp_dsx_driver.is_read_temp_c ) {
Original file line number Diff line number Diff line change @@ -85,6 +85,14 @@ bool DS18X20Hardware::GetSensor() {
85
85
/* **********************************************************************/
86
86
uint8_t DS18X20Hardware::GetOneWirePin () { return _onewire_pin; }
87
87
88
+ void DS18X20Hardware::setOneWirePinName (const char *prettyOWPinName) {
89
+ strncpy (_onewire_pin_name, prettyOWPinName, sizeof (_onewire_pin_name));
90
+ _onewire_pin_name[sizeof (_onewire_pin_name) - 1 ] = ' \0 ' ;
91
+ }
92
+
93
+ // Return _onewire_pin_name
94
+ const char *DS18X20Hardware::getOneWirePinName () { return _onewire_pin_name; }
95
+
88
96
/* ************************************************************************/
89
97
/* !
90
98
@brief Sets the DS18X20 sensor's resolution.
@@ -179,10 +187,6 @@ bool DS18X20Hardware::ReadTemperatureC() {
179
187
OneWireNg::ErrorCode ec =
180
188
_drv_therm.convertTemp (_sensorId, DSTherm::MAX_CONV_TIME, false );
181
189
182
- // TODO: this is extra debug prints, delete all prints and just return for
183
- // final ver.
184
- WS_DEBUG_PRINT (" Error Code: " );
185
- WS_DEBUG_PRINTLN (ec);
186
190
if (ec != OneWireNg::EC_SUCCESS)
187
191
return false ;
188
192
Original file line number Diff line number Diff line change @@ -31,11 +31,13 @@ class DS18X20Hardware {
31
31
DS18X20Hardware (uint8_t onewire_pin);
32
32
~DS18X20Hardware ();
33
33
void printErrorCode (OneWireNg::ErrorCode ec);
34
+ void setOneWirePinName (const char *prettyOWPinName);
34
35
void SetResolution (int resolution);
35
36
void SetPeriod (float period);
36
37
bool IsTimerExpired ();
37
38
bool GetSensor ();
38
39
uint8_t GetOneWirePin ();
40
+ const char *getOneWirePinName ();
39
41
bool ReadTemperatureC ();
40
42
float GetTemperatureC ();
41
43
float GetTemperatureF ();
@@ -52,7 +54,8 @@ class DS18X20Hardware {
52
54
float _temp_f; // /< Temperature in Fahrenheit
53
55
// From the PB model
54
56
uint8_t
55
- _onewire_pin; // /< Pin utilized by the OneWire bus, used for addressing
57
+ _onewire_pin; // /< Pin utilized by the OneWire bus, used for addressing
58
+ char _onewire_pin_name[5 ]; // /< Name of the OneWire bus pin
56
59
float _period; // /< The desired period to read the sensor, in seconds
57
60
float _prv_period; // /< Last time the sensor was polled, in seconds
58
61
};
Original file line number Diff line number Diff line change @@ -162,9 +162,10 @@ bool DS18X20Model::EncodeDs18x20Event() {
162
162
@brief Initializes the Ds18x20Event message.
163
163
*/
164
164
/* ************************************************************************/
165
- void DS18X20Model::InitDS18x20EventMsg () {
165
+ void DS18X20Model::InitDS18x20EventMsg (const char *ow_pin_name ) {
166
166
_msg_DS18x20Event = wippersnapper_ds18x20_Ds18x20Event_init_zero;
167
167
_msg_DS18x20Event.sensor_events_count = 0 ;
168
+ strcpy (_msg_DS18x20Event.onewire_pin , ow_pin_name);
168
169
}
169
170
170
171
/* ************************************************************************/
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ class DS18X20Model {
41
41
// TODO: move the below to private if we arent using it in controller?
42
42
wippersnapper_ds18x20_Ds18x20Event
43
43
_msg_DS18x20Event; // /< wippersnapper_ds18x20_Ds18x20Event message
44
- void InitDS18x20EventMsg ();
44
+ void InitDS18x20EventMsg (const char *ow_pin_name );
45
45
void addSensorEvent (wippersnapper_sensor_SensorType sensor_type,
46
46
float sensor_value);
47
47
You can’t perform that action at this time.
0 commit comments