From 9be13eb0b98964f49d2748086e80fd027277687b Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Thu, 13 Oct 2022 14:07:52 +0200 Subject: [PATCH] Lolin C3 mini v1.0 has standard led. --- lib/framework/NetworkSettingsService.cpp | 2 +- src/system.cpp | 42 ++++++++++++++++-------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/lib/framework/NetworkSettingsService.cpp b/lib/framework/NetworkSettingsService.cpp index 91b0ee00b..23428d2f4 100644 --- a/lib/framework/NetworkSettingsService.cpp +++ b/lib/framework/NetworkSettingsService.cpp @@ -75,7 +75,7 @@ void NetworkSettingsService::manageSTA() { esp_wifi_set_max_tx_power(networkSettings.tx_power * 4); // set power after wifi is startet for C3 }); #ifdef BOARD_C3_MINI_V1 - // not sure if we need this special value for c3_min_v1.0 + // v1 needs this value, see https://github.com/emsesp/EMS-ESP32/pull/620#discussion_r993173979 WiFi.setTxPower(WIFI_POWER_8_5dBm); // https://www.wemos.cc/en/latest/c3/c3_mini_1_0_0.html#about-wifi #endif } diff --git a/src/system.cpp b/src/system.cpp index 3f633239f..4ea14a3ca 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -38,7 +38,7 @@ #include "../rom/rtc.h" #endif #endif -#ifdef ARDUINO_LOLIN_C3_MINI +#if defined(ARDUINO_LOLIN_C3_MINI) && !defined(BOARD_C3_MINI_V1) #include Adafruit_NeoPixel pixels(1, 7, NEO_GRB + NEO_KHZ800); #endif @@ -459,14 +459,14 @@ void System::led_init(bool refresh) { } if ((led_gpio_ != 0) && is_valid_gpio(led_gpio_)) { -#ifdef ARDUINO_LOLIN_C3_MINI +#if defined(ARDUINO_LOLIN_C3_MINI) && !defined(BOARD_C3_MINI_V1) // rgb LED WS2812B, use Adafruit Neopixel // Adafruit_NeoPixel pixels(1, 7, NEO_GRB + NEO_KHZ800); pixels.begin(); pixels.setPin(led_gpio_); // pixels.setBrightness(0); - pixels.Color(0, 0, 0, 0); - pixels.show(); + // pixels.Color(0, 0, 0, 0); + // pixels.show(); #else pinMode(led_gpio_, OUTPUT); // 0 means disabled digitalWrite(led_gpio_, !LED_ON); // start with LED off @@ -661,7 +661,7 @@ void System::system_check() { if (healthcheck_ == 0) { // everything is healthy, show LED permanently on or off depending on setting if (led_gpio_) { -#ifdef ARDUINO_LOLIN_C3_MINI +#if defined(ARDUINO_LOLIN_C3_MINI) && !defined(BOARD_C3_MINI_V1) pixels.setPixelColor(0, 0, hide_led_ ? 0 : 128, 0); pixels.show(); #else @@ -672,7 +672,7 @@ void System::system_check() { } else { // turn off LED so we're ready to the flashes if (led_gpio_) { -#ifdef ARDUINO_LOLIN_C3_MINI +#if defined(ARDUINO_LOLIN_C3_MINI) && !defined(BOARD_C3_MINI_V1) pixels.setPixelColor(0, 0, 0, 0); pixels.show(); #else @@ -738,7 +738,7 @@ void System::led_monitor() { // Serial.println("resetting flash check"); led_long_timer_ = uuid::get_uptime(); led_flash_step_ = 0; -#ifdef ARDUINO_LOLIN_C3_MINI +#if defined(ARDUINO_LOLIN_C3_MINI) && !defined(BOARD_C3_MINI_V1) pixels.setPixelColor(0, 0, 0, 0); pixels.show(); #else @@ -750,6 +750,24 @@ void System::led_monitor() { // 2 flashes if the network (wifi or ethernet) is not connected // 3 flashes is both the bus and the network are not connected. Then you know you're truly f*cked. +#if defined(ARDUINO_LOLIN_C3_MINI) && !defined(BOARD_C3_MINI_V1) + if (led_flash_step_ == 3) { + if ((healthcheck_ & HEALTHCHECK_NO_NETWORK) == HEALTHCHECK_NO_NETWORK) { + pixels.setPixelColor(0, 128, 0, 0); // red + } else if ((healthcheck_ & HEALTHCHECK_NO_BUS) == HEALTHCHECK_NO_BUS) { + pixels.setPixelColor(0, 0, 0, 128); // blue + } + } + if (led_flash_step_ == 5 && (healthcheck_ & HEALTHCHECK_NO_NETWORK) == HEALTHCHECK_NO_NETWORK) { + pixels.setPixelColor(0, 128, 0, 0); // red + } + if ((led_flash_step_ == 7) && ((healthcheck_ & HEALTHCHECK_NO_NETWORK) == HEALTHCHECK_NO_NETWORK) + && ((healthcheck_ & HEALTHCHECK_NO_BUS) == HEALTHCHECK_NO_BUS)) { + pixels.setPixelColor(0, 0, 0, 128); // blue + } + pixels.show(); +#else + if ((led_flash_step_ == 3) && (((healthcheck_ & HEALTHCHECK_NO_NETWORK) == HEALTHCHECK_NO_NETWORK) || ((healthcheck_ & HEALTHCHECK_NO_BUS) == HEALTHCHECK_NO_BUS))) { led_on_ = true; @@ -765,17 +783,13 @@ void System::led_monitor() { } if (led_on_) { -#ifdef ARDUINO_LOLIN_C3_MINI - pixels.setPixelColor(0, 128, 0, 0); - pixels.show(); -#else - digitalWrite(led_gpio_, LED_ON); // LED off -#endif + digitalWrite(led_gpio_, LED_ON); // LED off } +#endif } else { // turn the led off after the flash, on even number count if (led_on_) { -#ifdef ARDUINO_LOLIN_C3_MINI +#if defined(ARDUINO_LOLIN_C3_MINI) && !defined(BOARD_C3_MINI_V1) pixels.setPixelColor(0, 0, 0, 0); pixels.show(); #else