#include "clockelements.hpp"

void elements::init(Adafruit_NeoPixel *pixels, unsigned int first_led, unsigned int number_leds, bool outside2inside)
{
    element_pixels = pixels;
    element_first_pixel = first_led;
    element_number_pixels = number_leds;
    element_last_pixel = first_led + number_leds;
    element_outside2inside = outside2inside;
}

void elements::clean(void)
{
    fill(0, 0, 0);
}

void elements::fill(uint16_t huecolor, uint8_t saturation, uint8_t brightness)
{
    for(unsigned int nrpixel = element_first_pixel; nrpixel < element_last_pixel; nrpixel++)
    {
        element_pixels->setPixelColor(nrpixel, element_pixels->ColorHSV(huecolor,saturation, brightness));
    }
}

void elements::ffill(uint16_t huecolor, unsigned int fraction, uint8_t saturation, uint8_t brightness)
{
    unsigned int fullpixels = element_number_pixels / fraction;
    unsigned int partpixels = element_number_pixels % fraction;
    elements_fraction = brightness / (60/element_number_pixels);
    unsigned int part_brightness = elements_fraction * partpixels;

    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->setPixelColor(current_pixel,element_pixels->ColorHSV(huecolor,saturation, brightness));
    }

    if(partpixels > 0)
    {
        current_pixel = element_outside2inside==true? element_last_pixel - fullpixels : element_first_pixel + fullpixels;
        element_pixels->setPixelColor(current_pixel,element_pixels->ColorHSV(huecolor,saturation, part_brightness));
    }

}

