File tree Expand file tree Collapse file tree 2 files changed +24
-12
lines changed
src/components/uart/drivers Expand file tree Collapse file tree 2 files changed +24
-12
lines changed Original file line number Diff line number Diff line change @@ -76,15 +76,25 @@ class drvUartPm25 : public drvUartBase {
76
76
@returns True if initialized successfully, False otherwise.
77
77
*/
78
78
bool begin () override {
79
+ #if HAS_SW_SERIAL
80
+ if (_sw_serial == nullptr )
81
+ return false ;
82
+ #else
79
83
if (_hw_serial == nullptr )
80
84
return false ;
85
+ #endif // HAS_SW_SERIAL
81
86
82
87
_pm25 = new Adafruit_PM25AQI ();
83
88
if (_pm25 == nullptr )
84
89
return false ;
85
90
86
91
delay (1000 ); // Wait for the sensor to boot
92
+
93
+ #ifdef HAS_SW_SERIAL
94
+ return _pm25->begin_UART (_sw_serial);
95
+ #else
87
96
return _pm25->begin_UART (_hw_serial);
97
+ #endif // HAS_SW_SERIAL
88
98
}
89
99
90
100
/* !
Original file line number Diff line number Diff line change @@ -114,28 +114,30 @@ class drvUartUs100 : public drvUartBase {
114
114
/* !
115
115
@brief Destructor for a US-100 UART device.
116
116
*/
117
- ~drvUartUs100 () { /* TODO: Add back CTOR */ }
117
+ ~drvUartUs100 () {
118
+ if (_uart_dev) {
119
+ delete _uart_dev; // Clean up the UARTDevice instance
120
+ _uart_dev = nullptr ;
121
+ }
122
+ }
118
123
119
124
/* !
120
125
@brief Initializes the US-100 UART device.
121
126
@returns True if initialized successfully, False otherwise.
122
127
*/
123
128
bool begin () override {
124
- // is _hw_serial nullptr?
125
- if (_hw_serial == nullptr ) {
126
- WS_DEBUG_PRINTLN (" [uart] ERROR: _hw_serial is null!" );
129
+ #if HAS_SW_SERIAL
130
+ if (_sw_serial == nullptr )
131
+ return false ;
132
+ _uart_dev = new UARTDevice (_sw_serial);
133
+ #else
134
+ if (_hw_serial == nullptr )
127
135
return false ;
128
- } else {
129
- WS_DEBUG_PRINTLN (" [uart] _hw_serial is not null, proceeding..." );
130
- }
131
-
132
- WS_DEBUG_PRINTLN (
133
- " [uart] Initializing US-100 Ultrasonic Distance Sensor..." );
134
136
_uart_dev = new UARTDevice (_hw_serial);
135
- WS_DEBUG_PRINTLN (" [uart] Creating GenericDevice..." );
137
+ #endif // HAS_SW_SERIAL
138
+
136
139
// Create a GenericDevice instance using the UARTDevice
137
140
return _uart_dev->CreateDevice ();
138
- WS_DEBUG_PRINTLN (" [uart] US-100 device initialized successfully." );
139
141
return true ;
140
142
}
141
143
You can’t perform that action at this time.
0 commit comments