You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

219 lines
5.2 KiB

#include <ViewStates.h>
ViewTimeState::ViewTimeState(DS3231 &_ds3231, AT24C32 &_at24c32)
{
ds3231 = _ds3231;
at24c32 = _at24c32;
init();
}
/*
default german matrix layout
'E', 'S', 'K', 'I', 'S', 'T', 'L', 'F', 'Ü', 'N', 'F',
'Z', 'E', 'H', 'N', 'Z', 'W', 'A', 'N', 'Z', 'I', 'G',
'D', 'R', 'E', 'I', 'V', 'I', 'E', 'R', 'T', 'E', 'L',
'T', 'A', 'N', 'A', 'C', 'H', 'V', 'O', 'R', 'J', 'M',
'H', 'A', 'L', 'B', 'X', 'Z', 'W', 'Ö', 'L', 'F', 'P',
'Z', 'W', 'E', 'I', 'N', 'S', 'I', 'E', 'B', 'E', 'N',
'K', 'D', 'R', 'E', 'I', 'R', 'H', 'F', 'Ü', 'N', 'F',
'E', 'L', 'F', 'N', 'E', 'U', 'N', 'V', 'I', 'E', 'R',
'W', 'A', 'C', 'H', 'T', 'Z', 'E', 'H', 'N', 'R', 'S',
'B', 'S', 'E', 'C', 'H', 'S', 'F', 'M', 'U', 'H', 'R',
'B', 'S', 'E', 'C', 'H', 'S', 'F', 'M', 'U', 'H', 'R',
'□', '□', '□', '□', '▣', '□', '□', '□', '□', '□', '□',
*/
void ViewTimeState::init()
{
text[0] = {0, 0, 1, true};
text[1] = {0, 3, 5, true};
hours[0][0] = {4, 5, 9, true};
hours[0][1] = {0, 0, 0, false};
hours[1][0] = {5, 2, 4, true};
hours[1][1] = {5, 2, 5, true};
hours[2][0] = {5, 0, 3, true};
hours[2][1] = {0, 0, 0, false};
hours[3][0] = {6, 1, 4, true};
hours[3][1] = {0, 0, 0, false};
hours[4][0] = {7, 7, 10, true};
hours[4][1] = {0, 0, 0, false};
hours[5][0] = {6, 7, 10, true};
hours[5][1] = {0, 0, 0, false};
hours[6][0] = {9, 1, 5, true};
hours[6][1] = {0, 0, 0, false};
hours[7][0] = {5, 5, 10, true};
hours[7][1] = {0, 0, 0, false};
hours[8][0] = {8, 1, 4, true};
hours[8][1] = {0, 0, 0, false};
hours[9][0] = {7, 3, 6, true};
hours[9][1] = {0, 0, 0, false};
hours[10][0] = {8, 5, 8, true};
hours[10][1] = {0, 0, 0, false};
hours[11][0] = {7, 0, 2, true};
hours[11][1] = {0, 0, 0, false};
// 0
minutes[0][0] = {9, 8, 10, true};
minutes[0][1] = {0, 0, 0, false};
minutes[0][2] = {0, 0, 0, false};
// 5
minutes[1][0] = {0, 7, 10, true};
minutes[1][1] = {3, 2, 5, true};
minutes[1][2] = {0, 0, 0, false};
// 10
minutes[2][0] = {1, 0, 3, true};
minutes[2][1] = {3, 2, 5, true};
minutes[2][2] = {0, 0, 0, false};
// 15
minutes[3][0] = {2, 4, 10, true};
minutes[3][1] = {3, 2, 5, true};
minutes[3][2] = {0, 0, 0, false};
// 20
minutes[4][0] = {1, 4, 10, true};
minutes[4][1] = {3, 2, 5, true};
minutes[4][2] = {0, 0, 0, false};
// 25
minutes[5][0] = {0, 7, 10, true};
minutes[5][1] = {3, 6, 8, true};
minutes[5][2] = {4, 0, 3, true};
// 30
minutes[6][0] = {4, 0, 3, true};
minutes[6][1] = {0, 0, 0, false};
minutes[6][2] = {0, 0, 0, false};
// 35
minutes[7][0] = {0, 7, 10, true};
minutes[7][1] = {3, 2, 5, true};
minutes[7][2] = {4, 0, 3, true};
// 40
minutes[8][0] = {1, 4, 10, true};
minutes[8][1] = {3, 6, 8, true};
minutes[8][2] = {0, 0, 0, false};
// 45
minutes[9][0] = {2, 4, 10, true};
minutes[9][1] = {3, 6, 8, true};
minutes[9][2] = {0, 0, 0, false};
// 50
minutes[10][0] = {1, 0, 3, true};
minutes[10][1] = {3, 6, 8, true};
minutes[10][2] = {0, 0, 0, false};
// 55
minutes[11][0] = {0, 7, 10, true};
minutes[11][1] = {3, 6, 8, true};
minutes[11][2] = {0, 0, 0, false};
increment = 24;
}
void ViewTimeState::setWessi()
{
init();
minutes[4][0] = {1, 0, 3, true};
minutes[4][1] = {3, 6, 8, true};
minutes[4][2] = {4, 0, 3, true};
minutes[8][0] = {1, 0, 3, true};
minutes[8][1] = {3, 2, 5, true};
minutes[8][2] = {4, 0, 3, true};
increment = 19;
}
void ViewTimeState::setOssi()
{
setWessi();
minutes[3][0] = {2, 4, 10, true};
minutes[3][1] = {0, 0, 0, false};
minutes[9][0] = {2, 0, 10, true};
minutes[9][1] = {0, 0, 0, false};
increment = 14;
}
void ViewTimeState::setWord(uint8_t matrix[121], matrix_entry word)
{
int row;
for (int i = word.columnFrom; i <= word.columnTo; i++)
{
row = word.row * 11 + i;
matrix[row] = color;
}
}
void ViewTimeState::render(uint8_t matrix[121], ControlStates controlState)
{
uint8_t currentMode = at24c32.read(TIME_MODE_ADDRESS);
if (mode != currentMode)
{
mode = currentMode;
switch (mode)
{
case 1:
setWessi();
break;
case 2:
setOssi();
break;
default:
init();
}
}
bool const blink = (millis() / CONTROL_BLINK_INTERVAL) % 2 == 0;
if (controlState != ControlStates::TIME_MODE || blink)
{
setWord(matrix, text[0]);
setWord(matrix, text[1]);
}
uint8_t mm = ds3231.getMinutes();
uint8_t m = mm / 5;
uint8_t h = ds3231.getHours() % 12;
uint8_t s = ds3231.getSeconds();
// increment hours
if (mm > increment)
{
h = (h + 1) % 12;
}
// set hours
if (controlState != ControlStates::TIME_HOURS || blink)
{
setWord(matrix, hours[h][0]);
if (mm >= 5 && hours[h][1].notNull == true)
{
setWord(matrix, hours[h][1]);
}
}
// set 5 minutes
if (controlState != ControlStates::TIME_MINUTES || blink)
{
for (int i = 0; i < 3; i++)
{
if (minutes[m][i].notNull == true)
{
setWord(matrix, minutes[m][i]);
}
}
}
// set minutes
if (mm % 5 > 0)
{
if (controlState != ControlStates::TIME_MINUTES || blink)
{
setWord(matrix, {10, 0, mm % 5 - 1});
}
}
// set seconds
setWord(matrix, {10, 5, 5 + (s / 10)});
}