diff --git a/lib_standalone/Arduino.cpp b/lib_standalone/Arduino.cpp index 69cb01aef..16b286985 100644 --- a/lib_standalone/Arduino.cpp +++ b/lib_standalone/Arduino.cpp @@ -147,5 +147,6 @@ double ledcSetup(uint8_t chan, double freq, uint8_t bit_num) { void ledcAttachPin(uint8_t pin, uint8_t chan) {}; void ledcWrite(uint8_t chan, uint32_t duty) {}; void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val) {}; +void rgbLedWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val) {}; #endif \ No newline at end of file diff --git a/lib_standalone/Arduino.h b/lib_standalone/Arduino.h index adecdc7d0..9fe2f9ec1 100644 --- a/lib_standalone/Arduino.h +++ b/lib_standalone/Arduino.h @@ -72,6 +72,7 @@ double ledcSetup(uint8_t chan, double freq, uint8_t bit_num); void ledcAttachPin(uint8_t pin, uint8_t chan); void ledcWrite(uint8_t chan, uint32_t duty); void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val); +void rgbLedWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val); #define PROGMEM #define PGM_P const char * diff --git a/src/core/system.cpp b/src/core/system.cpp index 441d3ee6f..4701ec4de 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -551,7 +551,11 @@ void System::led_init(bool refresh) { if (refresh) { // disabled old led port before setting new one if ((led_gpio_ != 0) && is_valid_gpio(led_gpio_)) { +#if ESP_ARDUINO_VERSION_MAJOR < 3 led_type_ ? neopixelWrite(led_gpio_, 0, 0, 0) : digitalWrite(led_gpio_, !LED_ON); +#else + led_type_ ? rgbLedWrite(led_gpio_, 0, 0, 0) : digitalWrite(led_gpio_, !LED_ON); +#endif pinMode(led_gpio_, INPUT); } reload_settings(); @@ -560,7 +564,11 @@ void System::led_init(bool refresh) { if ((led_gpio_ != 0) && is_valid_gpio(led_gpio_)) { // 0 means disabled if (led_type_) { // rgb LED WS2812B, use Neopixel +#if ESP_ARDUINO_VERSION_MAJOR < 3 neopixelWrite(led_gpio_, 0, 0, 0); +#else + rgbLedWrite(led_gpio_, 0, 0, 0); +#endif } else { pinMode(led_gpio_, OUTPUT); digitalWrite(led_gpio_, !LED_ON); // start with LED off @@ -817,12 +825,20 @@ void System::system_check() { if (healthcheck_ == 0) { // everything is healthy, show LED permanently on or off depending on setting if (led_gpio_) { +#if ESP_ARDUINO_VERSION_MAJOR < 3 led_type_ ? neopixelWrite(led_gpio_, 0, hide_led_ ? 0 : 128, 0) : digitalWrite(led_gpio_, hide_led_ ? !LED_ON : LED_ON); +#else + led_type_ ? rgbLedWrite(led_gpio_, 0, hide_led_ ? 0 : 128, 0) : digitalWrite(led_gpio_, hide_led_ ? !LED_ON : LED_ON); +#endif } } else { // turn off LED so we're ready to the flashes if (led_gpio_) { +#if ESP_ARDUINO_VERSION_MAJOR < 3 led_type_ ? neopixelWrite(led_gpio_, 0, 0, 0) : digitalWrite(led_gpio_, !LED_ON); +#else + led_type_ ? rgbLedWrite(led_gpio_, 0, 0, 0) : digitalWrite(led_gpio_, !LED_ON); +#endif } } } @@ -882,7 +898,11 @@ void System::led_monitor() { // reset the whole sequence led_long_timer_ = uuid::get_uptime(); led_flash_step_ = 0; +#if ESP_ARDUINO_VERSION_MAJOR < 3 led_type_ ? neopixelWrite(led_gpio_, 0, 0, 0) : digitalWrite(led_gpio_, !LED_ON); // LED off +#else + led_type_ ? rgbLedWrite(led_gpio_, 0, 0, 0) : digitalWrite(led_gpio_, !LED_ON); // LED off +#endif } else if (led_flash_step_ % 2) { // handle the step events (on odd numbers 3,5,7,etc). see if we need to turn on a LED // 1 flash is the EMS bus is not connected @@ -892,17 +912,33 @@ void System::led_monitor() { if (led_type_) { if (led_flash_step_ == 3) { if ((healthcheck_ & HEALTHCHECK_NO_NETWORK) == HEALTHCHECK_NO_NETWORK) { +#if ESP_ARDUINO_VERSION_MAJOR < 3 neopixelWrite(led_gpio_, 128, 0, 0); // red +#else + rgbLedWrite(led_gpio_, 128, 0, 0); // red +#endif } else if ((healthcheck_ & HEALTHCHECK_NO_BUS) == HEALTHCHECK_NO_BUS) { +#if ESP_ARDUINO_VERSION_MAJOR < 3 neopixelWrite(led_gpio_, 0, 0, 128); // blue +#else + rgbLedWrite(led_gpio_, 0, 0, 128); // blue +#endif } } if (led_flash_step_ == 5 && (healthcheck_ & HEALTHCHECK_NO_NETWORK) == HEALTHCHECK_NO_NETWORK) { +#if ESP_ARDUINO_VERSION_MAJOR < 3 neopixelWrite(led_gpio_, 128, 0, 0); // red +#else + rgbLedWrite(led_gpio_, 128, 0, 0); // red +#endif } if ((led_flash_step_ == 7) && ((healthcheck_ & HEALTHCHECK_NO_NETWORK) == HEALTHCHECK_NO_NETWORK) && ((healthcheck_ & HEALTHCHECK_NO_BUS) == HEALTHCHECK_NO_BUS)) { +#if ESP_ARDUINO_VERSION_MAJOR < 3 neopixelWrite(led_gpio_, 0, 0, 128); // blue +#else + rgbLedWrite(led_gpio_, 0, 0, 128); // blue +#endif } } else { if ((led_flash_step_ == 3) @@ -926,7 +962,11 @@ void System::led_monitor() { } else { // turn the led off after the flash, on even number count if (led_on_) { +#if ESP_ARDUINO_VERSION_MAJOR < 3 led_type_ ? neopixelWrite(led_gpio_, 0, 0, 0) : digitalWrite(led_gpio_, !LED_ON); +#else + led_type_ ? rgbLedWrite(led_gpio_, 0, 0, 0) : digitalWrite(led_gpio_, !LED_ON); +#endif led_on_ = false; } } diff --git a/src/uart/emsuart_esp32.cpp b/src/uart/emsuart_esp32.cpp index 0b9f2fccc..bf13dfd4a 100644 --- a/src/uart/emsuart_esp32.cpp +++ b/src/uart/emsuart_esp32.cpp @@ -73,14 +73,17 @@ void EMSuart::uart_event_task(void * pvParameters) { */ void EMSuart::start(const uint8_t tx_mode, const uint8_t rx_gpio, const uint8_t tx_gpio) { if (tx_mode_ == 0xFF) { - uart_config_t uart_config = { - .baud_rate = EMSUART_BAUD, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, - .rx_flow_ctrl_thresh = 0, // not used - https://docs.espressif.com/projects/esp-idf/en/v3.3.6/api-reference/peripherals/uart.html - .source_clk = UART_SCLK_APB, + uart_config_t uart_config = {.baud_rate = EMSUART_BAUD, + .data_bits = UART_DATA_8_BITS, + .parity = UART_PARITY_DISABLE, + .stop_bits = UART_STOP_BITS_1, + .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, + .rx_flow_ctrl_thresh = 0, + .source_clk = UART_SCLK_APB +#if ESP_ARDUINO_VERSION_MAJOR >= 3 + , + .flags = {0, 0} +#endif }; #if defined(EMSUART_RX_INVERT) inverse_mask |= UART_SIGNAL_RXD_INV;