Fix phase durations & colors for 9-phase relaxation, use duration_sec and red hues
This commit is contained in:
+23
-78
@@ -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]))
|
||||
|
||||
@@ -61,9 +62,9 @@ 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){
|
||||
for(int i=0;i<LED_NUMBERS;i++){
|
||||
led_pixels[i*3+0]= (uint8_t)g;
|
||||
led_pixels[i*3+1]= (uint8_t)b;
|
||||
led_pixels[i*3+2]= (uint8_t)r;
|
||||
led_pixels[i*3+0]=(uint8_t)g; // G
|
||||
led_pixels[i*3+1]=(uint8_t)r; // R
|
||||
led_pixels[i*3+2]=(uint8_t)b; // B
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,60 +84,23 @@ static void apply_preset(int idx){
|
||||
led_on = true;
|
||||
last_toggle_ms = esp_timer_get_time()/1000;
|
||||
phase_start_ms = esp_timer_get_time()/1000;
|
||||
ESP_LOGI(TAG, "Preset %d %s %dHz %dmin", idx, p->name, 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;i<PRESET_COUNT;i++){
|
||||
const preset_t *p=&presets[i];
|
||||
printf("%d - %s %dHz %dmin\n", i, p->name, 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<PRESET_COUNT){ apply_preset(idx); return; }
|
||||
}
|
||||
printf("Unknown: %s\n", line);
|
||||
}
|
||||
|
||||
void app_main(void){
|
||||
ESP_LOGI(TAG,"LED Laser Frequenz start");
|
||||
|
||||
uart_config_t uart_cfg = {
|
||||
.baud_rate = 115200,
|
||||
.data_bits = UART_DATA_8_BITS,
|
||||
.parity = UART_PARITY_DISABLE,
|
||||
.stop_bits = UART_STOP_BITS_1,
|
||||
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE
|
||||
};
|
||||
uart_config_t uart_cfg = {.baud_rate=115200,.data_bits=UART_DATA_8_BITS,.parity=UART_PARITY_DISABLE,.stop_bits=UART_STOP_BITS_1,.flow_ctrl=UART_HW_FLOWCTRL_DISABLE};
|
||||
ESP_ERROR_CHECK(uart_driver_install(UART_NUM_0,1024,0,0,NULL,0));
|
||||
ESP_ERROR_CHECK(uart_param_config(UART_NUM_0,&uart_cfg));
|
||||
|
||||
rmt_tx_channel_config_t tx_cfg = {
|
||||
.clk_src = RMT_CLK_SRC_DEFAULT,
|
||||
.gpio_num = LED_GPIO_NUM,
|
||||
.mem_block_symbols = 64,
|
||||
.resolution_hz = RMT_LED_STRIP_RESOLUTION_HZ,
|
||||
.trans_queue_depth = 4
|
||||
};
|
||||
rmt_tx_channel_config_t tx_cfg = {.clk_src=RMT_CLK_SRC_DEFAULT,.gpio_num=LED_GPIO_NUM,.mem_block_symbols=64,.resolution_hz=RMT_LED_STRIP_RESOLUTION_HZ,.trans_queue_depth=4};
|
||||
ESP_ERROR_CHECK(rmt_new_tx_channel(&tx_cfg,&led_chan));
|
||||
led_strip_encoder_config_t enc_cfg={.resolution=RMT_LED_STRIP_RESOLUTION_HZ};
|
||||
ESP_ERROR_CHECK(rmt_new_led_strip_encoder(&enc_cfg,&led_encoder));
|
||||
@@ -145,34 +109,14 @@ void app_main(void){
|
||||
memset(led_pixels,0,sizeof(led_pixels));
|
||||
flush_leds();
|
||||
|
||||
// Auto-Start des 25-Minuten Entspannungsprogramms beim Einschalten
|
||||
apply_preset(0);
|
||||
ESP_LOGI(TAG,"Auto-Start: Relaxation Programm gestartet (Pin D10/GPIO18)");
|
||||
|
||||
char line_buf[64];
|
||||
int line_pos=0;
|
||||
ESP_LOGI(TAG,"Auto-Start Pin D10/GPIO18");
|
||||
|
||||
while(1){
|
||||
size_t buffered = 0;
|
||||
uart_get_buffered_data_len(UART_NUM_0, &buffered);
|
||||
while(buffered > 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 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){
|
||||
@@ -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(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user