Files
@ 33512a8a338c
Branch filter:
Location: protofusion-esp32-template/main/osc_control.c - annotation
33512a8a338c
2.2 KiB
text/plain
Add OSC library, works!
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 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 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>
#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 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':
ESP_LOGI(TAG, "==> i: %ld", 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);
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);
}
|