Files @ 64275d7d6618
Branch filter:

Location: protofusion-esp32-template/main/osc_control.c - annotation

Ethan Zonca
More LED work, etc
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
91735168ee75
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
e4270e6d9529
e4270e6d9529
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
e4270e6d9529
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
64275d7d6618
64275d7d6618
64275d7d6618
64275d7d6618
e4270e6d9529
e4270e6d9529
e4270e6d9529
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
e4270e6d9529
e4270e6d9529
e4270e6d9529
e4270e6d9529
33512a8a338c
e4270e6d9529
e4270e6d9529
33512a8a338c
e4270e6d9529
e4270e6d9529
e4270e6d9529
e4270e6d9529
e4270e6d9529
e4270e6d9529
33512a8a338c
e4270e6d9529
33512a8a338c
e4270e6d9529
e4270e6d9529
33512a8a338c
e4270e6d9529
33512a8a338c
33512a8a338c
e4270e6d9529
e4270e6d9529
e4270e6d9529
e4270e6d9529
64275d7d6618
64275d7d6618
64275d7d6618
64275d7d6618
64275d7d6618
64275d7d6618
64275d7d6618
64275d7d6618
64275d7d6618
64275d7d6618
64275d7d6618
64275d7d6618
64275d7d6618
64275d7d6618
64275d7d6618
e4270e6d9529
91735168ee75
33512a8a338c
e4270e6d9529
33512a8a338c
e4270e6d9529
e4270e6d9529
33512a8a338c
e4270e6d9529
33512a8a338c
e4270e6d9529
e4270e6d9529
33512a8a338c
e4270e6d9529
33512a8a338c
33512a8a338c
e4270e6d9529
e4270e6d9529
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
33512a8a338c
#include "osc_control.h"
#include <stdlib.h>
#include <esp_event.h>
#include <esp_log.h>
#include <esp_wifi.h>
#include "display.h"
#include <esp_osc.h>
#include "ledstrip.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;

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

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

static uint8_t r_man = 0;
static uint8_t g_man = 0;
static uint8_t b_man = 0;


static bool callback(const char *topic, const char *format, esp_osc_value_t *values)
{
  // log message
  ESP_LOGI(TAG, "got message: %s (%s)", topic, format);


  char out[512] = {0};
  snprintf(out, 128, "topic: %s\nformat: %s\n", topic, format);

  for (size_t i = 0; i < strlen(format); i++) 
  {
    switch (format[i])
    {
      case 'i':
      {
        snprintf(out+strlen(out), 128-strlen(out), "Value: %ld", values[i].i);
        ESP_LOGI(TAG, "==> i: %ld", values[i].i);
        if(strcmp(topic, "/led_effect") == 0)
        {
          ledstrip_set_effect(values[i].i);
        }
      } break;

      case 'h':
      {
        ESP_LOGI(TAG, "==> h: %lld", values[i].h);
      }  break;

      case 'f':
      {
        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);
        }
        else if(strcmp(topic, "/led_manual_r") == 0)
        {
          r_man = values[i].f * 255.0;
          ledstrip_set(r_man, g_man, b_man);
        }
        else if(strcmp(topic, "/led_manual_g") == 0)
        {
          g_man = values[i].f * 255.0;
          ledstrip_set(r_man, g_man, b_man);
        }
        else if(strcmp(topic, "/led_manual_b") == 0)
        {
          b_man = values[i].f * 255.0;
          ledstrip_set(r_man, g_man, b_man);
        }
      } break;

      case 'd':
      {
        ESP_LOGI(TAG, "==> d: %f", values[i].d);
      } break;

      case 's':
      {
        ESP_LOGI(TAG, "==> s: %s", values[i].s);
      }  break;

      case 'b':
      {
        ESP_LOGI(TAG, "==> b: %.*s (%d)", values[i].bl, values[i].b, values[i].bl);
        break;
      }

    }
  }

  display_update_text(out);

  return true;
}

static void receiver() {
  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);
  }
}


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