Skip to content

Commit 70406f3

Browse files
committed
🚧 WIP, digitalio - Add doxygen comments
1 parent 0675abc commit 70406f3

File tree

4 files changed

+184
-41
lines changed

4 files changed

+184
-41
lines changed

src/Wippersnapper_demo.ino.cpp

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/components/digitalIO/controller.cpp

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

17+
/***********************************************************************/
18+
/*!
19+
@brief DigitalIOController constructor
20+
*/
21+
/***********************************************************************/
1722
DigitalIOController::DigitalIOController() {
1823
_dio_model = new DigitalIOModel();
1924
_dio_hardware = new DigitalIOHardware();
@@ -22,11 +27,23 @@ DigitalIOController::DigitalIOController() {
2227
SetMaxDigitalPins(0);
2328
}
2429

30+
/***********************************************************************/
31+
/*!
32+
@brief DigitalIOController destructor
33+
*/
34+
/***********************************************************************/
2535
DigitalIOController::~DigitalIOController() {
2636
delete _dio_model;
2737
delete _dio_hardware;
2838
}
2939

40+
/***********************************************************************/
41+
/*!
42+
@brief Set the maximum number of digital pins
43+
@param max_digital_pins
44+
The maximum number of digital pins
45+
*/
46+
/***********************************************************************/
3047
void DigitalIOController::SetMaxDigitalPins(uint8_t max_digital_pins) {
3148
_max_digital_pins = max_digital_pins;
3249
}
@@ -39,6 +56,21 @@ bool DigitalIOController::IsStatusLEDPin(uint8_t pin_name) {
3956
return false;
4057
}
4158

59+
/***********************************************************************/
60+
/*!
61+
@brief Create a new digital pin and add it to the controller's vector
62+
@param name
63+
The pin's name.
64+
@param direction
65+
The pin's direction.
66+
@param sample_mode
67+
The pin's sample mode.
68+
@param value
69+
The pin's value.
70+
@param period
71+
The pin's period.
72+
*/
73+
/***********************************************************************/
4274
void DigitalIOController::CreateDigitalIOPin(
4375
uint8_t name, wippersnapper_digitalio_DigitalIODirection direction,
4476
wippersnapper_digitalio_DigitalIOSampleMode sample_mode, bool value,
@@ -54,6 +86,14 @@ void DigitalIOController::CreateDigitalIOPin(
5486
_digital_io_pins.push_back(new_pin);
5587
}
5688

89+
/***********************************************************************/
90+
/*!
91+
@brief Add a new digital pin to the controller
92+
@param stream
93+
The nanopb input stream.
94+
@return True if the digital pin was successfully added.
95+
*/
96+
/***********************************************************************/
5797
bool DigitalIOController::AddDigitalIOPin(pb_istream_t *stream) {
5898
// Early-out if we have reached the maximum number of digital pins
5999
if (_digital_io_pins.size() >= _max_digital_pins) {
@@ -96,6 +136,14 @@ bool DigitalIOController::AddDigitalIOPin(pb_istream_t *stream) {
96136
return true;
97137
}
98138

139+
/***********************************************************************/
140+
/*!
141+
@brief Get the index of a digital output pin
142+
@param pin_name
143+
The pin's name.
144+
@return The index of the digital output pin.
145+
*/
146+
/***********************************************************************/
99147
int DigitalIOController::GetDigitalOutputPinsIdx(uint8_t pin_name) {
100148
for (int i = 0; i < _digital_io_pins.size(); i++) {
101149
if (_digital_io_pins[i].pin_name == pin_name) {
@@ -105,6 +153,14 @@ int DigitalIOController::GetDigitalOutputPinsIdx(uint8_t pin_name) {
105153
return -1; // Pin not found
106154
}
107155

156+
/***********************************************************************/
157+
/*!
158+
@brief Write a digital pin
159+
@param stream
160+
The nanopb input stream.
161+
@return True if the digital pin was successfully written.
162+
*/
163+
/***********************************************************************/
108164
bool DigitalIOController::WriteDigitalIOPin(pb_istream_t *stream) {
109165
// Attempt to decode the DigitalIOWrite message
110166
if (!_dio_model->DecodeDigitalIOWrite(stream)) {
@@ -151,10 +207,28 @@ bool DigitalIOController::WriteDigitalIOPin(pb_istream_t *stream) {
151207
return true;
152208
}
153209

210+
/***********************************************************************/
211+
/*!
212+
@brief Check if a pin's timer has expired
213+
@param pin
214+
The pin to check.
215+
@param cur_time
216+
The current time.
217+
@return True if the pin's timer has expired.
218+
*/
219+
/***********************************************************************/
154220
bool DigitalIOController::IsPinTimerExpired(DigitalIOPin *pin, ulong cur_time) {
155221
return cur_time - pin->prv_pin_time > pin->pin_period;
156222
}
157223

224+
/***********************************************************************/
225+
/*!
226+
@brief Check if a pin's timer has expired
227+
@param pin
228+
The pin to check.
229+
@return True if the pin's timer has expired.
230+
*/
231+
/***********************************************************************/
158232
bool DigitalIOController::CheckTimerPin(DigitalIOPin *pin) {
159233
ulong cur_time = millis();
160234

@@ -172,6 +246,14 @@ bool DigitalIOController::CheckTimerPin(DigitalIOPin *pin) {
172246
return true;
173247
}
174248

249+
/***********************************************************************/
250+
/*!
251+
@brief Check if a pin's value has changed
252+
@param pin
253+
The pin to check.
254+
@return True if the pin's value has changed.
255+
*/
256+
/***********************************************************************/
175257
bool DigitalIOController::CheckEventPin(DigitalIOPin *pin) {
176258
// Get the pin's current value
177259
pin->pin_value = _dio_hardware->GetValue(pin->pin_name);
@@ -190,6 +272,16 @@ bool DigitalIOController::CheckEventPin(DigitalIOPin *pin) {
190272
return true;
191273
}
192274

275+
/***********************************************************************/
276+
/*!
277+
@brief Encode and publish a pin event
278+
@param pin_name
279+
The pin's name.
280+
@param pin_value
281+
The pin's value.
282+
@return True if the pin event was successfully encoded and published.
283+
*/
284+
/***********************************************************************/
193285
bool DigitalIOController::EncodePublishPinEvent(uint8_t pin_name,
194286
bool pin_value) {
195287
// Prefix pin_name with "D" to match the expected pin name format
@@ -215,6 +307,11 @@ bool DigitalIOController::EncodePublishPinEvent(uint8_t pin_name,
215307
return true;
216308
}
217309

310+
/***********************************************************************/
311+
/*!
312+
@brief Updates the digital_io_pins array.
313+
*/
314+
/***********************************************************************/
218315
void DigitalIOController::Update() {
219316
// Bail out if we have no digital pins to poll
220317
if (_digital_io_pins.empty())

src/components/digitalIO/hardware.cpp

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,43 @@
1+
/*!
2+
* @file hardware.cpp
3+
*
4+
* Hardware driver for the digitalio.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+
*/
115
#include "hardware.h"
216

17+
/***********************************************************************/
18+
/*!
19+
@brief DigitalIOHardware constructor
20+
*/
21+
/***********************************************************************/
322
DigitalIOHardware::DigitalIOHardware() {}
4-
DigitalIOHardware::~DigitalIOHardware() {}
523

6-
void DigitalIOHardware::deinit(uint8_t pin_name) {
7-
// Turn off pin output and reset mode to hi-z floating state
8-
digitalWrite(pin_name, LOW);
9-
pinMode(pin_name, INPUT);
10-
// TODO: Release status led, if it's a LED, back to the application
11-
}
24+
/***********************************************************************/
25+
/*!
26+
@brief DigitalIOHardware destructor
27+
*/
28+
/***********************************************************************/
29+
DigitalIOHardware::~DigitalIOHardware() {}
1230

31+
/***********************************************************************/
32+
/*!
33+
@brief Configures a digital pin.
34+
@param name
35+
The pin's name.
36+
@param direction
37+
The pin's direction.
38+
@return True if the pin was successfully configured. False otherwise.
39+
*/
40+
/***********************************************************************/
1341
bool DigitalIOHardware::ConfigurePin(
1442
uint8_t name, wippersnapper_digitalio_DigitalIODirection direction) {
1543
// Configure an output pin
@@ -40,10 +68,41 @@ bool DigitalIOHardware::ConfigurePin(
4068
return true;
4169
}
4270

71+
/***********************************************************************/
72+
/*!
73+
@brief Deinitializes a digital pin.
74+
@param pin_name
75+
The digital pin to deinitialize.
76+
*/
77+
/***********************************************************************/
78+
void DigitalIOHardware::deinit(uint8_t pin_name) {
79+
// Turn off pin output and reset mode to hi-z floating state
80+
digitalWrite(pin_name, LOW);
81+
pinMode(pin_name, INPUT);
82+
// TODO: Release status led, if it's a LED, back to the application
83+
}
84+
85+
/***********************************************************************/
86+
/*!
87+
@brief Sets a digital pin's value.
88+
@param pin_name
89+
The pin's name.
90+
@param pin_value
91+
The pin's value.
92+
*/
93+
/***********************************************************************/
4394
void DigitalIOHardware::SetValue(uint8_t pin_name, bool pin_value) {
4495
digitalWrite(pin_name, pin_value ? HIGH : LOW);
4596
}
4697

98+
/***********************************************************************/
99+
/*!
100+
@brief Gets a digital pin's value.
101+
@param pin_name
102+
The pin's name.
103+
@return The pin's value.
104+
*/
105+
/***********************************************************************/
47106
bool DigitalIOHardware::GetValue(uint8_t pin_name) {
48107
return digitalRead(pin_name);
49108
}

src/components/digitalIO/model.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ bool DigitalIOModel::DecodeDigitalIOAdd(pb_istream_t *stream) {
5252
&_msg_dio_add);
5353
}
5454

55+
/***********************************************************************/
56+
/*!
57+
@brief Decodes a DigitalIOWrite message into the _msg_dio_write
58+
object from a nanopb stream.
59+
@param stream
60+
The nanopb input stream.
61+
@return True if the DigitalIOWrite message was successfully decoded.
62+
*/
63+
/***********************************************************************/
5564
bool DigitalIOModel::DecodeDigitalIOWrite(pb_istream_t *stream) {
5665
// Zero-out the DigitalIOWrite message struct. to ensure we don't have any old
5766
// data
@@ -61,6 +70,18 @@ bool DigitalIOModel::DecodeDigitalIOWrite(pb_istream_t *stream) {
6170
&_msg_dio_write);
6271
}
6372

73+
/***********************************************************************/
74+
/*!
75+
@brief Encodes a DigitalIOEvent message into the
76+
_msg_dio_event object.
77+
@param pin_name
78+
The pin's name.
79+
@param value
80+
The pin's value.
81+
@return True if the DigitalIOEvent message was successfully encoded.
82+
False if encoding resulted in a failure.
83+
*/
84+
/***********************************************************************/
6485
bool DigitalIOModel::EncodeDigitalIOEvent(char *pin_name, bool value) {
6586
// Initialize the DigitalIOEvent
6687
_msg_dio_event = wippersnapper_digitalio_DigitalIOEvent_init_default;

0 commit comments

Comments
 (0)