Files
@ 54d6639e1b4b
Branch filter:
Location: protofusion-esp32-template/main/osc_control.c
54d6639e1b4b
2.4 KiB
text/plain
Cleanup ledstrip implementation
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | #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 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);
uint8_t val = values[i].f * 255;
// ledstrip_set(val, val, val);
ledstrip_set_modifier(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);
}
|