move functions to shared lib
This commit is contained in:
parent
07409625a0
commit
e313f5170f
2 changed files with 117 additions and 0 deletions
87
ESblinkt.cpp
Normal file
87
ESblinkt.cpp
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
#include "ESblinkt.hpp"
|
||||
|
||||
struct RgbColor color_wheel(uint8_t pos)
|
||||
{
|
||||
uint16_t p = (uint8_t)pos;
|
||||
|
||||
if (p < 85)
|
||||
{
|
||||
return RgbColor((uint8_t)(255 - p * 3), (uint8_t)(p * 3), (uint8_t)0);
|
||||
}
|
||||
else if (p < 170)
|
||||
{
|
||||
p -= 85;
|
||||
return RgbColor((uint8_t)0, (uint8_t)(255 - p * 3), (uint8_t)(p * 3));
|
||||
}
|
||||
else
|
||||
{
|
||||
p -= 170;
|
||||
return RgbColor((uint8_t)(p * 3), (uint8_t)0, (uint8_t)(255 - p * 3));
|
||||
}
|
||||
}
|
||||
|
||||
void fill_rainbow(uint8_t offset, struct strip leds)
|
||||
{
|
||||
uint16_t color_index = 0;
|
||||
for (uint16_t i = 0; i < leds.pixelCount; i++)
|
||||
{
|
||||
color_index = (i + (uint16_t)offset) % 256;
|
||||
leds.setPixelColor(i, color_wheel(color_index));
|
||||
}
|
||||
}
|
||||
|
||||
void fill_solid(struct RgbColor color, struct strip leds)
|
||||
{
|
||||
for (uint16_t i = 0; i < leds.pixelCount; i++)
|
||||
{
|
||||
leds.setPixelColor(i, color);
|
||||
}
|
||||
}
|
||||
|
||||
void rainbow(uint32_t rainbow_speed, struct strip leds)
|
||||
{
|
||||
for (int i = 0; i < 256; i++)
|
||||
{
|
||||
fill_rainbow(i, leds);
|
||||
leds.commit();
|
||||
vTaskDelay(rainbow_speed / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
void solid(struct RgbColor color, struct strip leds)
|
||||
{
|
||||
fill_solid(color, leds);
|
||||
leds.commit();
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
void three_sided(struct three_sided three_sided_config, struct strip leds)
|
||||
{
|
||||
uint32_t delay = 1000;
|
||||
uint8_t n = 1;
|
||||
|
||||
if (three_sided_config.anim)
|
||||
{
|
||||
delay = three_sided_config.speed;
|
||||
n = 3;
|
||||
}
|
||||
|
||||
for (int off = 0; off < n; off++)
|
||||
{
|
||||
|
||||
for (int j = 0; j < three_sided_config.endRight; j++)
|
||||
{
|
||||
leds.setPixelColor(j, three_sided_config.colors[(off) % 3]);
|
||||
}
|
||||
for (int j = three_sided_config.endRight; j < three_sided_config.endTop; j++)
|
||||
{
|
||||
leds.setPixelColor(j, three_sided_config.colors[(off + 1) % 3]);
|
||||
}
|
||||
for (int j = three_sided_config.endTop; j < leds.pixelCount; j++)
|
||||
{
|
||||
leds.setPixelColor(j, three_sided_config.colors[(off + 2) % 3]);
|
||||
}
|
||||
leds.commit();
|
||||
vTaskDelay(delay / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
30
ESblinkt.hpp
Normal file
30
ESblinkt.hpp
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#ifndef ESBLINKT_HPP
|
||||
#define ESBLINKT_HPP
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <NeoPixelBus.h>
|
||||
|
||||
struct RgbColor color_wheel(uint8_t pos);
|
||||
void fill_rainbow(uint8_t offset, struct strip leds);
|
||||
void fill_solid(struct RgbColor color, struct strip leds);
|
||||
void rainbow(struct strip leds);
|
||||
void solid(struct RgbColor color, struct strip leds);
|
||||
void three_sided(struct three_sided three_sided_config, struct strip leds);
|
||||
|
||||
struct strip
|
||||
{
|
||||
uint16_t pixelCount;
|
||||
void (*setPixelColor)(uint16_t, Neo3ByteElements::ColorObject);
|
||||
void (*commit)(void);
|
||||
};
|
||||
|
||||
struct three_sided
|
||||
{
|
||||
bool anim;
|
||||
uint32_t speed;
|
||||
uint16_t endRight;
|
||||
uint16_t endTop;
|
||||
struct RgbColor colors[3];
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Reference in a new issue