wordclock/libraries/States/ViewLEDState.cpp

76 lines
1.6 KiB
C++
Raw Normal View History

2019-02-13 19:27:22 +01:00
#include <ViewStates.h>
ViewLEDState::ViewLEDState(){
};
void ViewLEDState::render(uint8_t matrix[121], ControlStates controlState)
{
if (controlState != ControlStates::COLOR_R && controlState != ControlStates::COLOR_G && controlState != ControlStates::COLOR_B)
{
int const color = (millis() / 500) % 256;
for (int i = 0; i < 121; i++)
{
matrix[i] = color - i % 256;
}
}
else
{
// special color edit view
bool const blink = (millis() / CONTROL_BLINK_INTERVAL) % 2 == 0;
if (controlState != ControlStates::COLOR_R || blink)
{
uint8_t red = color >> 5;
matrix[0] = 0x07 << 5;
matrix[10] = 0x07 << 5;
matrix[11] = 0x07 << 5;
matrix[21] = 0x07 << 5;
for (int i = 0; i < red; i++)
{
// red
matrix[i + 2] = red << 5;
matrix[i + 13] = red << 5;
}
}
if (controlState != ControlStates::COLOR_G || blink)
{
uint8_t green = (color >> 2) & 0x07;
matrix[22] = 0x07 << 2;
matrix[32] = 0x07 << 2;
matrix[33] = 0x07 << 2;
matrix[43] = 0x07 << 2;
for (int i = 0; i < green; i++)
{
// green
matrix[i + 24] = green << 2;
matrix[i + 35] = green << 2;
}
}
if (controlState != ControlStates::COLOR_B || blink)
{
uint8_t blue = color & 0x03;
matrix[44] = 0x03;
matrix[54] = 0x03;
matrix[55] = 0x03;
matrix[65] = 0x03;
for (int i = 0; i < blue; i++)
{
// blue
matrix[i + 46] = blue;
matrix[i + 57] = blue;
}
}
for (int i = 77; i < 121; i++)
{
matrix[i] = color;
}
}
}