Files
pti-ledy/lowLevel.ino
T
2026-01-29 14:28:56 +01:00

250 lines
7.6 KiB
Arduino

#include "lowLevel.h"
unsigned char saved_images_count = 0;
Cursor cursor1;
uint32_t saved_imaged[2][16][16] =
{
{
{
0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000
},
{
0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000
},
{
0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000
},
{
0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFF000000, 0xFF000000, 0xFF000000
},
{
0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFF000000, 0xFF000000, 0xFF000000
},
{
0xFF000000, 0xFF000000, 0xFFFFFF00, 0xFFFFFF00, 0xFF000000, 0xFF000000, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFF000000, 0xFF000000, 0xFFFFFF00, 0xFFFFFF00, 0xFF000000, 0xFF000000
},
{
0xFF000000, 0xFF000000, 0xFFFFFF00, 0xFFFFFF00, 0xFF000000, 0xFF000000, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFF000000, 0xFF000000, 0xFFFFFF00, 0xFFFFFF00, 0xFF000000, 0xFF000000
},
{
0xFF000000, 0xFF000000, 0xFFFFFF00, 0xFFFFFF00, 0xFF000000, 0xFF000000, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFF000000, 0xFF000000, 0xFFFFFF00, 0xFFFFFF00, 0xFF000000, 0xFF000000
},
{
0xFF000000, 0xFF000000, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFF000000, 0xFF000000
},
{
0xFF000000, 0xFF000000, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFF000000, 0xFF000000, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFF000000, 0xFF000000
},
{
0xFF000000, 0xFF000000, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFF000000, 0xFF000000, 0xFFFFFF00, 0xFF000000, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFF000000, 0xFF000000
},
{
0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFF000000, 0xFF000000, 0xFFFFFF00, 0xFF000000, 0xFFFFFF00, 0xFFFFFF00, 0xFF000000, 0xFF000000, 0xFF000000
},
{
0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFF000000, 0xFF000000, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFF000000, 0xFF000000, 0xFF000000
},
{
0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFFFFFF00, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000
},
{
0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000
},
{
0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000
}
}
};
void setPixel(short x, short y, uint32_t color)
{
if (x < 0 || y < 0) return;
if (x % 2 == 1)
{
y = PANEL_PIXEL_COUNT - 1 - y;
}
pixels.setPixelColor(y + (x * PANEL_PIXEL_COUNT), color);
}
uint32_t getPixelColor(short x, short y)
{
if (x < 0 || y < 0) return 0;
if (x % 2 == 1)
{
y = PANEL_PIXEL_COUNT - 1 - y;
}
return pixels.getPixelColor(y + (x * PANEL_PIXEL_COUNT));
}
void drawImageFromSaved(short offset_x, short offset_y, unsigned char i)
{
for (int row = 0; row < 16; row++)
{
for (int col = 0; col < 16; col++)
{
uint32_t px_color = saved_imaged[i][row][col];
if (!px_color)
{
continue;
}
short pixel_x = col + offset_x;
short pixel_y = row + offset_y;
if (pixel_x >= 0 && pixel_x < NUMPIXELS &&
pixel_y >= 0 && pixel_y < NUMPIXELS)
{
setPixel(pixel_x, pixel_y, px_color);
}
}
}
}
void drawCharacterPart(const bool* character_row, unsigned char height, uint32_t color, short start_x, short start_y)
{
for (unsigned char col = 0; col < height; col++)
{
if (character_row[col])
{
short pixel_x = col + start_x;
short pixel_y = start_y;
if (pixel_x >= 0 && pixel_x <= PANEL_MAX_X &&
pixel_y >= 0 && pixel_y <= PANEL_MAX_Y)
{
setPixel(pixel_x, pixel_y, color);
}
}
}
}
void drawCharacter(const bool (*character)[5], unsigned char height, unsigned char width, uint32_t color, Cursor (*used_cursor))
{
for (unsigned char row = 0; row < height; row++)
{
drawCharacterPart(character[row], width, color, used_cursor->x, row + used_cursor->y);
}
used_cursor->x += width + 1;
}
void fillPixels(short x1, short y1, short x2, short y2, uint32_t color)
{
if (x1 > x2)
{
short tmp = x1; x1 = x2; x2 = tmp;
}
if (y1 > y2)
{
short tmp = y1; y1 = y2; y2 = tmp;
}
short width = (short)(x2 - x1 + 1);
short height = (short)(y2 - y1 + 1);
for (short i = 0; i < height; i++)
{
for (short j = 0; j < width; j++)
{
setPixel(x1 + j, y1 + i, color);
}
}
}
void shiftGivenRectangleLeft(short x1, short y1, short x2, short y2, unsigned char shift_by)
{
if (!shift_by)
{
return;
}
if (x1 > x2)
{
short tmp = x1; x1 = x2; x2 = tmp;
}
if (y1 > y2)
{
short tmp = y1; y1 = y2; y2 = tmp;
}
unsigned short width = (unsigned short)(x2 - x1 + 1);
unsigned short height = (unsigned short)(y2 - y1 + 1);
for (short i = 0; i < height; i++)
{
short y = y1 + i;
if (y < 0 || y > PANEL_MAX_Y) continue;
for (short j = 0; j < width; j++)
{
short src_x = x1 + j;
short dest_x = src_x - shift_by;
uint32_t color = 0;
if (src_x >= 0 && src_x <= PANEL_MAX_X) {
color = getPixelColor(src_x, y);
}
if (dest_x >= 0 && dest_x <= PANEL_MAX_X) {
setPixel(dest_x, y, color);
}
}
}
// Clear the trailing edge that was shifted from
for (short y = y1; y <= y2; y++) {
if (y < 0 || y > PANEL_MAX_Y) continue;
for (short x = x2 - shift_by + 1; x <= x2; x++) {
if (x >= 0 && x <= PANEL_MAX_X) {
setPixel(x, y, 0);
}
}
}
}
void shiftGivenRectangleRight(short x1, short y1, short x2, short y2, unsigned char shift_by)
{
if (!shift_by)
{
return;
}
if (x1 > x2)
{
short tmp = x1; x1 = x2; x2 = tmp;
}
if (y1 > y2)
{
short tmp = y1; y1 = y2; y2 = tmp;
}
unsigned short width = (unsigned short)(x2 - x1 + 1);
unsigned short height = (unsigned short)(y2 - y1 + 1);
for (short i = 0; i < height; i++)
{
short y = y1 + i;
if (y < 0 || y > PANEL_MAX_Y) continue;
for (short j = width - 1; j >= 0; j--)
{
short src_x = x1 + j;
short dest_x = src_x + shift_by;
uint32_t color = 0;
if (src_x >= 0 && src_x <= PANEL_MAX_X) {
color = getPixelColor(src_x, y);
}
if (dest_x >= 0 && dest_x <= PANEL_MAX_X) {
setPixel(dest_x, y, color);
}
}
}
// Clear the trailing edge that was shifted from
for (short y = y1; y <= y2; y++) {
if (y < 0 || y > PANEL_MAX_Y) continue;
for (short x = x1; x < x1 + shift_by; x++) {
if (x >= 0 && x <= PANEL_MAX_X) {
setPixel(x, y, 0);
}
}
}
}