Changeset - 48d2337d76c2
[Not reviewed]
default
0 4 0
Ethan Zonca - 8 months ago 2024-09-29 12:16:50
ez@ethanzonca.com
Functional OSC TX and RX
4 files changed with 70 insertions and 41 deletions:
0 comments (0 inline, 0 general)
components/esp-osc/esp_osc.c
Show inline comments
 
#include <stdio.h>
 
#include <stdarg.h>
 
#include <esp_log.h>
 

	
 
#include "esp_osc.h"
 

	
 
#define TAG "esp-osc"
 
@@ -79,6 +78,9 @@ bool esp_osc_send_v(esp_osc_client_t *cl
 
    ESP_LOGE(TAG, "failed to send message (%d)", errno);
 
    return false;
 
  }
 
  else{
 
    ESP_LOGI(TAG, "sent message OK");
 
  }
 

	
 
  return true;
 
}
main/main.c
Show inline comments
 
@@ -48,11 +48,11 @@ void app_main(void)
 

	
 
    ledstrip_init();
 

	
 
    squeeze_init();
 

	
 
    // Initialize OSC
 
    osc_init();
 

	
 
    squeeze_init();
 

	
 
    // Initialize canbus
 
    //can_init();
main/osc_control.c
Show inline comments
 
@@ -6,35 +6,32 @@
 
#include "display.h"
 
#include <esp_osc.h>
 
#include "ledstrip.h"
 
#include "squeeze.h"
 

	
 
#define WIFI_SSID ""
 
#define WIFI_PASS ""
 

	
 
#define OSC_ADDRESS ""
 
#define OSC_PORT 0
 

	
 
static const char *TAG = "osc_control";
 

	
 
esp_osc_client_t client;
 
#define FLAMESPEWER_IP "192.168.1.25"
 

	
 
static esp_osc_client_t client;
 

	
 
static void sender()
 
{
 
  // select targets
 
  esp_osc_target_t targets[2] = {
 
      esp_osc_target("127.0.0.1", 9000),
 
      esp_osc_target(OSC_ADDRESS, OSC_PORT),
 
  };
 
// static void sender()
 
// {
 
//   // select targets
 
//   esp_osc_target_t targets[2] = {
 
//       esp_osc_target("127.0.0.1", 9000),
 
//   };
 

	
 
  for(;;) {
 
    // delay
 
    vTaskDelay(1000 / portTICK_PERIOD_MS);
 
//   for(;;) {
 
//     // delay
 
//     vTaskDelay(1000 / portTICK_PERIOD_MS);
 

	
 
    // send messages
 
    for (size_t i = 0; i < 2; i++) {
 
      esp_osc_send(&client, &targets[i], "test", "ihfdsb", 42, (int64_t)84, 3.14f, 6.28, "foo", 3, "bar");
 
    }
 
  }
 
}
 
//     // send messages
 
//     for (size_t i = 0; i < 2; i++) {
 
//       esp_osc_send(&client, &targets[i], "test", "ihfdsb", 42, (int64_t)84, 3.14f, 6.28, "foo", 3, "bar");
 
//     }
 
//   }
 
// }
 

	
 
static uint8_t r_man = 0;
 
static uint8_t g_man = 0;
 
@@ -78,7 +75,7 @@ static bool callback(const char *topic, 
 

	
 
        snprintf(out+strlen(out), 128-strlen(out), "Value: %f", values[i].f);
 
        ESP_LOGI(TAG, "==> f: %f", values[i].f);
 
        
 

	
 
        if(strcmp(topic, "/led_modifier") == 0)
 
        {
 
          ledstrip_set_modifier(values[i].f);
 
@@ -117,6 +114,7 @@ static bool callback(const char *topic, 
 
      }
 

	
 
    }
 
    
 
  }
 

	
 
  display_update_text(out);
 
@@ -124,30 +122,56 @@ static bool callback(const char *topic, 
 
  return true;
 
}
 

	
 
static void receiver() {
 

	
 
#define FLAMESPEWER_IP "192.168.1.204"
 

	
 
static void osc_process() 
 
{
 

	
 
  for (;;) {
 
    // receive messages
 
    esp_osc_receive(&client, callback);
 
  }
 
}
 

	
 
static void restarter() {
 
  for (;;) {
 
    // delay
 
    vTaskDelay(5000 / portTICK_PERIOD_MS);
 

	
 
    // restart client
 
    esp_osc_init(&client, 1024, 9000);
 
    // vTaskDelay(pdMS_TO_TICKS(100));
 
    vTaskDelay(pdMS_TO_TICKS(100));
 
  }
 
}
 

	
 

	
 
//#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;
 

	
 
  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());
 
    }
 

	
 
    vTaskDelay(pdMS_TO_TICKS(10));
 
  }
 
}
 

	
 
void osc_init() {
 
  // prepare client
 
  esp_osc_init(&client, 1024, 5005);
 

	
 
  // create tasks
 
  //xTaskCreatePinnedToCore(sender, "sender", 4096, NULL, 10, NULL, 1);
 
  xTaskCreatePinnedToCore(receiver, "receiver", 4096, NULL, 10, NULL, 1);
 
  //xTaskCreatePinnedToCore(restarter, "restarter", 4096, NULL, 10, NULL, 1);
 
  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
main/wifi.c
Show inline comments
 
@@ -73,6 +73,9 @@ void wifi_init(void)
 
    wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
 
    ESP_ERROR_CHECK(esp_wifi_init(&cfg));
 

	
 
    // EMZ new
 
    ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
 

	
 
    esp_event_handler_instance_t instance_any_id;
 
    esp_event_handler_instance_t instance_got_ip;
 
    ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
0 comments (0 inline, 0 general)