Files
@ 45c4b4d15fc5
Branch filter:
Location: protofusion-esp32-template/main/osc_control.c
45c4b4d15fc5
3.3 KiB
text/plain
Add squeeze sensing. Update chase to only do one rep.
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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | #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':
{
if(values[i].f > 1.0)
values[i].f = 1.0;
if(values[i].f < 0.0)
values[i].f = 0.0;
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(g_man, r_man, b_man);
}
else if(strcmp(topic, "/led_manual_g") == 0)
{
g_man = values[i].f * 255.0;
ledstrip_set(g_man, r_man, b_man);
}
else if(strcmp(topic, "/led_manual_b") == 0)
{
b_man = values[i].f * 255.0;
ledstrip_set(g_man, r_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);
}
|