Skip to content

Commit 7374287

Browse files
committed
🐛 Fix DSx bug, onewirePin not added to ds18x20Evetn messages
1 parent acab0f1 commit 7374287

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

src/components/ds18x20/controller.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ bool DS18X20Controller::Handle_Ds18x20Add(pb_istream_t *stream) {
6666
if (is_initialized) {
6767
WS_DEBUG_PRINTLN("Sensor found on OneWire bus and initialized");
6868

69+
// Set the sensor's pin name (non-logical)
70+
new_dsx_driver->setOneWirePinName(
71+
_DS18X20_model->GetDS18x20AddMsg()->onewire_pin);
72+
6973
// Set the sensor's resolution
7074
new_dsx_driver->SetResolution(
7175
_DS18X20_model->GetDS18x20AddMsg()->sensor_resolution);
@@ -190,7 +194,7 @@ void DS18X20Controller::update() {
190194

191195
// We got a temperature value from the hardware, let's create a new
192196
// sensor_event
193-
_DS18X20_model->InitDS18x20EventMsg();
197+
_DS18X20_model->InitDS18x20EventMsg(temp_dsx_driver.getOneWirePinName());
194198

195199
// Are we reading the temperature in Celsius, Fahrenheit, or both?
196200
if (temp_dsx_driver.is_read_temp_c) {

src/components/ds18x20/hardware.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ bool DS18X20Hardware::GetSensor() {
8585
/***********************************************************************/
8686
uint8_t DS18X20Hardware::GetOneWirePin() { return _onewire_pin; }
8787

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+
8896
/*************************************************************************/
8997
/*!
9098
@brief Sets the DS18X20 sensor's resolution.
@@ -179,10 +187,6 @@ bool DS18X20Hardware::ReadTemperatureC() {
179187
OneWireNg::ErrorCode ec =
180188
_drv_therm.convertTemp(_sensorId, DSTherm::MAX_CONV_TIME, false);
181189

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);
186190
if (ec != OneWireNg::EC_SUCCESS)
187191
return false;
188192

src/components/ds18x20/hardware.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ class DS18X20Hardware {
3131
DS18X20Hardware(uint8_t onewire_pin);
3232
~DS18X20Hardware();
3333
void printErrorCode(OneWireNg::ErrorCode ec);
34+
void setOneWirePinName(const char *prettyOWPinName);
3435
void SetResolution(int resolution);
3536
void SetPeriod(float period);
3637
bool IsTimerExpired();
3738
bool GetSensor();
3839
uint8_t GetOneWirePin();
40+
const char *getOneWirePinName();
3941
bool ReadTemperatureC();
4042
float GetTemperatureC();
4143
float GetTemperatureF();
@@ -52,7 +54,8 @@ class DS18X20Hardware {
5254
float _temp_f; ///< Temperature in Fahrenheit
5355
// From the PB model
5456
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
5659
float _period; ///< The desired period to read the sensor, in seconds
5760
float _prv_period; ///< Last time the sensor was polled, in seconds
5861
};

src/components/ds18x20/model.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,10 @@ bool DS18X20Model::EncodeDs18x20Event() {
162162
@brief Initializes the Ds18x20Event message.
163163
*/
164164
/*************************************************************************/
165-
void DS18X20Model::InitDS18x20EventMsg() {
165+
void DS18X20Model::InitDS18x20EventMsg(const char *ow_pin_name) {
166166
_msg_DS18x20Event = wippersnapper_ds18x20_Ds18x20Event_init_zero;
167167
_msg_DS18x20Event.sensor_events_count = 0;
168+
strcpy(_msg_DS18x20Event.onewire_pin, ow_pin_name);
168169
}
169170

170171
/*************************************************************************/

src/components/ds18x20/model.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class DS18X20Model {
4141
// TODO: move the below to private if we arent using it in controller?
4242
wippersnapper_ds18x20_Ds18x20Event
4343
_msg_DS18x20Event; ///< wippersnapper_ds18x20_Ds18x20Event message
44-
void InitDS18x20EventMsg();
44+
void InitDS18x20EventMsg(const char *ow_pin_name);
4545
void addSensorEvent(wippersnapper_sensor_SensorType sensor_type,
4646
float sensor_value);
4747

0 commit comments

Comments
 (0)