# HG changeset patch # User Ethan Zonca # Date 2024-09-29 20:02:43 # Node ID 755225bf17312862b2a0406fdd5f4801831dbf80 # Parent 48d2337d76c226f474a036d9a4dcf6051fb917cd Add discovery message TX. Add unused nonvolatile flash saving. diff --git a/components/esp-osc/esp_osc.c b/components/esp-osc/esp_osc.c --- a/components/esp-osc/esp_osc.c +++ b/components/esp-osc/esp_osc.c @@ -79,7 +79,7 @@ bool esp_osc_send_v(esp_osc_client_t *cl return false; } else{ - ESP_LOGI(TAG, "sent message OK"); + // ESP_LOGI(TAG, "sent message OK"); } return true; diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -1,2 +1,2 @@ -idf_component_register(SRCS "main.c" "wifi.c" "usb_cdc.c" "can.c" "display.c" "display_gui.c" "osc_control.c" "ledstrip.c" "squeeze.c" +idf_component_register(SRCS "main.c" "wifi.c" "usb_cdc.c" "can.c" "display.c" "display_gui.c" "osc_control.c" "ledstrip.c" "squeeze.c" "flash.c" INCLUDE_DIRS .) diff --git a/main/main.c b/main/main.c --- a/main/main.c +++ b/main/main.c @@ -9,7 +9,7 @@ #include "esp_system.h" #include "esp_event.h" #include "esp_log.h" -#include "nvs_flash.h" +#include "flash.h" #include "sdkconfig.h" #include "osc_control.h" #include "wifi.h" @@ -24,7 +24,6 @@ // Private variables static const char *TAG = "main"; - // Application entry point void app_main(void) { @@ -32,12 +31,18 @@ void app_main(void) // usb_cdc_init(); // Initialize NVS - esp_err_t ret = nvs_flash_init(); - if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { - ESP_ERROR_CHECK(nvs_flash_erase()); - ret = nvs_flash_init(); - } - ESP_ERROR_CHECK(ret); + // esp_err_t ret = nvs_flash_init(); + // if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { + // ESP_ERROR_CHECK(nvs_flash_erase()); + // ret = nvs_flash_init(); + // } + // ESP_ERROR_CHECK(ret); + + flash_init(); + int32_t cnt = flash_read("count"); + cnt += 1; + flash_write("count", cnt); + // Initialize display display_init(); @@ -64,6 +69,8 @@ void app_main(void) while(1) { + // ESP_LOGI(TAG, "cnt=%ld\n", cnt); + vTaskDelay(pdMS_TO_TICKS(100)); } diff --git a/main/osc_control.c b/main/osc_control.c --- a/main/osc_control.c +++ b/main/osc_control.c @@ -148,6 +148,7 @@ static void osc_send() vTaskDelay(pdMS_TO_TICKS(2000)); uint32_t last_tx = 0; + uint32_t last_discover = 0; for (;;) { @@ -165,12 +166,18 @@ static void osc_send() esp_osc_send(&client, &target, "/squeeze_value", "f", squeeze_value()); } + if(xTaskGetTickCount()*portTICK_PERIOD_MS - last_discover > 1000) + { + last_discover = xTaskGetTickCount() * portTICK_PERIOD_MS; + esp_osc_send(&client, &target, "/discover", "s", "ledstrip"); + } + vTaskDelay(pdMS_TO_TICKS(10)); } } void osc_init() { - esp_osc_init(&client, 1024, 5005); + esp_osc_init(&client, 1024, 5000); xTaskCreatePinnedToCore(osc_process, "osc_process", 1024*8, NULL, 10, NULL, 1); xTaskCreatePinnedToCore(osc_send, "osc_send", 1024*4, NULL, 10, NULL, 1);