pitrix/src/effect_big_clock.cpp

44 lines
1.2 KiB
C++
Raw Normal View History

#include "Effect.h"
#include "effect_big_clock.h"
#include "text.h"
#include "functions.h"
#include "ntp.h"
void BigClockEffect::drawNumber(uint8_t number, int x, int y, CRGB color) {
2019-06-07 04:24:16 +00:00
char buffer[7];
sprintf(buffer, "%02d", number);
drawText(buffer, x, y, color);
}
void BigClockEffect::drawText(char *text, int x, int y, CRGB color) {
2019-06-07 04:24:16 +00:00
for (uint8_t i = 0; i < strlen(text); i++) {
drawSprite(font_char(numbers4x7, text[i]), x + i * 4, y, color);
}
}
2019-06-06 04:42:00 +00:00
const unsigned char* BigClockEffect::font_char(const unsigned char* font, char c) {
2019-06-07 04:24:16 +00:00
return font + (c - 48) * 4;
}
2019-06-06 04:42:00 +00:00
void BigClockEffect::drawSprite(const unsigned char* sprite, int xOffset, int yOffset, CRGB color) {
2019-06-07 04:24:16 +00:00
for ( byte y = 0; y < 7; y++) {
for ( byte x = 0; x < 4; x++) {
bool on = (sprite[x] >> y & 1) * 255;
if (on) {
leds[ XYsafe(x + xOffset, y + yOffset) ] = color;
}
}
}
}
void BigClockEffect::loop() {
2019-06-07 04:24:16 +00:00
clear();
drawNumber(ntpClient.getHours(), 0, 0, color_h);
drawNumber(ntpClient.getMinutes(), 8, 0, color_m);
/*if (ntpClient.getSeconds() & 1) {
leds[XYsafe(13, 2)] = color_colon;
leds[XYsafe(13, 5)] = color_colon;
2019-06-07 04:24:16 +00:00
}*/
drawNumber(ntpClient.getSeconds(), 8, 8, color_colon);
}