/*
Copyright (c):
Philipp Matthias Schäfer (philipp.matthias.schaefer@posteo.de), 2020
This file is part of the KrautStatus' Arduino code.
The Clean CommonMark library is free software: you can redistribute it and/or
modify it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
The Clean CommonMark library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
for more details.
You should have received a copy of the GNU Affero General Public License along
with the Clean CommonMark library. If not, see .
*/
#include
#include
#include
#include "matrix.h"
const uint32_t RED = COLOR(255, 0, 0);
const uint32_t YELLOW = COLOR(255, 255, 0);
const unsigned long int SCAN_UPDATE_FREQUENCY = 25;
void matrix_setup() {
MATRIX.begin();
}
void matrix_show_failure() {
MATRIX.stroke(RED);
MATRIX.beginDraw();
MATRIX.clear();
MATRIX.line(0, 0, MATRIX.width() - 1, MATRIX.height() - 1);
MATRIX.line(0, MATRIX.height() - 1, MATRIX.width() - 1, 0);
MATRIX.endDraw();
}
uint8_t scan_timer = 0;
void matrix_paint_scan() {
// We paint a vertical line that oscillates between the left and right border
// of the matrix. Going back and forth one pixel at a time gives us as period
// of
// 2 * width - 2
// because we do not want to remain at the borders for one tick.
scan_timer += 1;
scan_timer %= 2 * MATRIX.width() - 2;
uint8_t position = scan_timer;
if(position >= MATRIX.width())
position = 2 * MATRIX.width() - position - 2;
MATRIX.beginDraw();
MATRIX.clear();
MATRIX.line(position, 0, position, 6);
MATRIX.endDraw();
}
bool matrix_show_scan_and_run(bool(*thunk)()) {
MATRIX.stroke(YELLOW);
TimerLib.setInterval_us(matrix_paint_scan, 1000000 / SCAN_UPDATE_FREQUENCY);
bool result = thunk();
TimerLib.clearTimer();
MATRIX.beginDraw();
MATRIX.clear();
MATRIX.endDraw();
return result;
}
void matrix_fill(uint32_t color) {
MATRIX.fill(color);
MATRIX.beginDraw();
MATRIX.clear();
MATRIX.endDraw();
}