diff --git a/main/ledstrip.c b/main/ledstrip.c --- a/main/ledstrip.c +++ b/main/ledstrip.c @@ -4,23 +4,26 @@ #include "led_strip.h" #include "esp_log.h" #include "esp_err.h" +#include "ledstrip.h" +#include "esp_log.h" + // Settings #define LED_STRIP_GPIO 11 -#define LED_STRIP_NUM_LEDS 120 +#define LED_STRIP_NUM_LEDS 150 #define LED_STRIP_RMT_FREQ_HZ (10 * 1000 * 1000) static const char *TAG = "ledstrip"; // Private Prototypes -static uint8_t strip0_loop0func(); -static uint8_t strip0_loop0_eff0(); +static uint8_t process_effect_rainbow(); +static uint8_t process_effect_singlechase(); // Private variables static led_strip_handle_t led_strip; - +static effect_t current_effect = EFFECT_NONE; // Initialize WS2812 strip void ledstrip_init(void) @@ -55,6 +58,12 @@ void ledstrip_set_modifier(float frac) } +void ledstrip_set_effect(effect_t effect) +{ + current_effect = effect; +} + + // Set entire strip to RGB value void ledstrip_set(uint32_t r, uint32_t g, uint32_t b) { @@ -64,17 +73,41 @@ void ledstrip_set(uint32_t r, uint32_t g led_strip_refresh(led_strip); } - // Run effect and refresh strip void ledstrip_refresh(void) { - if(strip0_loop0func() & 0x01) - led_strip_refresh(led_strip); + switch(current_effect) + { + + case EFFECT_RAINBOW: + { + if(process_effect_rainbow() & 0x01) + led_strip_refresh(led_strip); + } break; + + case EFFECT_SINGLECHASE: + { + if(process_effect_singlechase() & 0x01) + led_strip_refresh(led_strip); + } break; + + case EFFECT_NONE: + default: + { + ledstrip_set(10,10,10); + led_strip_refresh(led_strip); + } break; + } } + + + + + static uint8_t effect = -1; static uint8_t effects = 120; static uint16_t effStep; @@ -87,48 +120,9 @@ static void __reset(void) effStart = xTaskGetTickCount() * portTICK_PERIOD_MS; } -typedef struct Loop -{ - uint8_t currentChild; - uint8_t childs; - bool timeBased; - uint16_t cycles; - uint16_t currentTime; -} loop_t; - -loop_t strip0loop0 = -{ - .currentTime = 0, - .currentChild = 0, - .childs = 1, - .timeBased = false, - .cycles = 1, -}; - - -static uint8_t strip0_loop0func() { - uint8_t ret = 0x00; - switch(strip0loop0.currentChild) { - case 0: - ret = strip0_loop0_eff0();break; - } - if(ret & 0x02) { - ret &= 0xfd; - if(strip0loop0.currentChild + 1 >= strip0loop0.childs) { - strip0loop0.currentChild = 0; - if(++strip0loop0.currentTime >= strip0loop0.cycles) {strip0loop0.currentTime = 0; ret |= 0x02;} - } - else { - strip0loop0.currentChild++; - } - }; - return ret; -} - - -static uint8_t strip0_loop0_eff0() { +static uint8_t process_effect_rainbow() { // Strip ID: 0 - Effect: Rainbow - LEDS: 120 // Steps: 60 - Delay: 20 // Colors: 3 (255.0.0, 0.255.0, 0.0.255) @@ -136,7 +130,7 @@ static uint8_t strip0_loop0_eff0() { if((xTaskGetTickCount() * portTICK_PERIOD_MS) - effStart < 20 * (effStep)) return 0x00; float factor1, factor2; uint16_t ind; - for(uint16_t j=0;j<120;j++) { + for(uint16_t j=0;j