Windows. Everything now is implemented in Windows. ;-) (Okay, just the drawing stuff. And defnititely nothing by Microsoft.)

This commit is contained in:
Fabian Schlenz 2019-06-11 19:48:09 +02:00
parent 9acdc42dc3
commit 83254f2eaa
25 changed files with 223 additions and 223 deletions

View File

@ -34,6 +34,7 @@ it contains only one entry and .individual_delays will be false.
#include <Arduino.h>
#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();
};

View File

@ -1,19 +1,19 @@
#ifndef Effect_H
#define Effect_H
#include "prototypes.h"
#include "Window.h"
#include "config.h"
#include <Arduino.h>
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() {}

26
include/Window.h Normal file
View File

@ -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);
};

View File

@ -1,17 +1,15 @@
#ifndef effect_clock_H
#define effect_clock_H
#pragma once
#include "Effect.h"
#include "prototypes.h"
#include <FastLED.h>
#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

View File

@ -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();

5
include/fonts.h Normal file
View File

@ -0,0 +1,5 @@
#pragma once
#include "prototypes.h"
extern Font font_numbers3x5;
extern Font font_numbers4x7;

View File

@ -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);

View File

@ -1,5 +1,4 @@
#ifndef prototypes_H
#define prototypes_H
#pragma once
#include <Arduino.h>
@ -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

View File

@ -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; i<this->currentFrame; i++) this->drawFrame(i);
void Animation::draw(Window* win) {
for (uint16_t i=0; i<this->currentFrame; 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]; i<this->data->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; j<count; j++) this->drawPixel(led_index++, color);
for (int j=0; j<count; j++) this->drawPixel(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) {

62
src/Window.cpp Normal file
View File

@ -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; x<this->width; x++) for(int y=0; y<this->height; 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; y<font->height; y++) for(uint8_t x=0; x<font->width; 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; x<this->width; x++) for(uint8_t y=0; y<this->height; y++) {
leds[coordsToGlobalIndex(x, y)].nscale8(255 - speed);
}
}

View File

@ -19,6 +19,6 @@ void AnimationEffect::stop() {
}
void AnimationEffect::loop() {
this->animation->drawFrame();
this->animation->drawFrame(this->window);
this->animation->advance();
}

View File

@ -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);
}

View File

@ -1,7 +1,7 @@
#include "effect_clock.h"
#include <FastLED.h>
#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; i<window.w; i++) setPixel(window, i, 0, bg_color);
for(int i=0; i<window->width; 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);
}
}

View File

@ -4,9 +4,10 @@
#include "prototypes.h"
void ConfettiEffect::loop() {
fadeToBlackBy(leds, LED_COUNT, 1);
window->fadeToBlackBy(3);
for (int i=0; i<EFFECT_CONFETTI_PIXELS_PER_LOOP; i++) {
addPixelColor(random16(LED_COUNT), CHSV(baseHue + random8(64), 200, 255));
CRGB color(CHSV(baseHue + random8(64), 200, 255));
window->addPixelColor(random16(LED_COUNT), &color);
}
}

View File

@ -18,9 +18,9 @@ void SingleDynamicEffect::loop() {
}
void SingleDynamicEffect::draw() {
for (int x=0; x<window.w; x++) for (int y=0; y<window.h; y++) {
int index = y/2 * window.w/2 + x/2;
setPixel(window, x, y, tiles[index]);
for (int x=0; x<window->width; x++) for (int y=0; y<window->height; y++) {
int index = y/2 * window->width/2 + x/2;
window->setPixel(x, y, &tiles[index]);
}
}

View File

@ -5,9 +5,9 @@
#include "functions.h"
void FireEffect::start() {
this->data = new uint8_t[LED_COUNT];
for (int i=0; i<LED_COUNT; i++) this->data[i]=0;
for (int i=0; i<LED_WIDTH; i++) this->data[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; i<this->window->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; i<LED_COUNT; i++) this->data[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; x<LED_WIDTH; x++) if (random8(EFFECT_FIRE_SPARK_CHANCE)==0) this->data[x] = this->spark_temp();
for(int x=0; x<this->window->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; y<LED_HEIGHT; y++) for (int x=0; x<LED_WIDTH; x++) {
int index = y*LED_WIDTH + x;
uint8_t below_index = (y-1)*LED_WIDTH + x;
for (int y=1; y<this->window->height; y++) for (int x=0; x<this->window->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; y<LED_HEIGHT; y++) for (int x=0; x<LED_WIDTH; x++) {
setPixel(x, LED_HEIGHT - 1 - y, ColorFromPalette((CRGBPalette16) palette_fire, this->data[y*LED_WIDTH + x]));
for (int y=1; y<this->window->width; y++) for (int x=0; x<this->window->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);
}
}

View File

@ -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; i<length; i++) {
CRGB color;
if (i==0) {
setPixel(*window, x, y-i, CRGB(255, 255, 255));
color = CRGB(255, 255, 255);
} else {
setPixel(*window, x, y-i, ColorFromPalette((CRGBPalette16)palette_matrix, 255 * (length - i) / length));
color = ColorFromPalette((CRGBPalette16)palette_matrix, 255 * (length - i) / length);
}
window->setPixel(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; i<LED_WIDTH; i++) columns[i] = MatrixEffectColumn(&window, i);
for (int i=0; i<LED_WIDTH; i++) columns[i] = MatrixEffectColumn(window, i);
}
void MatrixEffect::loop() {
clear(window);
for (int i=0; i<LED_WIDTH; i++) columns[i].loop();
window->clear();
for (int i=0; i<window->width; i++) columns[i].loop();
}

View File

@ -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);
}
}
}

View File

@ -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.x<window.w && c.y<window.h;
return c.x<window->width && c.y<window->height;
}
Coords SnakeEffect::update_position(Coords original, uint8_t direction) {

View File

@ -8,6 +8,6 @@ StaticEffect::StaticEffect(CRGB col) {
void StaticEffect::loop() {
EVERY_N_SECONDS(1) {
clear(window, color);
window->clear(&color);
}
}

View File

@ -2,10 +2,11 @@
#include "functions.h"
void TwirlEffect::loop() {
for (int x=0; x<window.w; x++) for (int y=0; y<window.h; y++) {
for (int x=0; x<window->width; x++) for (int y=0; y<window->height; 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;
}

View File

@ -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
*/

View File

@ -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; i<LED_HEIGHT; i++) blur_row(i, blur_amount);

View File

@ -10,7 +10,6 @@
#include "EffectEntry.h"
#include "my_mqtt.h"
#include "functions.h"
#include "text.h"
#include "effects.h"
uint8_t starting_up = OTA_STARTUP_DELAY;
@ -43,9 +42,11 @@ void loop() {
EVERY_N_SECONDS(1) {
Serial.print("Core * Waiting for OTA... "); Serial.println(starting_up);
starting_up--;
clear();
Window* w = Window::getFullWindow();
CRGB color(0xFF0000);
w->clear();
for (int i=0; i<starting_up; i++) {
leds[XYsafe(i, 0)] = CRGB(0xff0000);
w->setPixel(i, 0, &color);
}
FastLED.show();
}

View File

@ -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; y++) for (byte x=0; x<w; x++) {
bool on = (sprite[x]>>(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);
}
}