From 83254f2eaa0818d2954055bccf81c3394a27cdfc Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Tue, 11 Jun 2019 19:48:09 +0200 Subject: [PATCH] Windows. Everything now is implemented in Windows. ;-) (Okay, just the drawing stuff. And defnititely nothing by Microsoft.) --- include/Animation.h | 9 ++-- include/Effect.h | 6 +-- include/Window.h | 26 +++++++++++ include/effect_clock.h | 10 ++--- include/effect_snake.h | 1 - include/fonts.h | 5 +++ include/functions.h | 14 ------ include/prototypes.h | 16 +++---- src/Animation.cpp | 17 ++++---- src/Window.cpp | 62 ++++++++++++++++++++++++++ src/effect_animation.cpp | 2 +- src/effect_big_clock.cpp | 28 ++---------- src/effect_clock.cpp | 29 +++++++------ src/effect_confetti.cpp | 5 ++- src/effect_dynamic.cpp | 6 +-- src/effect_fire.cpp | 23 +++++----- src/effect_matrix.cpp | 16 ++++--- src/effect_sinematrix3.cpp | 3 +- src/effect_snake.cpp | 8 ++-- src/effect_static.cpp | 2 +- src/effect_twirl.cpp | 5 ++- include/text.h => src/fonts.cpp | 77 +++++++++++++++++---------------- src/functions.cpp | 43 ------------------ src/pitrix.cpp | 7 +-- src/text.cpp | 26 ----------- 25 files changed, 223 insertions(+), 223 deletions(-) create mode 100644 include/Window.h create mode 100644 include/fonts.h create mode 100644 src/Window.cpp rename include/text.h => src/fonts.cpp (87%) delete mode 100644 src/text.cpp diff --git a/include/Animation.h b/include/Animation.h index ab543be..2329841 100644 --- a/include/Animation.h +++ b/include/Animation.h @@ -34,6 +34,7 @@ it contains only one entry and .individual_delays will be false. #include #include "prototypes.h" #include "my_fastled.h" +#include "Window.h" class Animation { protected: @@ -50,8 +51,8 @@ protected: uint8_t endFrame; virtual CRGB* getColor(uint8_t color_index); - void drawFrame(uint8_t frame_index); - void drawPixel(int index, CRGB* color); + void drawFrame(Window* w, uint8_t frame_index); + void drawPixel(Window* w, int index, CRGB* color); uint16_t getFrameDelay(int frame); public: Animation(AnimationData* d); @@ -64,7 +65,7 @@ public: void setFrameRange(uint8_t sf, uint8_t ef); void setSingleFrame(uint8_t frame); virtual ~Animation(); - void draw(); - void drawFrame(); + void draw(Window* w); + void drawFrame(Window* w); virtual bool advance(); }; diff --git a/include/Effect.h b/include/Effect.h index 6e9af06..49620b4 100644 --- a/include/Effect.h +++ b/include/Effect.h @@ -1,19 +1,19 @@ #ifndef Effect_H #define Effect_H -#include "prototypes.h" +#include "Window.h" #include "config.h" #include class Effect { protected: - Window window = {0, 0, LED_WIDTH, LED_HEIGHT}; // Use a full screen window per default. + Window* window = Window::getFullWindow(); // Use a full screen window per default. public: virtual void loop() = 0; boolean supports_window = false; virtual boolean can_be_shown_with_clock() { return false; }; virtual boolean clock_as_mask() { return false; }; - void setWindow(Window win) { + void setWindow(Window* win) { window = win; }; virtual void start() {} diff --git a/include/Window.h b/include/Window.h new file mode 100644 index 0000000..dc37ddf --- /dev/null +++ b/include/Window.h @@ -0,0 +1,26 @@ +#pragma once +#include "my_fastled.h" +#include "config.h" +#include "prototypes.h" + +class Window { +public: + const uint8_t x, y; + const uint8_t width, height; + static Window* getFullWindow(); + + Window(): Window(0, 0, LED_WIDTH, LED_HEIGHT) {}; + Window(uint8_t x, uint8_t y) : Window(x, y, LED_WIDTH-x, LED_HEIGHT-y) {}; + Window(uint8_t x, uint8_t y, uint8_t width, uint8_t height) : x(x), y(y), width(width), height(height) {}; + + void clear(); + void clear(CRGB* color); + void setPixel(uint8_t x, uint8_t y, CRGB* color); + void setPixelByIndex(uint16_t index, CRGB* color); + void line(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, CRGB* color, bool antialias=false); + uint16_t coordsToGlobalIndex(uint8_t x, uint8_t y); + uint16_t localToGlobalIndex(uint16_t); + void drawChar(Font* f, uint8_t x, uint8_t y, const char c, CRGB* color, bool mask=false); + void addPixelColor(uint16_t index, CRGB* color); + void fadeToBlackBy(fract8 speed); +}; diff --git a/include/effect_clock.h b/include/effect_clock.h index 7417967..81b2b86 100644 --- a/include/effect_clock.h +++ b/include/effect_clock.h @@ -1,17 +1,15 @@ -#ifndef effect_clock_H -#define effect_clock_H +#pragma once #include "Effect.h" #include "prototypes.h" -#include +#include "my_fastled.h" +#include "Window.h" class ClockEffect : public Effect { private: - Window window = {0, LED_HEIGHT - 6, LED_WIDTH, 6}; + Window* window = new Window(0, LED_HEIGHT - 6, LED_WIDTH, 6); public: void loop(); void loop(boolean invert, CRGB fg_color, CRGB bg_color); }; - -#endif diff --git a/include/effect_snake.h b/include/effect_snake.h index cad58dc..d1efe24 100644 --- a/include/effect_snake.h +++ b/include/effect_snake.h @@ -10,7 +10,6 @@ private: uint8_t direction = 1; uint8_t hue = 0; uint8_t run = 0; - Window window = {0, 0, LED_WIDTH, LED_HEIGHT-6}; bool is_turn_needed(); void turn_random(); bool turn_right(); diff --git a/include/fonts.h b/include/fonts.h new file mode 100644 index 0000000..01f1b93 --- /dev/null +++ b/include/fonts.h @@ -0,0 +1,5 @@ +#pragma once +#include "prototypes.h" + +extern Font font_numbers3x5; +extern Font font_numbers4x7; diff --git a/include/functions.h b/include/functions.h index 29d850a..8714061 100644 --- a/include/functions.h +++ b/include/functions.h @@ -7,20 +7,6 @@ uint16_t XYsafe(int x, int y); -void setPixel(int x, int y, CRGB color); - -void setPixel(int i, CRGB color); - -void setPixel(Window win, int x, int y, CRGB color); - -void addPixelColor(int i, CRGB color); - -void clear(Window window, CRGB color); - -void clear(Window window); - -void clear(); - void blur(fract8 blur_amount); void blur_row(uint8_t row_index, fract8 blur_amount); diff --git a/include/prototypes.h b/include/prototypes.h index 5df088f..6a135dd 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -1,5 +1,4 @@ -#ifndef prototypes_H -#define prototypes_H +#pragma once #include @@ -16,11 +15,12 @@ typedef struct { } AnimationData; typedef struct { - uint8_t x; - uint8_t y; - uint8_t w; - uint8_t h; -} Window; + uint8_t width; + uint8_t height; + const uint8_t *data; + bool (*isCharAllowed)(const char); + uint16_t (*getCharPosition)(const char); +} Font; typedef struct Vector { double x1; @@ -40,5 +40,3 @@ typedef struct { } Coords; extern uint8_t baseHue; - -#endif diff --git a/src/Animation.cpp b/src/Animation.cpp index 9231db6..6328450 100644 --- a/src/Animation.cpp +++ b/src/Animation.cpp @@ -32,6 +32,7 @@ it contains only one entry and .individual_delays will be false. #include "Animation.h" #include "functions.h" +#include "Window.h" Animation::Animation(AnimationData *d) { this->data = d; @@ -95,15 +96,15 @@ Animation::~Animation() { delete this->animation_data; } -void Animation::draw() { - for (uint16_t i=0; icurrentFrame; i++) this->drawFrame(i); +void Animation::draw(Window* win) { + for (uint16_t i=0; icurrentFrame; i++) this->drawFrame(win, i); } -void Animation::drawFrame() { - this->drawFrame(currentFrame); +void Animation::drawFrame(Window* win) { + this->drawFrame(win, currentFrame); } -void Animation::drawFrame(uint8_t frame_index) { +void Animation::drawFrame(Window* win, uint8_t frame_index) { uint16_t led_index = 0; for (uint16_t i=this->data->offsets[frame_index]; idata->offsets[frame_index + 1]; i++) { uint8_t color_index; @@ -120,7 +121,7 @@ void Animation::drawFrame(uint8_t frame_index) { led_index += count; } else { CRGB* color = this->getColor(color_index); - for (int j=0; jdrawPixel(led_index++, color); + for (int j=0; jdrawPixel(win, led_index++, color); } } } @@ -137,8 +138,8 @@ bool Animation::advance() { return false; } -void Animation::drawPixel(int index, CRGB* color) { - setPixel(this->xOffset + (index % this->data->w), this->yOffset + (index / this->data->h), *color); +void Animation::drawPixel(Window* win, int index, CRGB* color) { + win->setPixel(this->xOffset + (index % this->data->w), this->yOffset + (index / this->data->h), color); } uint16_t Animation::getFrameDelay(int frame) { diff --git a/src/Window.cpp b/src/Window.cpp new file mode 100644 index 0000000..f2353a0 --- /dev/null +++ b/src/Window.cpp @@ -0,0 +1,62 @@ +#include "Window.h" +#include "functions.h" + +Window* Window::getFullWindow() { + static Window win; + return &win; +} + +void Window::setPixel(uint8_t x, uint8_t y, CRGB* color) { + if (x>=this->width || y>=this->height) return; + leds[this->coordsToGlobalIndex(x, y)] = *color; +} + +void Window::setPixelByIndex(uint16_t index, CRGB* color) { + uint8_t x = index % this->width; + uint8_t y = index / this->width; + this->setPixel(x, y, color); +} + +uint16_t Window::coordsToGlobalIndex(uint8_t x, uint8_t y) { + return XYsafe(x + this->x, y+this->y); +} + +uint16_t Window::localToGlobalIndex(uint16_t index) { + uint8_t x = index % this->width; + uint8_t y = index / this->width; + return coordsToGlobalIndex(x, y); +} + +void Window::clear() { + CRGB black(0x000000); + this->clear(&black); +} + +void Window::clear(CRGB* color) { + for(int x=0; xwidth; x++) for(int y=0; yheight; y++) this->setPixel(x, y, color); +} + +void Window::drawChar(Font* font, uint8_t xPos, uint8_t yPos, const char c, CRGB* color, bool mask) { + if (!font->isCharAllowed(c)) return; + uint16_t position = font->getCharPosition(c); + uint8_t* data = new uint8_t[font->width]; + memcpy_P(data, font->data + (position*font->width), font->width); + + for(uint8_t y=0; yheight; y++) for(uint8_t x=0; xwidth; x++) { + bool on = (data[x]>>(font->height - 1 - y) & 1) * 255; + if (mask) on = !on; + if (on) this->setPixel(x + xPos, y + yPos, color); + } + + free(data); +} + +void Window::addPixelColor(uint16_t index, CRGB* color) { + leds[localToGlobalIndex(index)] += *color; +} + +void Window::fadeToBlackBy(fract8 speed) { + for (uint8_t x=0; xwidth; x++) for(uint8_t y=0; yheight; y++) { + leds[coordsToGlobalIndex(x, y)].nscale8(255 - speed); + } +} diff --git a/src/effect_animation.cpp b/src/effect_animation.cpp index 7cc77ef..47ec116 100644 --- a/src/effect_animation.cpp +++ b/src/effect_animation.cpp @@ -19,6 +19,6 @@ void AnimationEffect::stop() { } void AnimationEffect::loop() { - this->animation->drawFrame(); + this->animation->drawFrame(this->window); this->animation->advance(); } diff --git a/src/effect_big_clock.cpp b/src/effect_big_clock.cpp index c4dd75d..0bc49b3 100644 --- a/src/effect_big_clock.cpp +++ b/src/effect_big_clock.cpp @@ -1,7 +1,6 @@ #include "Effect.h" #include "effect_big_clock.h" -#include "text.h" -#include "functions.h" +#include "fonts.h" #include "ntp.h" void BigClockEffect::drawNumber(uint8_t number, int x, int y, CRGB color) { @@ -12,32 +11,13 @@ void BigClockEffect::drawNumber(uint8_t number, int x, int y, CRGB color) { void BigClockEffect::drawText(char *text, int x, int y, CRGB color) { for (uint8_t i = 0; i < strlen(text); i++) { - drawSprite(font_char(numbers4x7, text[i]), x + i * 4, y, color); - } -} - -const unsigned char* BigClockEffect::font_char(const unsigned char* font, char c) { - return font + (c - 48) * 4; -} - -void BigClockEffect::drawSprite(const unsigned char* sprite, int xOffset, int yOffset, CRGB color) { - 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; - } - } + window->drawChar(&font_numbers4x7, text[i], x + i * 4, y, &color); } } void BigClockEffect::loop() { - clear(); + window->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; -}*/ -drawNumber(ntpClient.getSeconds(), 8, 8, color_colon); + drawNumber(ntpClient.getSeconds(), 8, 8, color_colon); } diff --git a/src/effect_clock.cpp b/src/effect_clock.cpp index 74ae9db..505e455 100644 --- a/src/effect_clock.cpp +++ b/src/effect_clock.cpp @@ -1,7 +1,7 @@ #include "effect_clock.h" #include #include "functions.h" -#include "text.h" +#include "fonts.h" #include "ntp.h" void ClockEffect::loop() { @@ -10,32 +10,33 @@ void ClockEffect::loop() { void ClockEffect::loop(boolean invert, CRGB fg_color, CRGB bg_color) { if (!invert) { - clear(window, bg_color); + window->clear(&bg_color); } else { // Manually clear the needed parts - for(int i=0; iwidth; i++) window->setPixel(i, 0, &bg_color); for(int y=0; y<6; y++) { - setPixel(window, 3, y, bg_color); + window->setPixel(3, y, &bg_color); if (y!=2 && y!=4) { - setPixel(window, 7, y, bg_color); + window->setPixel(7, y, &bg_color); } - setPixel(window, 8, y, bg_color); - setPixel(window, 12, y, bg_color); + window->setPixel(8, y, &bg_color); + window->setPixel(12, y, &bg_color); } fg_color = bg_color; } if (ntpClient.isTimeSet()==false && (ntpClient.getSeconds() & 1)==0) { - clear(window, bg_color); + window->clear(&bg_color); return; } int h = ntpClient.getHours(); - drawDigit(window, numbers3x5, 3, 5, 0, 1, h / 10, fg_color, invert); - drawDigit(window, numbers3x5, 3, 5, 4, 1, h % 10, fg_color, invert); + //void drawChar(Font f, uint8_t x, uint8_t y, const char c, CRGB* color, bool mask=false); + window->drawChar(&font_numbers3x5, 0, 1, '0' + (h / 10), &fg_color, invert); + window->drawChar(&font_numbers3x5, 4, 1, '0' + (h % 10), &fg_color, invert); int m = ntpClient.getMinutes(); - drawDigit(window, numbers3x5, 3, 5, 9, 1, m / 10, fg_color, invert); - drawDigit(window, numbers3x5, 3, 5, 13, 1, m % 10, fg_color, invert); + window->drawChar(&font_numbers3x5, 9, 1, '0' + (m / 10), &fg_color, invert); + window->drawChar(&font_numbers3x5, 13, 1, '0' + (m % 10), &fg_color, invert); if (ntpClient.getSeconds() & 1) { - setPixel(window, 7, 2, fg_color); - setPixel(window, 7, 4, fg_color); + window->setPixel(7, 2, &fg_color); + window->setPixel(7, 4, &fg_color); } } diff --git a/src/effect_confetti.cpp b/src/effect_confetti.cpp index 3599d47..7c9128a 100644 --- a/src/effect_confetti.cpp +++ b/src/effect_confetti.cpp @@ -4,9 +4,10 @@ #include "prototypes.h" void ConfettiEffect::loop() { - fadeToBlackBy(leds, LED_COUNT, 1); + window->fadeToBlackBy(3); for (int i=0; iaddPixelColor(random16(LED_COUNT), &color); } } diff --git a/src/effect_dynamic.cpp b/src/effect_dynamic.cpp index 8b02b16..4e4b716 100644 --- a/src/effect_dynamic.cpp +++ b/src/effect_dynamic.cpp @@ -18,9 +18,9 @@ void SingleDynamicEffect::loop() { } void SingleDynamicEffect::draw() { - for (int x=0; xwidth; x++) for (int y=0; yheight; y++) { + int index = y/2 * window->width/2 + x/2; + window->setPixel(x, y, &tiles[index]); } } diff --git a/src/effect_fire.cpp b/src/effect_fire.cpp index 8ff840f..e05148a 100644 --- a/src/effect_fire.cpp +++ b/src/effect_fire.cpp @@ -5,9 +5,9 @@ #include "functions.h" void FireEffect::start() { - this->data = new uint8_t[LED_COUNT]; - for (int i=0; idata[i]=0; - for (int i=0; idata[i]=this->spark_temp(); + this->data = new uint8_t[this->window->width * this->window->height]; + for (int i=0; i<(this->window->width * this->window->height); i++) this->data[i]=0; + for (int i=0; iwindow->width; i++) this->data[i]=this->spark_temp(); } void FireEffect::stop() { @@ -22,11 +22,11 @@ void FireEffect::loop() { } void FireEffect::cooldown() { - for(int i=0; idata[i] = scale8(this->data[i], EFFECT_FIRE_COOLDOWN); // 240 or something + for(int i=0; i<(this->window->width * this->window->height); i++) this->data[i] = scale8(this->data[i], EFFECT_FIRE_COOLDOWN); // 240 or something } void FireEffect::spark() { - for(int x=0; xdata[x] = this->spark_temp(); + for(int x=0; xwindow->width; x++) if (random8(EFFECT_FIRE_SPARK_CHANCE)==0) this->data[x] = this->spark_temp(); } inline uint8_t FireEffect::spark_temp() { @@ -34,12 +34,12 @@ inline uint8_t FireEffect::spark_temp() { } void FireEffect::propagate() { - for (int y=1; ywindow->height; y++) for (int x=0; xwindow->width; x++) { + int index = y*this->window->width + x; + uint8_t below_index = index - this->window->width; if (x==0) { this->data[index] = scale8(this->data[below_index], 128) + scale8(this->data[below_index+1], 64); - } else if (x==LED_WIDTH-1) { + } else if (x==this->window->width-1) { this->data[index] = scale8(this->data[below_index], 128) + scale8(this->data[below_index-1], 64); } else { this->data[index] = scale8(this->data[below_index], 128) + scale8(this->data[below_index-1], 32) + scale8(this->data[below_index+1], 32); @@ -48,7 +48,8 @@ void FireEffect::propagate() { } void FireEffect::draw() { - for (int y=1; ydata[y*LED_WIDTH + x])); + for (int y=1; ywindow->width; y++) for (int x=0; xwindow->width; x++) { + CRGB color = ColorFromPalette((CRGBPalette16) palette_fire, this->data[y*this->window->width + x]); + this->window->setPixel(x, this->window->height - 1 - y, (CRGB *)&color); } } diff --git a/src/effect_matrix.cpp b/src/effect_matrix.cpp index d4176f4..d79023a 100644 --- a/src/effect_matrix.cpp +++ b/src/effect_matrix.cpp @@ -9,7 +9,7 @@ MatrixEffectColumn::MatrixEffectColumn(Window* win, int xPos) : MatrixEffectColu window = win; x = xPos; start(); - y = random8(0, win->h); + y = random8(0, window->height); } void MatrixEffectColumn::start() { @@ -21,16 +21,18 @@ void MatrixEffectColumn::start() { void MatrixEffectColumn::advance() { y++; - if (y-length > window->h) running = false; + if (y-length > window->height) running = false; } void MatrixEffectColumn::draw() { for(int i=0; isetPixel(x, y-i, &color); } } @@ -53,10 +55,10 @@ void MatrixEffectColumn::loop() { boolean MatrixEffect::can_be_shown_with_clock() { return true; }; MatrixEffect::MatrixEffect() { - for (int i=0; iclear(); + for (int i=0; iwidth; i++) columns[i].loop(); } diff --git a/src/effect_sinematrix3.cpp b/src/effect_sinematrix3.cpp index 74874ca..56d1082 100644 --- a/src/effect_sinematrix3.cpp +++ b/src/effect_sinematrix3.cpp @@ -44,7 +44,8 @@ void Sinematrix3Effect::loop() { for ( int y = 0; y < LED_HEIGHT; y++ ) { Vector c = add(multiply( multiply(rotate, zoom), { .x1 = x - rcx, .x2 = y - rcy } ), translate); int sat = (basecol + basefield(c.x1, c.x2)) * 255; - setPixel(window, x, y, CHSV(sat, 120, 255)); + CRGB color(CHSV(sat, 120, 255)); + window->setPixel(x, y, &color); } } } diff --git a/src/effect_snake.cpp b/src/effect_snake.cpp index c3af641..5c37def 100644 --- a/src/effect_snake.cpp +++ b/src/effect_snake.cpp @@ -3,6 +3,7 @@ SnakeEffect::SnakeEffect() { this->coords = {0, 0}; + this->window = new Window(0, 0, LED_WIDTH, LED_HEIGHT-6); } void SnakeEffect::loop() { @@ -12,8 +13,9 @@ void SnakeEffect::loop() { this->coords = update_position(this->coords, this->direction); } - fadeToBlackBy(leds, LED_COUNT, 2); - setPixel(window, this->coords.x, this->coords.y, CHSV(hue, 200, 255)); + window->fadeToBlackBy(2); + CRGB color(CHSV(hue, 200, 255)); + window->setPixel(this->coords.x, this->coords.y, &color); hue++; } @@ -43,7 +45,7 @@ bool SnakeEffect::is_turn_needed() { bool SnakeEffect::is_direction_okay(uint8_t dir) { Coords c = update_position(this->coords, dir); - return c.xwidth && c.yheight; } Coords SnakeEffect::update_position(Coords original, uint8_t direction) { diff --git a/src/effect_static.cpp b/src/effect_static.cpp index 6609df7..89fd688 100644 --- a/src/effect_static.cpp +++ b/src/effect_static.cpp @@ -8,6 +8,6 @@ StaticEffect::StaticEffect(CRGB col) { void StaticEffect::loop() { EVERY_N_SECONDS(1) { - clear(window, color); + window->clear(&color); } } diff --git a/src/effect_twirl.cpp b/src/effect_twirl.cpp index b078f65..3b867f4 100644 --- a/src/effect_twirl.cpp +++ b/src/effect_twirl.cpp @@ -2,10 +2,11 @@ #include "functions.h" void TwirlEffect::loop() { - for (int x=0; xwidth; x++) for (int y=0; yheight; y++) { uint8_t angle = (x==center_x && y==center_y) ? 0 : atan2(y - center_y, x - center_x) / M_PI * 128 + 128 + angleOffset; uint8_t brightness = sqrt16((center_x - x) * (center_x - x) + (center_y - y) * (center_y - y)) & 0xFF; - setPixel(window, x, y, CHSV(angle, (brightness<<5) & 0xFF, 255)); + CRGB color(CHSV(angle, (brightness<<5) & 0xFF, 255)); + window->setPixel(x, y, &color); } angleOffset += 1; } diff --git a/include/text.h b/src/fonts.cpp similarity index 87% rename from include/text.h rename to src/fonts.cpp index f67a913..f8a4a73 100644 --- a/include/text.h +++ b/src/fonts.cpp @@ -1,8 +1,44 @@ -#ifndef text_H -#define text_H +#include "prototypes.h" -#include "functions.h" +const uint8_t font_numbers3x5_data[] PROGMEM = { + B01110, B10001, B01110, // 0 + B01000, B11111, B00000, // 1 + B01001, B10011, B01101, // 2 + B10001, B10101, B01010, // 3 + B11100, B00100, B11111, // 4 + B11101, B10101, B10111, // 5 + B01110, B10101, B10110, // 6 + B10000, B10011, B11100, // 7 + B11111, B10101, B11111, // 8 + B11101, B10101, B11111, // 9 +}; +bool font_numbers3x5_check(const char c) { return c>='0' && c<='9'; } + +uint16_t font_numbers3x5_get(const char c) { return c - '0'; } + +Font font_numbers3x5 = {3, 5, &font_numbers3x5_data[0], font_numbers3x5_check, font_numbers3x5_get}; + +const uint8_t font_numbers4x7_data[] PROGMEM = { + 0x3E, 0x51, 0x45, 0x3E,// 0 + 0x00, 0x42, 0x7F, 0x40,// 1 + 0x42, 0x61, 0x49, 0x46,// 2 + 0x21, 0x45, 0x4B, 0x31,// 3 + 0x18, 0x14, 0x7F, 0x10,// 4 + 0x27, 0x45, 0x45, 0x39,// 5 + 0x3C, 0x4A, 0x49, 0x30,// 6 + 0x01, 0x71, 0x09, 0x05,// 7 + 0x36, 0x49, 0x49, 0x36,// 8 + 0x06, 0x49, 0x29, 0x1E // 9 +}; + +bool font_numbers4x7_check(const char c) { return c>='0' && c<='9'; } + +uint16_t font_numbers4x7_get(const char c) { return c - '0'; } + +Font font_numbers4x7 = {4, 7, &font_numbers4x7_data[0], font_numbers4x7_check, font_numbers4x7_get}; + +/* const unsigned char font5x7[] = { 0x00, 0x00, 0x00, 0x00, 0x00,// (space) 0x00, 0x00, 0x5F, 0x00, 0x00,// ! @@ -102,38 +138,5 @@ const unsigned char font5x7[] = { 0x08, 0x1C, 0x2A, 0x08, 0x08 // <- }; -const unsigned char numbers4x7[] = { - 0x3E, 0x51, 0x45, 0x3E,// 0 - 0x00, 0x42, 0x7F, 0x40,// 1 - 0x42, 0x61, 0x49, 0x46,// 2 - 0x21, 0x45, 0x4B, 0x31,// 3 - 0x18, 0x14, 0x7F, 0x10,// 4 - 0x27, 0x45, 0x45, 0x39,// 5 - 0x3C, 0x4A, 0x49, 0x30,// 6 - 0x01, 0x71, 0x09, 0x05,// 7 - 0x36, 0x49, 0x49, 0x36,// 8 - 0x06, 0x49, 0x29, 0x1E // 9 -}; -const unsigned char numbers3x5[] = { - B01110, B10001, B01110, // 0 - B01000, B11111, B00000, // 1 - B01001, B10011, B01101, // 2 - B10001, B10101, B01010, // 3 - B11100, B00100, B11111, // 4 - B11101, B10101, B10111, // 5 - B01110, B10101, B10110, // 6 - B10000, B10011, B11100, // 7 - B11111, B10101, B11111, // 8 - B11101, B10101, B11111, // 9 -}; - -void drawTextSprite(Window window, const unsigned char* sprite, int w, int h, int xPos, int yPos, CRGB color, boolean invert); - -void drawChar(Window window, const unsigned char* font, int w, int h, int x, int y, char c, CRGB color); - -void drawDigit(Window window, const unsigned char* font, int w, int h, int x, int y, int digit, CRGB color, boolean invert); - -void drawText(Window window, const char *font, int w, int h, char *text, int x, int y, CRGB color); - -#endif +*/ diff --git a/src/functions.cpp b/src/functions.cpp index 82873c1..65be99b 100644 --- a/src/functions.cpp +++ b/src/functions.cpp @@ -19,49 +19,6 @@ uint16_t XYsafe(int x, int y) { return y*LED_WIDTH+x; } -void setPixel(int x, int y, CRGB color) { - if ( x >= LED_WIDTH) return; - if ( y >= LED_HEIGHT) return; - if ( x < 0) return; - if ( y < 0) return; - - uint16_t index = XYsafe(x, y); - - leds[index] = color; -} - -void setPixel(int i, CRGB color) { - int x = i % LED_WIDTH; - int y = i / LED_WIDTH; - setPixel(x, y, color); -} - -void setPixel(Window win, int x, int y, CRGB color) { - if (x >= win.w || y >= win.h || x < 0 || y < 0) return; - setPixel(win.x + x, win.y + y, color); -} - -void addPixelColor(int i, CRGB color) { - leds[i] += color; -} - -void clear(Window window, CRGB color) { - for ( byte y = 0; y < window.h; y++) { - for ( byte x = 0; x < window.w; x++) { - setPixel(window, x, y, color); - } - } -} - -void clear(Window window) { - clear(window, CRGB(0)); -} - -void clear() { - Window w = {0, 0, LED_WIDTH, LED_HEIGHT}; - clear(w); -} - void blur(fract8 blur_amount) { // Based on FastLED code for (uint8_t i=0; iclear(); for (int i=0; isetPixel(i, 0, &color); } FastLED.show(); } diff --git a/src/text.cpp b/src/text.cpp deleted file mode 100644 index 0cebc6f..0000000 --- a/src/text.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "functions.h" -#include "text.h" - -void drawTextSprite(Window window, const unsigned char* sprite, int w, int h, int xPos, int yPos, CRGB color, boolean invert) { - for (byte y=0; y>(h-1-y)&1)*255; - if (invert) on = !on; - if (on) setPixel(window, x+xPos, y+yPos, color); - } -} - -void drawChar(Window window, const unsigned char* font, int w, int h, int x, int y, char c, CRGB color) { - const unsigned char* sprite = &font[(c-32)*w]; - drawTextSprite(window, sprite, w, h, x, y, color, false); -} - -void drawDigit(Window window, const unsigned char* font, int w, int h, int x, int y, int digit, CRGB color, boolean invert) { - const unsigned char* sprite = &font[digit*w]; - drawTextSprite(window, sprite, w, h, x, y, color, invert); -} - -void drawText(Window window, const char *font, int w, int h, char *text, int x, int y, CRGB color) { - for (uint16_t i = 0; i < strlen(text); i++) { - drawChar(window, font5x7, 5, 7, x+i*(w+1), y, text[i], color); - } -}