Skip to content

Commit c10dca5

Browse files
committed
implement setup for dsx, remove deps that conflict
1 parent ed44d24 commit c10dca5

File tree

10 files changed

+75
-456
lines changed

10 files changed

+75
-456
lines changed

platformio.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ lib_deps =
7272
adafruit/Adafruit MQTT Library
7373
bblanchon/ArduinoJson
7474
https://github.com/pstolarz/OneWireNg.git
75-
https://github.com/pstolarz/Arduino-Temperature-Control-Library.git#OneWireNg
7675
https://github.com/Sensirion/arduino-sht.git
7776
https://github.com/Sensirion/arduino-i2c-scd4x.git
7877
https://github.com/Sensirion/arduino-i2c-sen5x.git

src/Wippersnapper.cpp

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ Wippersnapper::Wippersnapper() {
6666

6767
// UART
6868
WS._uartComponent = new ws_uart();
69-
70-
// DallasSemi (OneWire)
71-
WS._ds18x20Component = new ws_ds18x20();
7269
};
7370

7471
/**************************************************************************/
@@ -1319,43 +1316,6 @@ void cbPWMMsg(char *data, uint16_t len) {
13191316
bool cbDecodeDs18x20Msg(pb_istream_t *stream, const pb_field_t *field,
13201317
void **arg) {
13211318
(void)arg; // marking unused parameter to avoid compiler warning
1322-
if (field->tag ==
1323-
wippersnapper_signal_v1_Ds18x20Request_req_ds18x20_init_tag) {
1324-
WS_DEBUG_PRINTLN("[Message Type] Init. DS Sensor");
1325-
// Attempt to decode contents of DS18x20 message
1326-
wippersnapper_ds18x20_v1_Ds18x20InitRequest msgDS18xInitReq =
1327-
wippersnapper_ds18x20_v1_Ds18x20InitRequest_init_zero;
1328-
1329-
if (!ws_pb_decode(stream,
1330-
wippersnapper_ds18x20_v1_Ds18x20InitRequest_fields,
1331-
&msgDS18xInitReq)) {
1332-
WS_DEBUG_PRINTLN("ERROR: Could not decode "
1333-
"wippersnapper_ds18x20_v1_Ds18x20InitRequest");
1334-
return false; // fail out if we can't decode the request
1335-
}
1336-
WS_DEBUG_PRINT("Adding DS18x20 Component...");
1337-
if (!WS._ds18x20Component->addDS18x20(&msgDS18xInitReq))
1338-
return false;
1339-
WS_DEBUG_PRINTLN("Added!");
1340-
} else if (field->tag ==
1341-
wippersnapper_signal_v1_Ds18x20Request_req_ds18x20_deinit_tag) {
1342-
WS_DEBUG_PRINTLN("[Message Type] De-init. DS Sensor");
1343-
// Attempt to decode contents of message
1344-
wippersnapper_ds18x20_v1_Ds18x20DeInitRequest msgDS18xDeInitReq =
1345-
wippersnapper_ds18x20_v1_Ds18x20DeInitRequest_init_zero;
1346-
if (!ws_pb_decode(stream,
1347-
wippersnapper_ds18x20_v1_Ds18x20DeInitRequest_fields,
1348-
&msgDS18xDeInitReq)) {
1349-
WS_DEBUG_PRINTLN("ERROR: Could not decode "
1350-
"wippersnapper_ds18x20_v1_Ds18x20DeInitRequest");
1351-
return false; // fail out if we can't decode the request
1352-
}
1353-
// exec. deinit request
1354-
WS._ds18x20Component->deleteDS18x20(&msgDS18xDeInitReq);
1355-
} else {
1356-
WS_DEBUG_PRINTLN("ERROR: DS Message type not found!");
1357-
return false;
1358-
}
13591319
return true;
13601320
}
13611321

@@ -2876,10 +2836,6 @@ ws_status_t Wippersnapper::run() {
28762836
WS._i2cPort0->update();
28772837
WS.feedWDT();
28782838

2879-
// Process DS18x20 sensor events
2880-
WS._ds18x20Component->update();
2881-
WS.feedWDT();
2882-
28832839
// Process UART sensor events
28842840
WS._uartComponent->update();
28852841
WS.feedWDT();

src/Wippersnapper.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
#include "display/ws_display_ui_helper.h"
6565
#endif
6666

67-
#include "components/ds18x20/ws_ds18x20.h"
6867
#include "components/pixels/ws_pixels.h"
6968
#include "components/pwm/ws_pwm.h"
7069
#include "components/servo/ws_servo.h"
@@ -104,7 +103,6 @@ class ws_ledc;
104103
class WipperSnapper_Component_I2C;
105104
class ws_servo;
106105
class ws_pwm;
107-
class ws_ds18x20;
108106
class ws_pixels;
109107
class ws_uart;
110108

@@ -227,7 +225,6 @@ class Wippersnapper {
227225
ws_pixels *_ws_pixelsComponent; ///< ptr to instance of ws_pixels class
228226
ws_pwm *_pwmComponent; ///< Instance of pwm class
229227
ws_servo *_servoComponent; ///< Instance of servo class
230-
ws_ds18x20 *_ds18x20Component; ///< Instance of DS18x20 class
231228
ws_uart *_uartComponent; ///< Instance of UART class
232229

233230
// TODO: does this really need to be global?

src/components/ds18x20/controller.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,19 @@
1414
*/
1515
#include "controller.h"
1616

17-
DS18X20Controller::DS18X20Controller() {
18-
_DS18X20_model = new DS18X20Model();
19-
_DS18X20_hardware = new DS18X20Hardware();
20-
}
17+
DS18X20Controller::DS18X20Controller() { _DS18X20_model = new DS18X20Model(); }
2118

22-
DS18X20Controller::~DS18X20Controller() {
23-
delete _DS18X20_model;
24-
delete _DS18X20_hardware;
25-
}
19+
DS18X20Controller::~DS18X20Controller() { delete _DS18X20_model; }
2620

2721
bool DS18X20Controller::Handle_Ds18x20Add(pb_istream_t *stream) {
28-
// TODO: This requires an implementation
22+
// Attempt to decode the incoming message into a Ds18x20Add message
23+
if (!_DS18X20_model->DecodeDS18x20Add(stream)) {
24+
WS_DEBUG_PRINTLN("ERROR: Unable to decode Ds18x20Add message");
25+
return false;
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
30+
2931
return true;
3032
}

src/components/ds18x20/controller.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ class DS18X20Controller {
3535
bool Handle_Ds18x20Add(pb_istream_t *stream);
3636

3737
private:
38-
DS18X20Model *_DS18X20_model; ///< ds18x20 model
39-
DS18X20Hardware *_DS18X20_hardware; ///< ds18x20 hardware
38+
DS18X20Model *_DS18X20_model; ///< ds18x20 model
39+
std::vector<DS18X20Hardware>
40+
_DS18X20_pins; ///< Vector containing multiple DS18X20Hardware objects
4041
};
4142
extern Wippersnapper_V2 WsV2; ///< Wippersnapper V2 instance
4243
#endif // WS_DS18X20_CONTROLLER_H

src/components/ds18x20/hardware.cpp

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,39 @@
1414
*/
1515
#include "hardware.h"
1616

17-
DS18X20Hardware::DS18X20Hardware() {
18-
// TODO: Implement this
17+
DS18X20Hardware::DS18X20Hardware(uint8_t onewire_pin) : _drv_therm(_ow) {
18+
new (&_ow) OneWireNg_CurrentPlatform(onewire_pin, false);
1919
}
2020

21-
DS18X20Hardware::~DS18X20Hardware() {
22-
// TODO: Implement this
21+
DS18X20Hardware::~DS18X20Hardware() { delete &_ow; }
22+
23+
void DS18X20Hardware::setResolution(int resolution) {
24+
// Set the resolution of the DS18X20 sensor driver
25+
switch (resolution) {
26+
case 9:
27+
_resolution = DSTherm::Resolution::RES_9_BIT;
28+
break;
29+
case 10:
30+
_resolution = DSTherm::Resolution::RES_10_BIT;
31+
break;
32+
case 11:
33+
_resolution = DSTherm::Resolution::RES_11_BIT;
34+
break;
35+
case 12:
36+
_resolution = DSTherm::Resolution::RES_12_BIT;
37+
break;
38+
default:
39+
_resolution =
40+
DSTherm::Resolution::RES_12_BIT; // Default to 12-bit resolution
41+
break;
42+
}
43+
44+
// Set common resolution for all sensors.
45+
// Th, Tl (high/low alarm triggers) are set to 0.
46+
_drv_therm.writeScratchpadAll(0, 0, _resolution);
47+
48+
// The configuration above is stored in volatile sensors scratchpad
49+
// memory and will be lost after power unplug. Therefore store the
50+
// configuration permanently in sensors EEPROM.
51+
_drv_therm.copyScratchpadAll(false);
2352
}

src/components/ds18x20/hardware.h

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,9 @@
1616
#define WS_DS18X20_HARDWARE_H
1717
#include "Wippersnapper_V2.h"
1818

19-
struct DS18X20_Pin {
20-
// Specific to the DS18X20 sensor object
21-
// TODO: Implement this!
22-
// From the PB model
23-
char onewire_pin[5]; ///< Pin utilized by the OneWire bus, used for addressing
24-
float period; ///< The desired period to read the sensor, in seconds
25-
float prv_period; ///< Last time the sensor was polled, in seconds
26-
pb_size_t
27-
sensor_types_count; ///< Number of sensor types to read from the sensor
28-
wippersnapper_sensor_SensorType
29-
sensor_types[2]; ///< DS sensor type(s) to read from the sensor
30-
}; ///< DS18X20 Pin Object
19+
#include "OneWireNg_CurrentPlatform.h"
20+
#include "drivers/DSTherm.h"
21+
#include "utils/Placeholder.h"
3122

3223
/**************************************************************************/
3324
/*!
@@ -37,9 +28,24 @@ struct DS18X20_Pin {
3728
/**************************************************************************/
3829
class DS18X20Hardware {
3930
public:
40-
DS18X20Hardware();
31+
DS18X20Hardware(uint8_t onewire_pin);
4132
~DS18X20Hardware();
33+
void setResolution(int resolution);
34+
4235
private:
43-
std::vector<DS18X20_Pin> _DS18X20_Pins; ///< Vector of analogio pins
36+
// NOTE: We are going to try definining a vector of DS18X20Hardware objects
37+
// iwthin the controller so instead of a struct, these are all assigned to
38+
// this class
39+
Placeholder<OneWireNg_CurrentPlatform> _ow; ///< OneWire bus object
40+
DSTherm _drv_therm; ///< DS18X20 driver object
41+
DSTherm::Resolution _resolution; ///< Resolution of the DS18X20 sensor
42+
// From the PB model
43+
uint8_t onewire_pin; ///< Pin utilized by the OneWire bus, used for addressing
44+
float _period; ///< The desired period to read the sensor, in seconds
45+
float _prv_period; ///< Last time the sensor was polled, in seconds
46+
pb_size_t
47+
_sensor_types_count; ///< Number of sensor types to read from the sensor
48+
wippersnapper_sensor_SensorType
49+
_sensor_types[2]; ///< DS sensor type(s) to read from the sensor
4450
};
4551
#endif // WS_DS18X20_HARDWARE_H

src/components/ds18x20/model.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,11 @@ DS18X20Model::DS18X20Model() {
1919
_msg_DS18x20Add = wippersnapper_ds18x20_Ds18x20Add_init_zero;
2020
}
2121

22-
DS18X20Model::~DS18X20Model() {}
22+
DS18X20Model::~DS18X20Model() {}
23+
24+
bool DS18X20Model::DecodeDS18x20Add(pb_istream_t *stream) {
25+
_msg_DS18x20Add = wippersnapper_ds18x20_Ds18x20Add_init_zero;
26+
// Attempt to decode the stream into a Ds18x20Add message
27+
return pb_decode(stream, wippersnapper_ds18x20_Ds18x20Add_fields,
28+
&_msg_DS18x20Add);
29+
}

0 commit comments

Comments
 (0)