Changeset - 755225bf1731
[Not reviewed]
default
0 4 0
Ethan Zonca - 8 months ago 2024-09-29 20:02:43
ez@ethanzonca.com
Add discovery message TX. Add unused nonvolatile flash saving.
4 files changed with 25 insertions and 11 deletions:
0 comments (0 inline, 0 general)
components/esp-osc/esp_osc.c
Show inline comments
 
@@ -70,25 +70,25 @@ bool esp_osc_send(esp_osc_client_t *clie
 

	
 
bool esp_osc_send_v(esp_osc_client_t *client, esp_osc_target_t *target, const char *topic, const char *format,
 
                    va_list args) {
 
  // prepare message
 
  uint32_t length = tosc_vwrite((char *)client->sbuf, client->len, topic, format, args);
 

	
 
  // send message
 
  if (sendto(client->socket, client->sbuf, length, 0, (struct sockaddr *)&target->addr, sizeof(target->addr)) < 0) {
 
    ESP_LOGE(TAG, "failed to send message (%d)", errno);
 
    return false;
 
  }
 
  else{
 
    ESP_LOGI(TAG, "sent message OK");
 
    // ESP_LOGI(TAG, "sent message OK");
 
  }
 

	
 
  return true;
 
}
 

	
 
bool esp_osc_receive(esp_osc_client_t *client, esp_osc_callback_t callback) {
 
  // prepare values
 
  esp_osc_value_t values[32];
 

	
 
  for (;;) {
 
    // receive message
 
    ssize_t ret = recvfrom(client->socket, client->rbuf, client->len, 0, NULL, NULL);
main/CMakeLists.txt
Show inline comments
 
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 .)
main/main.c
Show inline comments
 
//
 
// Protofusion ESP32S3 Template
 
//
 

	
 
#include <stdint.h>
 
#include "freertos/FreeRTOS.h"
 
#include "freertos/task.h"
 
#include "freertos/event_groups.h"
 
#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"
 
// #include "usb_cdc.h"
 
#include "can.h"
 
#include "display.h"
 
#include "squeeze.h"
 
#include "ledstrip.h"
 
#include "display_gui.h"
 

	
 

	
 
// Private variables
 
static const char *TAG = "main";
 

	
 

	
 
// Application entry point
 
void app_main(void)
 
{
 
    // Initialize usb-cdc interface
 
    // 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();
 
    display_gui_homescreen();
 

	
 
    // Connect to wifi
 
    wifi_init();
 

	
 
    ledstrip_init();
 

	
 
    squeeze_init();
 

	
 
@@ -55,16 +60,18 @@ void app_main(void)
 

	
 

	
 
    // Initialize canbus
 
    //can_init();
 

	
 
    // Start tasks
 
    xTaskCreatePinnedToCore(ledstrip_refresh,    "ledstrip_refresh", 4096, NULL, 10, NULL, 1);
 
    xTaskCreatePinnedToCore(display_gui_process, "display_gui_process", 4096, NULL, 10, NULL, 1);
 

	
 

	
 
    while(1)
 
    {
 
        // ESP_LOGI(TAG, "cnt=%ld\n", cnt);
 

	
 
        vTaskDelay(pdMS_TO_TICKS(100));
 
    }
 

	
 
}
main/osc_control.c
Show inline comments
 
@@ -139,39 +139,46 @@ static void osc_process()
 

	
 
//#define pdTICKSTOMS( xTicks ) ( ( ( TickTypet ) ( xTicks ) * 1000u ) / configTICKRATE_HZ )
 

	
 
static void osc_send() 
 
{
 
  ESP_LOGI(TAG, "begin task osc_send");
 

	
 
  // // Really need this to wait for wifi connect
 
  esp_osc_target_t target = esp_osc_target("192.168.1.25", 5005);
 
    vTaskDelay(pdMS_TO_TICKS(2000));
 

	
 
  uint32_t last_tx = 0;
 
  uint32_t last_discover = 0;
 

	
 
  for (;;) {
 

	
 

	
 
    if(squeeze_triggered())
 
    {
 
      ESP_LOGI(TAG, "trig that squeeze");
 

	
 
      esp_osc_send(&client, &target, "/squeeze_trig", "i", 1);
 
    }
 

	
 
    if(xTaskGetTickCount()*portTICK_PERIOD_MS - last_tx > 150)
 
    {
 
      last_tx = xTaskGetTickCount() * portTICK_PERIOD_MS;
 
      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);
 
}
 
\ No newline at end of file
0 comments (0 inline, 0 general)