#include ViewTextState::ViewTextState(AT24C32 &_at24c32) { at24c32 = _at24c32; renderOffset = (millis() / TEXT_INTERVAL); }; void ViewTextState::render(uint8_t matrix[121], ControlStates controlState) { length = at24c32.read(TEXT_SIZE_ADDRESS); if (controlState != ControlStates::TEXT) { for (uint8_t i = 0; i < length; i++) { text[i] = at24c32.read(TEXT_ADDRESS + i); } writeText(matrix); } else { bool const blink = (millis() / CONTROL_BLINK_INTERVAL) % 2 == 0; position = 0; text[0] = 0x20; text[1] = 0x20; if (length > 2) { text[0] = at24c32.read(TEXT_ADDRESS + length - 2); if (blink) { text[1] = at24c32.read(TEXT_ADDRESS + length - 1); } } else if (length > 1 && blink) { text[0] = at24c32.read(TEXT_ADDRESS + length - 1); } writeChars(matrix); } } void ViewTextState::writeText(uint8_t matrix[121]) { position = (millis() / TEXT_INTERVAL - renderOffset - 1) % (length + 2); writeChars(matrix); } void ViewTextState::writeChars(uint8_t matrix[121]) { uint8_t char1 = 0x20; uint8_t char2 = 0x20; if (length > position) { char1 = text[position]; } if (length > position + 1) { char2 = text[position + 1]; } for (int col = 0; col < 5; col++) { // created ascii chars in 'ascii_memory.ino' to AT23C32 epromm uint8_t char1Byte = at24c32.read(char1 * 5 + col); uint8_t char2Byte = at24c32.read(char2 * 5 + col); for (int row = 0; row < 8; row++) { if (!!(char1Byte & (1 << row))) { matrix[(row + v_offset) * 11 + col] = color; } if (!!(char2Byte & (1 << row))) { matrix[(row + v_offset) * 11 + col + 6] = color; } } } }