Initial Commit

This commit is contained in:
2026-03-31 10:19:59 -04:00
commit a1af89eef1
15 changed files with 444 additions and 0 deletions

86
include/Utilities.h Normal file
View File

@@ -0,0 +1,86 @@
#ifndef UTILITIES_H
#define UTILITIES_H
#include <Arduino.h>
#include <FastLED.h>
#include "GlobalSettings.h"
enum class XYModes {
HORIZONTALSCAN,
HORIZONTALSERPENTINE,
COLUMNSCAN,
COLUMNSERPENTINE
};
class Utilities {
public:
static uint16_t XY(XYModes mode, uint16_t x, uint16_t y) {
if(mode == XYModes::HORIZONTALSCAN) {
return WIDTH * y + x;
} else if(mode == XYModes::COLUMNSCAN) {
return HEIGHT * x + y;
} else if(mode == XYModes::HORIZONTALSERPENTINE) {
if(y & 0x1) {
return y * WIDTH + (WIDTH - 1 - x);
} else {
return y * WIDTH + x;
}
} else if(mode == XYModes::COLUMNSERPENTINE) {
if(x & 0x1) {
return x * HEIGHT + (HEIGHT - 1 - y);
} else {
return x * HEIGHT + y;
}
} else {
return 0; //How did you get here?
}
}
static void setArea(CRGB* leds, XYModes mode, uint16_t startX, uint16_t startY, uint16_t endX, uint16_t endY, CRGB color) {
for(uint16_t x = startX; x < endX; x++) {
for(uint16_t y = startY; y < endY; y++) {
leds[XY(mode, x, y)] = color;
}
}
}
static void setAll(CRGB* leds, XYModes mode, CRGB color) {
setArea(leds, mode, 0, 0, WIDTH, HEIGHT, color);
}
static void drawPackedSquareBitmap(CRGB* leds, XYModes mode, const uint8_t* bitmap, uint16_t xOrigin, CRGB color) {
for(uint16_t y = 0; y < 8; y++) {
uint8_t mask = 0x80;
for(uint16_t x = xOrigin; x < xOrigin + 8; x++) {
if((bitmap[y] & mask) != 0) {
leds[XY(mode, x, y)] = color;
}
mask >>= 1;
}
}
}
static void drawPackedFullFrameBitmap(CRGB* leds, XYModes mode, const uint32_t* bitmap, CRGB color) {
for(uint16_t y = 0; y < 8; y++) {
uint32_t mask = 0x80000000;
for(uint16_t x = 0; x < 32; x++) {
if((bitmap[y] & mask) != 0) {
leds[XY(mode, x, y)] = color;
}
mask >>= 1;
}
}
}
static void drawFullFrameIndexedMap(CRGB* leds, XYModes mode, uint8_t** indexMap, CRGB* colors) {
for(uint16_t x = 0; x < WIDTH; x++) {
for(uint16_t y = 0; y < HEIGHT; y++) {
leds[XY(mode, x, y)] = colors[indexMap[x][y]];
}
}
}
};
#endif