infinityledclock/vscode/infclock/src/led_clockelements.cpp

107 lines
3.7 KiB
C++

#include "led_clockelements.hpp"
void elements::init(CRGB *pixels, unsigned int first_led, unsigned int number_leds, hue_color huecolor, bool outside2inside)
{
element_pixels = pixels;
element_first_pixel = first_led;
element_number_pixels = number_leds;
element_last_pixel = first_led + number_leds - 1;
element_outside2inside = outside2inside;
elements_huecolor = huecolor;
//Serial.printf("Init pixels - first:%d last:%d number:%d outsidetoinside:%d\n", element_first_pixel, element_last_pixel, element_number_pixels, element_outside2inside);
}
void elements::show(void)
{
FastLED.show();
delay(FASTLEDDLY);
}
void elements::clean(void)
{
fill(0, 0, 0);
}
void elements::test(bool all_at_once)
{
test(elements_huecolor.hue, elements_huecolor.sat, elements_huecolor.bright, all_at_once);
}
void elements::test(hue_color huecolor, bool all_at_once)
{
test(huecolor.hue, huecolor.sat, huecolor.bright, all_at_once);
}
void elements::test(uint8_t huecolor, uint8_t saturation, uint8_t brightness, bool all_at_once)
{
unsigned int setpix = element_outside2inside == true? element_last_pixel: element_first_pixel ;
char plus_minus = element_outside2inside == true? -1:1;
for(unsigned int nrpixel = 0; nrpixel < element_number_pixels; nrpixel++)
{
element_pixels[setpix] = CHSV(huecolor,saturation, brightness);
setpix = setpix + plus_minus;
if( all_at_once == false)
{
show();
}
}
if( all_at_once == true)
{
show();
}
delay(100);
clean();
show();
}
void elements::fill(void)
{
fill(elements_huecolor.hue, elements_huecolor.sat, elements_huecolor.bright);
}
void elements::fill(hue_color huecolor)
{
fill(huecolor.hue, huecolor.sat, huecolor.bright);
}
void elements::fill(uint8_t huecolor, uint8_t saturation, uint8_t brightness)
{
for(unsigned int nrpixel = element_first_pixel; nrpixel <= element_last_pixel; nrpixel++)
{
element_pixels[nrpixel] = CHSV(huecolor,saturation, brightness);
}
}
void elements::ffill(unsigned int fraction, unsigned int fullvalue)
{
ffill(fraction, fullvalue, elements_huecolor.hue, elements_huecolor.sat, elements_huecolor.bright);
}
void elements::ffill(unsigned int fraction, unsigned int fullvalue, hue_color huecolor)
{
ffill(fraction, fullvalue, huecolor.hue, huecolor.sat, huecolor.bright);
}
void elements::ffill(unsigned int fraction, unsigned int fullvalue, uint8_t huecolor, uint8_t saturation, uint8_t brightness)
{
unsigned int value_of_pixel = fullvalue / element_number_pixels; //this is what part one pixel of the element represents of the full value
unsigned int fullpixels = fraction / value_of_pixel; //the number of pixels that represents the fraction (part of the fullvalue)
unsigned int partialpixel = fraction % value_of_pixel; //the left over of the division of fraction and value of one pixel
uint8_t partial_brightness = (uint8_t)((brightness/element_number_pixels)*partialpixel);
unsigned int current_pixel = 0;
for(unsigned int num = 0; num < fullpixels; num++)
{
current_pixel = element_outside2inside==true? element_last_pixel - num : element_first_pixel + num;
element_pixels[current_pixel] = CHSV(huecolor,saturation, brightness);
}
if(partialpixel > 0)
{
current_pixel = element_outside2inside==true? element_last_pixel - fullpixels : element_first_pixel + fullpixels;
element_pixels[current_pixel] = CHSV(huecolor,saturation, partial_brightness);
}
}