main/dcf77tx.c

changeset 5
676c38f52d08
parent 3
849ca14d4a2f
--- a/main/dcf77tx.c	Sat Oct 21 16:22:20 2023 +0200
+++ b/main/dcf77tx.c	Sat Oct 21 17:22:37 2023 +0200
@@ -10,7 +10,7 @@
 static TaskHandle_t			xTaskDCF = NULL;
 char					hostname[32];
 int					Main_Loop = ML_INIT;
-
+static led_strip_handle_t		led_strip;			///< ESP32-C3 onboard LED
 
 extern SemaphoreHandle_t		xSemaphoreWiFi;
 extern WIFI_State			*wifi_state;			///< WiFi state
@@ -21,6 +21,17 @@
 extern bool				System_TimeOk;
 
 
+void set_ob_led(uint32_t red, uint32_t green, uint32_t blue)
+{
+    if ((red + green + blue) > 0) {
+    	led_strip_set_pixel(led_strip, 0, red, green, blue);
+    	led_strip_refresh(led_strip);
+    } else {
+	led_strip_clear(led_strip);
+    }
+}
+
+
 void app_main(void)
 {
     esp_err_t	ret;
@@ -49,6 +60,17 @@
     xTaskCreate(&task_wifi,    "task_wifi",     4096, NULL, 3, &xTaskWifi);
     xTaskCreate(&task_DCF,     "task_DCF",      4096, NULL, 4, &xTaskDCF);
 
+    led_strip_config_t strip_config = {
+        .strip_gpio_num = 7,
+        .max_leds = 1, // at least one LED on board
+    };
+    led_strip_rmt_config_t rmt_config = {
+        .resolution_hz = 10 * 1000 * 1000, // 10MHz
+    };
+    ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &led_strip));
+    /* Set all LED off to clear all pixels */
+    led_strip_clear(led_strip);
+
     int wait = 150;
     while (wait) {
         vTaskDelay(100 / portTICK_PERIOD_MS);
@@ -78,7 +100,7 @@
 	    case ML_INIT:	if (ready_WiFi() ) {
 				    Main_Loop = ML_SYNC;
 				    ESP_LOGI(TAG, "ML_INIT -> ML_SYNC");
-				    gpio_set_level(CONFIG_LED1_PIN, 1);
+				    set_ob_led(5, 0, 0);
 				} else {
 				    Main_Loop = ML_CONNECT;
 				    ESP_LOGI(TAG, "ML_INIT -> ML_CONNECT");
@@ -99,16 +121,12 @@
 				    Main_Loop = ML_RUN;
 				    ESP_LOGI(TAG, "ML_SYNC -> ML_RUN");
 				    request_DCF(true);
-				    gpio_set_level(CONFIG_LED2_PIN, 1);
-				    gpio_set_level(CONFIG_LED1_PIN, 0);
 				}
 				break;
 	    case ML_RUN:	if (System_TimeOk == false) {
 				    Main_Loop = ML_CONNECT;
 				    ESP_LOGI(TAG, "ML_RUN -> ML_CONNECT");
 				    request_DCF(false);
-				    gpio_set_level(CONFIG_LED1_PIN, 0);
-				    gpio_set_level(CONFIG_LED2_PIN, 0);
 				}
 				break;
 	}

mercurial