diff --git a/main/ledstrip.c b/main/ledstrip.c --- a/main/ledstrip.c +++ b/main/ledstrip.c @@ -5,79 +5,82 @@ #include "esp_log.h" #include "esp_err.h" -#define LED_STRIP_BLINK_GPIO 11 -#define LED_STRIP_LED_NUMBERS 120 -#define LED_STRIP_RMT_RES_HZ (10 * 1000 * 1000) +// Settings +#define LED_STRIP_GPIO 11 +#define LED_STRIP_NUM_LEDS 120 +#define LED_STRIP_RMT_FREQ_HZ (10 * 1000 * 1000) static const char *TAG = "ledstrip"; -led_strip_handle_t configure_led(void) +// Private Prototypes +static uint8_t strip0_loop0func(); +static uint8_t strip0_loop0_eff0(); + + +// Private variables +static led_strip_handle_t led_strip; + + +// Initialize WS2812 strip +void ledstrip_init(void) { // LED strip general initialization, according to your led board design led_strip_config_t strip_config = { - .strip_gpio_num = LED_STRIP_BLINK_GPIO, // The GPIO that connected to the LED strip's data line - .max_leds = LED_STRIP_LED_NUMBERS, // The number of LEDs in the strip, - .led_pixel_format = LED_PIXEL_FORMAT_GRB, // Pixel format of your LED strip - .led_model = LED_MODEL_WS2812, // LED strip model - .flags.invert_out = false, // whether to invert the output signal + .strip_gpio_num = LED_STRIP_GPIO, + .max_leds = LED_STRIP_NUM_LEDS, + .led_pixel_format = LED_PIXEL_FORMAT_GRB, + .led_model = LED_MODEL_WS2812, + .flags.invert_out = false, }; // LED strip backend configuration: RMT led_strip_rmt_config_t rmt_config = { -#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) - .rmt_channel = 0, -#else - .clk_src = RMT_CLK_SRC_DEFAULT, // different clock source can lead to different power consumption - .resolution_hz = LED_STRIP_RMT_RES_HZ, // RMT counter clock frequency - .flags.with_dma = false, // DMA feature is available on ESP target like ESP32-S3 -#endif + .clk_src = RMT_CLK_SRC_DEFAULT, + .resolution_hz = LED_STRIP_RMT_FREQ_HZ, + .flags.with_dma = true, // DMA feature is available on ESP target like ESP32-S3 }; // LED Strip object handle - led_strip_handle_t led_strip; ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &led_strip)); ESP_LOGI(TAG, "Created LED strip object with RMT backend"); - return led_strip; } -led_strip_handle_t led_strip; - -void ledstrip_init(void) -{ - led_strip = configure_led(); - bool led_on_off = false; -} - +// From OSC for testing static float modifier = 0.0; void ledstrip_set_modifier(float frac) { modifier = frac; } + +// Set entire strip to RGB value void ledstrip_set(uint32_t r, uint32_t g, uint32_t b) { - ESP_LOGI(TAG, "Led set!"); - - - for (int i = 0; i < LED_STRIP_LED_NUMBERS; i++) { + for (int i = 0; i < LED_STRIP_NUM_LEDS; i++) { ESP_ERROR_CHECK(led_strip_set_pixel(led_strip, i, r, g, b)); } led_strip_refresh(led_strip); } +// Run effect and refresh strip +void ledstrip_refresh(void) +{ + if(strip0_loop0func() & 0x01) + led_strip_refresh(led_strip); +} -uint8_t effect = -1; -uint8_t effects = 120; -uint16_t effStep; -unsigned long effStart; +static uint8_t effect = -1; +static uint8_t effects = 120; +static uint16_t effStep; +static unsigned long effStart; -void __reset(void) +static void __reset(void) { effStep = 0; effect = (effect + 1) % effects; @@ -91,8 +94,6 @@ typedef struct Loop bool timeBased; uint16_t cycles; uint16_t currentTime; - //Loop(uint8_t totchilds, bool timebased, uint16_t tottime) -// {currentTime=0;currentChild=0;childs=totchilds;timeBased=timebased;cycles=tottime;} } loop_t; loop_t strip0loop0 = @@ -104,18 +105,10 @@ loop_t strip0loop0 = .cycles = 1, }; -//proto -uint8_t strip0_loop0func(); -uint8_t strip0_loop0_eff0(); -void ledstrip_refresh(void) -{ - if(strip0_loop0func() & 0x01) - led_strip_refresh(led_strip); -} -uint8_t strip0_loop0func() { +static uint8_t strip0_loop0func() { uint8_t ret = 0x00; switch(strip0loop0.currentChild) { case 0: @@ -134,7 +127,8 @@ uint8_t strip0_loop0func() { return ret; } -uint8_t strip0_loop0_eff0() { + +static uint8_t strip0_loop0_eff0() { // Strip ID: 0 - Effect: Rainbow - LEDS: 120 // Steps: 60 - Delay: 20 // Colors: 3 (255.0.0, 0.255.0, 0.0.255)