Skip to content

Commit e513533

Browse files
committed
🚧 WIP, digitalio - Address TODO for statusled
1 parent 624ba3d commit e513533

File tree

5 files changed

+30
-16
lines changed

5 files changed

+30
-16
lines changed

platformio.ini

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,9 @@ board_build.filesystem = littlefs
151151
extends = common:esp32
152152
board = featheresp32-s2
153153
build_flags = -DARDUINO_ADAFRUIT_FEATHER_ESP32S2 -DBOARD_HAS_PSRAM
154-
board_build.partitions = tinyuf2-partitions-4MB-noota.csv
155-
build_type = debug
154+
;board_build.partitions = tinyuf2-partitions-4MB-noota.csv
155+
board_build.partitions = tinyuf2-partitions-4MB.csv
156+
;build_type = debug
156157
monitor_filters = esp32_exception_decoder
157158
extra_scripts = pre:rename_usb_config.py
158159

src/components/digitalIO/controller.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,6 @@ void DigitalIOController::SetMaxDigitalPins(uint8_t max_digital_pins) {
4848
_max_digital_pins = max_digital_pins;
4949
}
5050

51-
// TODO: This should be within the hardware class
52-
bool DigitalIOController::IsStatusLEDPin(uint8_t pin_name) {
53-
#ifdef STATUS_LED_PIN
54-
return pin_name == STATUS_LED_PIN;
55-
#endif
56-
return false;
57-
}
58-
5951
/***********************************************************************/
6052
/*!
6153
@brief Create a new digital pin and add it to the controller's vector
@@ -112,7 +104,7 @@ bool DigitalIOController::AddDigitalIOPin(pb_istream_t *stream) {
112104
int pin_name = atoi(_dio_model->GetDigitalIOAddMsg()->pin_name + 1);
113105

114106
// Check if the provided pin is also the status LED pin
115-
if (IsStatusLEDPin(pin_name))
107+
if (_dio_hardware->IsStatusLEDPin(pin_name))
116108
releaseStatusLED();
117109

118110
// Deinit the pin if it's already in use
@@ -169,8 +161,8 @@ bool DigitalIOController::WriteDigitalIOPin(pb_istream_t *stream) {
169161
}
170162

171163
// Get the digital pin
172-
int pin_idx = GetPinIdx(
173-
atoi(_dio_model->GetDigitalIOWriteMsg()->pin_name + 1));
164+
int pin_idx =
165+
GetPinIdx(atoi(_dio_model->GetDigitalIOWriteMsg()->pin_name + 1));
174166
// Check if the pin was found and is a valid digital output pin
175167
if (pin_idx == -1) {
176168
WS_DEBUG_PRINTLN("ERROR: Unable to find the requested digital output pin!");

src/components/digitalIO/controller.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,19 @@ class DigitalIOController {
4343
void Update();
4444
bool EncodePublishPinEvent(uint8_t pin_name, bool pin_value);
4545

46-
void CreateDigitalIOPin(uint8_t name,
46+
void
47+
CreateDigitalIOPin(uint8_t name,
4748
wippersnapper_digitalio_DigitalIODirection direction,
4849
wippersnapper_digitalio_DigitalIOSampleMode sample_mode,
4950
bool value, long period);
5051
bool CheckEventPin(DigitalIOPin *pin);
5152
bool CheckTimerPin(DigitalIOPin *pin);
5253
bool IsPinTimerExpired(DigitalIOPin *pin, ulong cur_time);
53-
bool IsStatusLEDPin(uint8_t pin_name);
5454

5555
void PrintPinValue(DigitalIOPin *pin);
5656
void SetMaxDigitalPins(uint8_t max_digital_pins);
5757
int GetPinIdx(uint8_t pin_name);
58+
5859
private:
5960
std::vector<DigitalIOPin> _digital_io_pins;
6061
uint8_t _max_digital_pins;

src/components/digitalIO/hardware.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ void DigitalIOHardware::deinit(uint8_t pin_name) {
7979
// Turn off pin output and reset mode to hi-z floating state
8080
digitalWrite(pin_name, LOW);
8181
pinMode(pin_name, INPUT);
82-
// TODO: Release status led, if it's a LED, back to the application
82+
// Prior to using this pin as a DIO,
83+
// was this a status LED pin?
84+
if (IsStatusLEDPin(pin_name)) {
85+
initStatusLED(); // it was! re-init status led
86+
}
8387
}
8488

8589
/***********************************************************************/
@@ -105,4 +109,19 @@ void DigitalIOHardware::SetValue(uint8_t pin_name, bool pin_value) {
105109
/***********************************************************************/
106110
bool DigitalIOHardware::GetValue(uint8_t pin_name) {
107111
return digitalRead(pin_name);
112+
}
113+
114+
/***********************************************************************/
115+
/*!
116+
@brief Checks if a pin is the status LED pin.
117+
@param pin_name
118+
The pin's name.
119+
@return True if the pin is the status LED pin.
120+
*/
121+
/***********************************************************************/
122+
bool DigitalIOHardware::IsStatusLEDPin(uint8_t pin_name) {
123+
#ifdef STATUS_LED_PIN
124+
return pin_name == STATUS_LED_PIN;
125+
#endif
126+
return false;
108127
}

src/components/digitalIO/hardware.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class DigitalIOHardware {
2525
void SetValue(uint8_t pin_name, bool pin_value);
2626
bool GetValue(uint8_t pin_name);
2727
void deinit(uint8_t pin_name);
28+
bool IsStatusLEDPin(uint8_t pin_name);
2829

2930
private:
3031
};

0 commit comments

Comments
 (0)