#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(unsigned short x, unsigned short y, uint32_t color) { if (x % 2 == 1) { y = PANEL_PIXEL_COUNT - 1 - y; } pixels.setPixelColor(y + (x * PANEL_PIXEL_COUNT), color); } uint32_t getPixelColor(unsigned short x, unsigned short y) { if (x % 2 == 1) { y = PANEL_PIXEL_COUNT - 1 - y; } return pixels.getPixelColor(y + (x * PANEL_PIXEL_COUNT)); } void drawImageFromSaved(unsigned short offset_x, unsigned 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; } unsigned short pixel_x = col + offset_x; unsigned 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 drawCharacter(const bool (*character)[5], unsigned char height, unsigned char width, uint32_t color, Cursor (*used_cursor)) { for (unsigned char row = 0; row < 7; row++) { for (unsigned char col = 0; col < 5; col++) { if (character[row][col]) { unsigned short pixel_x = col + used_cursor->x; unsigned short pixel_y = row + used_cursor->y; if (pixel_x <= PANEL_MAX_X && pixel_y <= PANEL_MAX_Y) { setPixel(pixel_x, pixel_y, color); } } } } used_cursor->x += width + 1; } void fillPixels(unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, uint32_t color) { if (x1 > x2) { unsigned short tmp = x1; x1 = x2; x2 = tmp; } if (y1 > y2) { unsigned short tmp = y1; y1 = y2; y2 = tmp; } unsigned short width = (unsigned short)(x2 - x1 + 1); unsigned short height = (unsigned short)(y2 - y1 + 1); for (unsigned short i = 0; i < height; i++) { for (unsigned 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); } } } }