Skip to content

Commit 81296f6

Browse files
committed
🚧 WIP, dsx - Sketch out ds18x20 classes
1 parent 706652f commit 81296f6

File tree

8 files changed

+205
-6
lines changed

8 files changed

+205
-6
lines changed

src/Wippersnapper_V2.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ Wippersnapper_V2::Wippersnapper_V2() {
6565
// UART
6666
WsV2._uartComponentV2 = new ws_uart();
6767

68-
// DallasSemi (OneWire)
69-
WsV2._ds18x20ComponentV2 = new ws_ds18x20();
70-
7168
// Initialize model classes
7269
WsV2.sensorModel = new SensorModel();
7370

src/Wippersnapper_V2.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656

5757
// Components (API v1)
5858
#include "components/analogIO/Wippersnapper_AnalogIO.h"
59-
#include "components/ds18x20/ws_ds18x20.h"
6059
#include "components/i2c/WipperSnapper_I2C.h"
6160
#include "components/pixels/ws_pixels.h"
6261
#include "components/pwm/ws_pwm.h"
@@ -107,7 +106,6 @@ class ws_ledc;
107106
class WipperSnapper_Component_I2C;
108107
class ws_servo;
109108
class ws_pwm;
110-
class ws_ds18x20;
111109
class ws_pixels;
112110
class ws_uart;
113111

@@ -214,7 +212,6 @@ class Wippersnapper_V2 {
214212
ws_pixels *_ws_pixelsComponentV2; ///< ptr to instance of ws_pixels class
215213
ws_pwm *_pwmComponentV2; ///< Instance of pwm class
216214
ws_servo *_servoComponentV2; ///< Instance of servo class
217-
ws_ds18x20 *_ds18x20ComponentV2; ///< Instance of DS18x20 class
218215
ws_uart *_uartComponentV2; ///< Instance of UART class
219216

220217
// API v2 Components
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*!
2+
* @file controller.cpp
3+
*
4+
* Controller for the ds18x20.proto API
5+
*
6+
* Adafruit invests time and resources providing this open source code,
7+
* please support Adafruit and open-source hardware by purchasing
8+
* products from Adafruit!
9+
*
10+
* Copyright (c) Brent Rubell 2024 for Adafruit Industries.
11+
*
12+
* BSD license, all text here must be included in any redistribution.
13+
*
14+
*/
15+
#include "controller.h"
16+
17+
DS18X20Controller::DS18X20Controller() {
18+
_DS18X20_model = new DS18X20Model();
19+
_DS18X20_hardware = new DS18X20Hardware();
20+
}
21+
22+
DS18X20Controller::~DS18X20Controller() {
23+
delete _DS18X20_model;
24+
delete _DS18X20_hardware;
25+
}
26+
27+
bool DS18X20Controller::Handle_Ds18x20Add(pb_istream_t *stream) {
28+
// TODO: This requires an implementation
29+
return true;
30+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*!
2+
* @file controller.h
3+
*
4+
* Controller for the DS18X20 API
5+
*
6+
* Adafruit invests time and resources providing this open source code,
7+
* please support Adafruit and open-source hardware by purchasing
8+
* products from Adafruit!
9+
*
10+
* Copyright (c) Brent Rubell 2024 for Adafruit Industries.
11+
*
12+
* BSD license, all text here must be included in any redistribution.
13+
*
14+
*/
15+
#ifndef WS_DS18X20_CONTROLLER_H
16+
#define WS_DS18X20_CONTROLLER_H
17+
#include "Wippersnapper_V2.h"
18+
#include "hardware.h"
19+
#include "model.h"
20+
21+
class Wippersnapper_V2; ///< Forward declaration
22+
class DS18X20Model; ///< Forward declaration
23+
class DS18X20Hardware; ///< Forward declaration
24+
25+
/**************************************************************************/
26+
/*!
27+
@brief Routes messages between the ds18x20.proto API and the hardware.
28+
*/
29+
/**************************************************************************/
30+
class DS18X20Controller {
31+
public:
32+
DS18X20Controller();
33+
~DS18X20Controller();
34+
// Routing
35+
bool Handle_Ds18x20Add(pb_istream_t *stream);
36+
37+
private:
38+
DS18X20Model *_DS18X20_model; ///< ds18x20 model
39+
DS18X20Hardware *_DS18X20_hardware; ///< ds18x20 hardware
40+
};
41+
extern Wippersnapper_V2 WsV2; ///< Wippersnapper V2 instance
42+
#endif // WS_DS18X20_CONTROLLER_H
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*!
2+
* @file hardware.cpp
3+
*
4+
* Hardware interface for the ds18x20.proto API
5+
*
6+
* Adafruit invests time and resources providing this open source code,
7+
* please support Adafruit and open-source hardware by purchasing
8+
* products from Adafruit!
9+
*
10+
* Copyright (c) Brent Rubell 2024 for Adafruit Industries.
11+
*
12+
* BSD license, all text here must be included in any redistribution.
13+
*
14+
*/
15+
#include "hardware.h"
16+
17+
DS18X20Hardware::DS18X20Hardware() {
18+
// TODO: Implement this
19+
}
20+
21+
DS18X20Hardware::~DS18X20Hardware() {
22+
// TODO: Implement this
23+
}

src/components/ds18x20/hardware.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*!
2+
* @file model.h
3+
*
4+
* Hardware implementation for the ds18x20.proto message.
5+
*
6+
* Adafruit invests time and resources providing this open source code,
7+
* please support Adafruit and open-source hardware by purchasing
8+
* products from Adafruit!
9+
*
10+
* Copyright (c) Brent Rubell 2024 for Adafruit Industries.
11+
*
12+
* BSD license, all text here must be included in any redistribution.
13+
*
14+
*/
15+
#ifndef WS_DS18X20_HARDWARE_H
16+
#define WS_DS18X20_HARDWARE_H
17+
#include "Wippersnapper_V2.h"
18+
#include <DallasTemperature.h>
19+
20+
struct DS18X20_Pin {
21+
// Specific to the DS18X20 sensor object
22+
OneWire
23+
*oneWire; ///< Ptr reference to the OneWire bus object used by this pin
24+
DallasTemperature
25+
*dallasTempObj; ///< Pointer to a DallasTemperature sensor object
26+
DeviceAddress dallasTempAddr; ///< Temperature sensor's address
27+
// From the PB model
28+
char onewire_pin[5]; ///< Pin utilized by the OneWire bus, used for addressing
29+
float period; ///< The desired period to read the sensor, in seconds
30+
float prv_period; ///< Last time the sensor was polled, in seconds
31+
pb_size_t
32+
sensor_types_count; ///< Number of sensor types to read from the sensor
33+
wippersnapper_sensor_SensorType
34+
sensor_types[2]; ///< DS sensor type(s) to read from the sensor
35+
}; ///< DS18X20 Pin Object
36+
37+
/**************************************************************************/
38+
/*!
39+
@brief Interface for interacting with the's DallasTemp
40+
and OneWire APIs.
41+
*/
42+
/**************************************************************************/
43+
class DS18X20Hardware {
44+
public:
45+
DS18X20Hardware();
46+
~DS18X20Hardware();
47+
48+
private:
49+
std::vector<DS18X20_Pin> _DS18X20_Pins; ///< Vector of analogio pins
50+
};
51+
#endif // WS_DS18X20_HARDWARE_H

src/components/ds18x20/model.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*!
2+
* @file model.cpp
3+
*
4+
* Model for the ds18x20.proto message.
5+
*
6+
* Adafruit invests time and resources providing this open source code,
7+
* please support Adafruit and open-source hardware by purchasing
8+
* products from Adafruit!
9+
*
10+
* Copyright (c) Brent Rubell 2024 for Adafruit Industries.
11+
*
12+
* BSD license, all text here must be included in any redistribution.
13+
*
14+
*/
15+
#include "model.h"
16+
17+
DS18X20Model::DS18X20Model() {
18+
// Initialize the DS18X20 messages
19+
_msg_DS18x20Add = wippersnapper_ds18x20_Ds18x20Add_init_zero;
20+
}
21+
22+
DS18X20Model::~DS18X20Model() {}

src/components/ds18x20/model.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*!
2+
* @file model.h
3+
*
4+
* Model interface for the DS18X20.proto message.
5+
*
6+
* Adafruit invests time and resources providing this open source code,
7+
* please support Adafruit and open-source hardware by purchasing
8+
* products from Adafruit!
9+
*
10+
* Copyright (c) Brent Rubell 2024 for Adafruit Industries.
11+
*
12+
* BSD license, all text here must be included in any redistribution.
13+
*
14+
*/
15+
#ifndef WS_DS18X20_MODEL_H
16+
#define WS_DS18X20_MODEL_H
17+
#include "Wippersnapper_V2.h"
18+
19+
/**************************************************************************/
20+
/*!
21+
@brief Provides an interface for creating, encoding, and parsing
22+
messages from DS18X20.proto.
23+
*/
24+
/**************************************************************************/
25+
class DS18X20Model {
26+
public:
27+
DS18X20Model();
28+
~DS18X20Model();
29+
// Ds18x20Add Message
30+
bool DecodeDS18x20Add(pb_istream_t *stream);
31+
wippersnapper_ds18x20_Ds18x20Add *GetDS18x20AddMsg();
32+
33+
private:
34+
wippersnapper_ds18x20_Ds18x20Add
35+
_msg_DS18x20Add; ///< wippersnapper_ds18x20_Ds18x20Add message
36+
};
37+
#endif // WS_DIGITALIO_MODEL_H

0 commit comments

Comments
 (0)