Skip to content

Commit 60238ca

Browse files
committed
🎨 WIP, dsx - Doxygen and remove unused code implemented in the sensor model
1 parent c66c97e commit 60238ca

File tree

7 files changed

+210
-38
lines changed

7 files changed

+210
-38
lines changed

‎src/components/digitalIO/model.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ wippersnapper_digitalio_DigitalIOAdd *DigitalIOModel::GetDigitalIOAddMsg() {
4646
/***********************************************************************/
4747
/*!
4848
@brief Parses a DigitalIORemove message.
49+
@param stream
50+
The nanopb input stream.
4951
@return DigitalIORemove message object.
5052
*/
5153
/***********************************************************************/

‎src/components/ds18x20/controller.cpp‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,34 @@
1414
*/
1515
#include "controller.h"
1616

17+
/***********************************************************************/
18+
/*!
19+
@brief DS18X20Controller constructor
20+
*/
21+
/***********************************************************************/
1722
DS18X20Controller::DS18X20Controller() { _DS18X20_model = new DS18X20Model(); }
1823

24+
/***********************************************************************/
25+
/*!
26+
@brief DS18X20Controller destructor
27+
*/
28+
/***********************************************************************/
1929
DS18X20Controller::~DS18X20Controller() { delete _DS18X20_model; }
2030

31+
/***********************************************************************/
32+
/*!
33+
@brief Handles a Ds18x20Add message from the broker. Attempts to
34+
initialize a OneWire bus on the requested pin, attempts to
35+
initialize a DSTherm driver on the OneWire bus, adds the
36+
OneWire bus to the controller, and publishes a Ds18x20Added
37+
message to the broker indicating the result of this function.
38+
@param stream
39+
The nanopb input stream.
40+
@return True if the sensor was successfully initialized,
41+
added to the controller, and a response was succesfully
42+
published to the broker. False otherwise.
43+
*/
44+
/***********************************************************************/
2145
bool DS18X20Controller::Handle_Ds18x20Add(pb_istream_t *stream) {
2246
// Attempt to decode the incoming message into a Ds18x20Add message
2347
if (!_DS18X20_model->DecodeDS18x20Add(stream)) {
@@ -81,6 +105,17 @@ bool DS18X20Controller::Handle_Ds18x20Add(pb_istream_t *stream) {
81105
return true;
82106
}
83107

108+
/***********************************************************************/
109+
/*!
110+
@brief Handles a Ds18x20Remove message from the broker. Attempts to
111+
remove a DS18X20Hardware object from the controller and
112+
release the OneWire pin for other uses.
113+
@param stream
114+
The nanopb input stream.
115+
@return True if the sensor was successfully removed from the
116+
controller, False otherwise.
117+
*/
118+
/***********************************************************************/
84119
bool DS18X20Controller::Handle_Ds18x20Remove(pb_istream_t *stream) {
85120
// Attempt to decode the stream
86121
if (!_DS18X20_model->DecodeDS18x20Remove(stream)) {
@@ -104,6 +139,11 @@ bool DS18X20Controller::Handle_Ds18x20Remove(pb_istream_t *stream) {
104139
return true;
105140
}
106141

142+
/***********************************************************************/
143+
/*!
144+
@brief Update/polling loop for the DS18X20 controller.
145+
*/
146+
/***********************************************************************/
107147
void DS18X20Controller::update() {
108148
// Bail out if there are no OneWire pins to poll
109149
if (_DS18X20_pins.empty())

‎src/components/ds18x20/hardware.cpp‎

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
*/
1515
#include "hardware.h"
1616

17+
/***********************************************************************/
18+
/*!
19+
@brief DS18X20Hardware constructor
20+
@param onewire_pin
21+
The OneWire bus pin to use.
22+
*/
23+
/***********************************************************************/
1724
DS18X20Hardware::DS18X20Hardware(uint8_t onewire_pin) : _drv_therm(_ow) {
1825
is_read_temp_c = false;
1926
is_read_temp_f = false;
@@ -22,19 +29,44 @@ DS18X20Hardware::DS18X20Hardware(uint8_t onewire_pin) : _drv_therm(_ow) {
2229
new (&_ow) OneWireNg_CurrentPlatform(onewire_pin, false);
2330
}
2431

32+
/***********************************************************************/
33+
/*!
34+
@brief DS18X20Hardware destructor
35+
*/
36+
/***********************************************************************/
2537
DS18X20Hardware::~DS18X20Hardware() {
2638
pinMode(_onewire_pin,
2739
INPUT); // Set the pin to hi-z and release it for other uses
2840
delete &_ow;
2941
}
3042

43+
/***********************************************************************/
44+
/*!
45+
@brief Get the sensor's ID
46+
@returns True if the sensor was successfully identified, False otherwise.
47+
*/
48+
/***********************************************************************/
3149
bool DS18X20Hardware::GetSensor() {
3250
OneWireNg::ErrorCode ec = _ow->readSingleId(_sensorId);
3351
return ec == OneWireNg::EC_SUCCESS;
3452
}
3553

54+
/***********************************************************************/
55+
/*!
56+
@brief Gets the pin used as a OneWire bus.
57+
@returns The OneWire bus pin.
58+
*/
59+
/***********************************************************************/
3660
uint8_t DS18X20Hardware::GetOneWirePin() { return _onewire_pin; }
3761

62+
/*************************************************************************/
63+
/*!
64+
@brief Sets the DS18X20 sensor's resolution.
65+
@param resolution
66+
The desired resolution of the DS18X20 sensor, in bits (from
67+
9 to 12).
68+
*/
69+
/*************************************************************************/
3870
void DS18X20Hardware::SetResolution(int resolution) {
3971
// Set the resolution of the DS18X20 sensor driver
4072
switch (resolution) {
@@ -66,20 +98,51 @@ void DS18X20Hardware::SetResolution(int resolution) {
6698
_drv_therm.copyScratchpadAll(false);
6799
}
68100

101+
/*************************************************************************/
102+
/*!
103+
@brief Sets the timer to read from the sensor.
104+
@param period
105+
The desired period to read the sensor, in seconds.
106+
*/
107+
/*************************************************************************/
69108
void DS18X20Hardware::SetPeriod(float period) {
70109
_period = period * 1000; // Convert to milliseconds
71110
}
72111

73-
// Get the current time in milliseconds and compare it to the last time
74-
// the sensor was polled
112+
/*************************************************************************/
113+
/*!
114+
@brief Obtains the current time in milliseconds and compares it to
115+
the last time the sensor was polled.
116+
@returns True if the timer has expired, False otherwise.
117+
*/
118+
/*************************************************************************/
75119
bool DS18X20Hardware::IsTimerExpired() {
76120
return millis() - _prv_period > _period;
77121
}
78122

123+
/*************************************************************************/
124+
/*!
125+
@brief Gets the temperature value last read by the sensor, in Celsius.
126+
@returns The temperature in Celsius.
127+
*/
128+
/*************************************************************************/
79129
float DS18X20Hardware::GetTemperatureC() { return _temp_c; }
80130

131+
/*************************************************************************/
132+
/*!
133+
@brief Gets the temperature value last read by the sensor, in Fahrenheit.
134+
@returns The temperature in Fahrenheit.
135+
*/
136+
/*************************************************************************/
81137
float DS18X20Hardware::GetTemperatureF() { return _temp_f; }
82138

139+
/*************************************************************************/
140+
/*!
141+
@brief Attempts to obtain the temperature from the sensor, in
142+
degrees Fahrenheit.
143+
@returns True if the temperature was successfully read, False otherwise.
144+
*/
145+
/*************************************************************************/
83146
bool DS18X20Hardware::ReadTemperatureF() {
84147
bool is_success = ReadTemperatureC();
85148
// Did we read the temperature successfully?
@@ -93,6 +156,13 @@ bool DS18X20Hardware::ReadTemperatureF() {
93156
return true;
94157
}
95158

159+
/*************************************************************************/
160+
/*!
161+
@brief Attempts to obtain the temperature from the sensor, in
162+
degrees Celsius.
163+
@returns True if the temperature was successfully read, False otherwise.
164+
*/
165+
/*************************************************************************/
96166
bool DS18X20Hardware::ReadTemperatureC() {
97167
// Start temperature conversion for the first identified sensor on the OneWire
98168
// bus

‎src/components/ds18x20/hardware.h‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ class DS18X20Hardware {
3939
bool ReadTemperatureF();
4040
float GetTemperatureC();
4141
float GetTemperatureF();
42-
bool is_read_temp_c;
43-
bool is_read_temp_f;
44-
42+
bool is_read_temp_c; ///< Flag telling the controller to read the temperature
43+
///< in degrees Celsius
44+
bool is_read_temp_f; ///< Flag telling the controller to read the temperature
45+
///< in degrees Fahrenheit
4546
private:
4647
Placeholder<OneWireNg_CurrentPlatform> _ow; ///< OneWire bus object
47-
OneWireNg::Id _sensorId;
48-
DSTherm _drv_therm; ///< DS18X20 driver object
48+
OneWireNg::Id _sensorId; ///< Sensor ID
49+
DSTherm _drv_therm; ///< DS18X20 driver object
4950
DSTherm::Resolution _resolution; ///< Resolution of the DS18X20 sensor
5051
float _temp_c; ///< Temperature in Celsius
5152
float _temp_f; ///< Temperature in Fahrenheit

‎src/components/ds18x20/model.cpp‎

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,72 @@
1414
*/
1515
#include "model.h"
1616

17+
/***********************************************************************/
18+
/*!
19+
@brief DS18X20Model constructor
20+
*/
21+
/***********************************************************************/
1722
DS18X20Model::DS18X20Model() {
1823
// Initialize the DS18X20 messages
1924
_msg_DS18x20Add = wippersnapper_ds18x20_Ds18x20Add_init_zero;
25+
_msg_DS18x20Added = wippersnapper_ds18x20_Ds18x20Added_init_zero;
26+
_msg_DS18x20Remove = wippersnapper_ds18x20_Ds18x20Remove_init_zero;
2027
}
2128

29+
/***********************************************************************/
30+
/*!
31+
@brief DS18X20Model destructor
32+
*/
33+
/***********************************************************************/
2234
DS18X20Model::~DS18X20Model() {}
2335

36+
/***********************************************************************/
37+
/*!
38+
@brief Attempts to decode a Ds18x20Add message from the broker.
39+
@param stream
40+
The nanopb input stream.
41+
@return True if the message was successfully decoded, False otherwise.
42+
*/
43+
/***********************************************************************/
2444
bool DS18X20Model::DecodeDS18x20Add(pb_istream_t *stream) {
2545
_msg_DS18x20Add = wippersnapper_ds18x20_Ds18x20Add_init_zero;
2646
// Attempt to decode the stream into a Ds18x20Add message
2747
return pb_decode(stream, wippersnapper_ds18x20_Ds18x20Add_fields,
2848
&_msg_DS18x20Add);
2949
}
3050

51+
/***********************************************************************/
52+
/*!
53+
@brief Gets a pointer to the Ds18x20Add message.
54+
@return Pointer to the Ds18x20Add message.
55+
*/
56+
/***********************************************************************/
3157
wippersnapper_ds18x20_Ds18x20Add *DS18X20Model::GetDS18x20AddMsg() {
3258
return &_msg_DS18x20Add;
3359
}
3460

61+
/***********************************************************************/
62+
/*!
63+
@brief Returns a pointer to the Ds18x20Added message.
64+
@return Pointer to the Ds18x20Added message.
65+
*/
66+
/***********************************************************************/
3567
wippersnapper_ds18x20_Ds18x20Added *DS18X20Model::GetDS18x20AddedMsg() {
3668
return &_msg_DS18x20Added;
3769
}
3870

71+
/***********************************************************************/
72+
/*!
73+
@brief Encodes a Ds18x20Added message.
74+
@param onewire_pin
75+
The OneWire bus pin to add.
76+
@param is_init
77+
True if the sensor was successfully initialized,
78+
False otherwise.
79+
@return True if the message was successfully encoded,
80+
False otherwise.
81+
*/
82+
/***********************************************************************/
3983
bool DS18X20Model::EncodeDS18x20Added(char *onewire_pin, bool is_init) {
4084
// Fill the Ds18x20Added message
4185
_msg_DS18x20Added = wippersnapper_ds18x20_Ds18x20Added_init_zero;
@@ -54,20 +98,52 @@ bool DS18X20Model::EncodeDS18x20Added(char *onewire_pin, bool is_init) {
5498
&_msg_DS18x20Added);
5599
}
56100

101+
/*************************************************************************/
102+
/*!
103+
@brief Attempts to decode a Ds18x20Remove message from the broker.
104+
@param stream
105+
The nanopb input stream.
106+
@return True if the message was successfully decoded, False otherwise.
107+
*/
108+
/*************************************************************************/
57109
bool DS18X20Model::DecodeDS18x20Remove(pb_istream_t *stream) {
58110
_msg_DS18x20Remove = wippersnapper_ds18x20_Ds18x20Remove_init_zero;
59111
return pb_decode(stream, wippersnapper_ds18x20_Ds18x20Remove_fields,
60112
&_msg_DS18x20Remove);
61113
}
62114

115+
/*************************************************************************/
116+
/*!
117+
@brief Gets a pointer to the Ds18x20Remove message.
118+
@return Pointer to the Ds18x20Remove message.
119+
*/
120+
/*************************************************************************/
63121
wippersnapper_ds18x20_Ds18x20Remove *DS18X20Model::GetDS18x20RemoveMsg() {
64122
return &_msg_DS18x20Remove;
65123
}
66124

125+
/*************************************************************************/
126+
/*!
127+
@brief Gets a pointer to the Ds18x20Event message.
128+
@return Pointer to the Ds18x20Event message.
129+
*/
130+
/*************************************************************************/
67131
wippersnapper_ds18x20_Ds18x20Event *DS18X20Model::GetDS18x20EventMsg() {
68132
return &_msg_DS18x20Event;
69133
}
70134

135+
/*************************************************************************/
136+
/*!
137+
@brief Encodes a Ds18x20Event message.
138+
@param onewire_pin
139+
The OneWire bus' pin where the sensor is located.
140+
@param sensor_events_count
141+
The number of sensorevent messages to encode.
142+
@param sensor_events
143+
The sensorevent messages to encode.
144+
@return True if the message was successfully encoded, False otherwise.
145+
*/
146+
/*************************************************************************/
71147
bool DS18X20Model::EncodeDs18x20Event(
72148
char *onewire_pin, pb_size_t sensor_events_count,
73149
const wippersnapper_sensor_SensorEvent sensor_events[2]) {
@@ -90,11 +166,25 @@ bool DS18X20Model::EncodeDs18x20Event(
90166
&_msg_DS18x20Event);
91167
}
92168

169+
/*************************************************************************/
170+
/*!
171+
@brief Initializes the Ds18x20Event message.
172+
*/
173+
/*************************************************************************/
93174
void DS18X20Model::InitDS18x20EventMsg() {
94175
_msg_DS18x20Event = wippersnapper_ds18x20_Ds18x20Event_init_zero;
95176
_msg_DS18x20Event.sensor_events_count = 0;
96177
}
97178

179+
/*************************************************************************/
180+
/*!
181+
@brief Adds a "sensor event" to the Ds18x20Event message.
182+
@param sensor_type
183+
The event's SensorType.
184+
@param sensor_value
185+
The event's value.
186+
*/
187+
/*************************************************************************/
98188
void DS18X20Model::addSensorEvent(wippersnapper_sensor_SensorType sensor_type,
99189
float sensor_value) {
100190
_msg_DS18x20Event.sensor_events[_msg_DS18x20Event.sensor_events_count].type =

0 commit comments

Comments
 (0)