From d385cb8a3517c9165ac15602a2669f17f58319c4 Mon Sep 17 00:00:00 2001 From: Clawdia Date: Wed, 12 Aug 2026 13:03:42 +0200 Subject: [PATCH] Fix phase durations & colors for 9-phase relaxation, use duration_sec and red hues --- src/main.c | 119 ++++++++++++++--------------------------------------- 1 file changed, 32 insertions(+), 87 deletions(-) diff --git a/src/main.c b/src/main.c index 24e93dc..af053ba 100644 --- a/src/main.c +++ b/src/main.c @@ -21,19 +21,20 @@ static rmt_encoder_handle_t led_encoder = NULL; typedef struct { const char *name; int freq_hz; - int duration_min; - uint32_t hue; + int duration_sec; + uint32_t hue; // 0 = Rot, 20-30 = warmes Orange-Rot } preset_t; static const preset_t presets[] = { - // 25-Minuten-Entspannungsprogramm mit absteigender Frequenz und Aufwachphase - // Alpha -> Theta -> sanfter Aufweck-Anstieg für sicheren Abschluss - {"Einschwingen", 12, 3, 15}, - {"Alpha Entspannung", 10, 5, 0}, - {"Alpha/Theta Übergang", 8, 6, 20}, - {"Theta Entspannung", 6, 6, 10}, - {"Tiefe Theta", 4, 3, 5}, - {"Aufwachen", 10, 2, 30} + {"Ankommen / Beta→Alpha", 10, 60, 0}, // 1 min Rot hell + {"Alpha-Entspannung", 8, 90, 5}, // 1.5 min Rot + {"Theta-Eintauchen", 5, 90, 10}, // 1.5 min Tiefes Rot + {"Theta-Tiefe", 6, 90, 15}, // 1.5 min Warmes Rot + {"Delta-Regeneration", 2,120, 20}, // 2 min Dunkelrot + {"Delta-Tiefschlaf", 1,120, 25}, // 2 min Sehr dunkel Rot + {"Theta-Aufstieg", 4, 90, 18}, // 1.5 min Warmes Rot + {"Alpha-Weckphase", 7, 90, 8}, // 1.5 min Helles Rot + {"Wachwerden / Gamma-Hit",10, 60, 0} // 1 min Hellstes Rot }; #define PRESET_COUNT (sizeof(presets)/sizeof(presets[0])) @@ -42,7 +43,7 @@ static bool led_on = false; static uint64_t last_toggle_ms = 0; static uint64_t phase_start_ms = 0; -static void hsv2rgb(uint32_t h, uint32_t s, uint32_t v, uint32_t *r, uint32_t *g, uint32_t *b) { +static void hsv2rgb(uint32_t h, uint32_t s, uint32_t v, uint32_t *r, uint32_t *g, uint32_t *b){ h %= 360; uint32_t rgb_max = v * 255 / 100; uint32_t rgb_min = rgb_max * (100 - s) / 100; @@ -59,11 +60,11 @@ static void hsv2rgb(uint32_t h, uint32_t s, uint32_t v, uint32_t *r, uint32_t *g } } -static void set_all_pixels(uint32_t r, uint32_t g, uint32_t b) { +static void set_all_pixels(uint32_t r, uint32_t g, uint32_t b){ for(int i=0;iname, p->freq_hz, p->duration_min); + ESP_LOGI(TAG,"Preset %d %s %dHz %ds", idx, p->name, p->freq_hz, p->duration_sec); } static void stop_leds(void){ current_preset = -1; memset(led_pixels,0,sizeof(led_pixels)); flush_leds(); - ESP_LOGI(TAG,"LEDs stopped"); -} - -static void list_presets(void){ - printf("\n--- Presets ---\n"); - for(int i=0;iname, p->freq_hz, p->duration_min); - } - printf("Commands: 0-6 select, next, stop, list\n"); -} - -static void process_line(char *line){ - if(strcmp(line,"stop")==0){ stop_leds(); return; } - if(strcmp(line,"next")==0){ - int nxt = (current_preset+1)%PRESET_COUNT; - apply_preset(nxt); - return; - } - if(strcmp(line,"list")==0){ list_presets(); return; } - if(strlen(line)==1 && line[0]>='0' && line[0]<='6'){ - int idx = line[0]-'0'; - if(idx 0){ - uint8_t c; - int len = uart_read_bytes(UART_NUM_0,&c,1,0); - if(len>0){ - if(c=='\r' || c=='\n'){ - line_buf[line_pos]='\0'; - if(line_pos>0){ process_line(line_buf); } - line_pos=0; - }else{ - if(line_pos < (int)sizeof(line_buf)-1){ line_buf[line_pos++]=c; } - } - } - } - if(current_preset>=0){ const preset_t *p=&presets[current_preset]; - uint64_t now = esp_timer_get_time()/1000; - uint64_t period_ms = 1000 / p->freq_hz; + uint64_t now=esp_timer_get_time()/1000; + uint64_t period_ms = p->freq_hz>0 ? 1000/p->freq_hz : 1000; uint64_t half = period_ms/2; if(half<1) half=1; if(now - last_toggle_ms >= half){ - led_on = !led_on; - last_toggle_ms = now; + led_on=!led_on; + last_toggle_ms=now; if(led_on){ uint32_t r,g,b; hsv2rgb(p->hue,100,100,&r,&g,&b); @@ -187,14 +131,15 @@ void app_main(void){ } flush_leds(); } - // Auto-weiter zur nächsten Phase nach Ablauf der Dauer uint64_t elapsed_ms = now - phase_start_ms; - if(elapsed_ms >= (uint64_t)p->duration_min * 60 * 1000){ - if(current_preset + 1 < PRESET_COUNT){ - apply_preset(current_preset + 1); + if(elapsed_ms >= (uint64_t)p->duration_sec * 1000){ + if(current_preset+1 < PRESET_COUNT){ + apply_preset(current_preset+1); }else{ stop_leds(); - ESP_LOGI(TAG,"25-Minuten Programm beendet"); + ESP_LOGI(TAG,"Programm beendet"); + vTaskDelay(pdMS_TO_TICKS(2000)); + apply_preset(0); } } }