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 {
7676 @returns True if initialized successfully, False otherwise.
7777 */
7878 bool begin () override {
79+ #if HAS_SW_SERIAL
80+ if (_sw_serial == nullptr )
81+ return false ;
82+ #else
7983 if (_hw_serial == nullptr )
8084 return false ;
85+ #endif // HAS_SW_SERIAL
8186
8287 _pm25 = new Adafruit_PM25AQI ();
8388 if (_pm25 == nullptr )
8489 return false ;
8590
8691 delay (1000 ); // Wait for the sensor to boot
92+
93+ #ifdef HAS_SW_SERIAL
94+ return _pm25->begin_UART (_sw_serial);
95+ #else
8796 return _pm25->begin_UART (_hw_serial);
97+ #endif // HAS_SW_SERIAL
8898 }
8999
90100 /* !
Original file line number Diff line number Diff line change @@ -114,28 +114,30 @@ class drvUartUs100 : public drvUartBase {
114114 /* !
115115 @brief Destructor for a US-100 UART device.
116116 */
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+ }
118123
119124 /* !
120125 @brief Initializes the US-100 UART device.
121126 @returns True if initialized successfully, False otherwise.
122127 */
123128 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 )
127135 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..." );
134136 _uart_dev = new UARTDevice (_hw_serial);
135- WS_DEBUG_PRINTLN (" [uart] Creating GenericDevice..." );
137+ #endif // HAS_SW_SERIAL
138+
136139 // Create a GenericDevice instance using the UARTDevice
137140 return _uart_dev->CreateDevice ();
138- WS_DEBUG_PRINTLN (" [uart] US-100 device initialized successfully." );
139141 return true ;
140142 }
141143
You can’t perform that action at this time.
0 commit comments