Compare commits
5 Commits
e3f23a1427
...
cbf5148b0f
Author | SHA1 | Date |
---|---|---|
|
cbf5148b0f | |
|
e9cee7a232 | |
|
744a4418f1 | |
|
aa7bcf6c03 | |
|
7013cac8f1 |
Binary file not shown.
After Width: | Height: | Size: 5.1 KiB |
Binary file not shown.
After Width: | Height: | Size: 5.1 KiB |
Binary file not shown.
After Width: | Height: | Size: 5.1 KiB |
Binary file not shown.
After Width: | Height: | Size: 5.1 KiB |
Binary file not shown.
After Width: | Height: | Size: 5.1 KiB |
Binary file not shown.
After Width: | Height: | Size: 5.1 KiB |
|
@ -0,0 +1,254 @@
|
|||
/*******************************************************************************
|
||||
* BMP Class
|
||||
*
|
||||
* Rewrite from: https://github.com/Jaycar-Electronics/Arduino-Picture-Frame.git
|
||||
******************************************************************************/
|
||||
#ifndef _BMPCLASS_H_
|
||||
#define _BMPCLASS_H_
|
||||
|
||||
|
||||
#include <SD.h>
|
||||
|
||||
|
||||
typedef void(BMP_DRAW_CALLBACK)(int16_t x, int16_t y, uint16_t *bitmap, int16_t w, int16_t h);
|
||||
|
||||
class BmpClass
|
||||
{
|
||||
public:
|
||||
void draw(
|
||||
File *f, BMP_DRAW_CALLBACK *bmpDrawCallback, bool useBigEndian,
|
||||
int16_t x, int16_t y, int16_t widthLimit, int16_t heightLimit)
|
||||
{
|
||||
_bmpDrawCallback = bmpDrawCallback;
|
||||
_useBigEndian = useBigEndian;
|
||||
_heightLimit = heightLimit;
|
||||
|
||||
int16_t u, v;
|
||||
uint32_t xend;
|
||||
|
||||
getbmpparms(f);
|
||||
|
||||
//validate bitmap
|
||||
if ((bmtype == 19778) && (bmwidth > 0) && (bmheight > 0) && (bmbpp > 0))
|
||||
{
|
||||
//centre image
|
||||
u = (widthLimit - bmwidth) / 2;
|
||||
v = (heightLimit - bmheight) / 2;
|
||||
u = (u < 0) ? x : x + u;
|
||||
v = (v < 0) ? y : y + v;
|
||||
xend = (bmwidth > widthLimit) ? widthLimit : bmwidth;
|
||||
|
||||
bmpRow = (uint16_t *)malloc(xend * 2);
|
||||
if (!bmpRow)
|
||||
{
|
||||
Serial.println(F("bmpRow malloc failed."));
|
||||
}
|
||||
if (bmbpp < 9)
|
||||
{
|
||||
bmplt = (uint16_t *)malloc(bmpltsize * 2);
|
||||
if (!bmplt)
|
||||
{
|
||||
Serial.println(F("bmplt malloc failed."));
|
||||
}
|
||||
bmloadplt(f); //load palette if palettized
|
||||
drawbmpal(f, u, v, xend);
|
||||
free(bmplt);
|
||||
}
|
||||
else if (bmbpp == 16)
|
||||
{
|
||||
// TODO: bpp 16 should have 3 pixel types
|
||||
drawbmRgb565(f, u, v, xend);
|
||||
}
|
||||
else
|
||||
{
|
||||
drawbmtrue(f, u, v, xend);
|
||||
}
|
||||
free(bmpRow);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void bmloadplt(File *f)
|
||||
{
|
||||
byte r, g, b;
|
||||
if (bmpltsize == 0)
|
||||
{
|
||||
bmpltsize = 1 << bmbpp; //load default palette size
|
||||
}
|
||||
f->seek(54); //palette position in type 0x28 bitmaps
|
||||
for (int16_t i = 0; i < bmpltsize; i++)
|
||||
{
|
||||
b = f->read();
|
||||
g = f->read();
|
||||
r = f->read();
|
||||
f->read(); //dummy byte
|
||||
bmplt[i] = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3);
|
||||
}
|
||||
}
|
||||
|
||||
void drawbmpal(File *f, int16_t u, int16_t v, uint32_t xend)
|
||||
{
|
||||
byte bmbitmask;
|
||||
int16_t i, ystart, bmppb, p, d;
|
||||
int16_t x, y;
|
||||
uint16_t c;
|
||||
bmbpl = ((bmbpp * bmwidth + 31) / 32) * 4; //bytes per line
|
||||
bmppb = 8 / bmbpp; //pixels/byte
|
||||
bmbitmask = ((1 << bmbpp) - 1); //mask for each pixel
|
||||
ystart = 0;
|
||||
if (bmheight > _heightLimit)
|
||||
{
|
||||
ystart = bmheight - _heightLimit; //don't draw if it's outside screen
|
||||
}
|
||||
for (y = ystart; y < bmheight; y++)
|
||||
{ //invert in calculation (y=0 is bottom)
|
||||
f->seek(bmdataptr + y * bmbpl); //seek to start of line
|
||||
x = 0;
|
||||
p = 0;
|
||||
while (x < xend)
|
||||
{
|
||||
if (p < 1)
|
||||
{
|
||||
d = f->read();
|
||||
p = bmppb;
|
||||
}
|
||||
d = d << bmbpp;
|
||||
c = bmplt[(bmbitmask & (d >> 8))];
|
||||
bmpRow[x] = (_useBigEndian) ? ((c >> 8) | (c << 8)) : c;
|
||||
|
||||
p--;
|
||||
x++;
|
||||
}
|
||||
_bmpDrawCallback(u, v + bmheight - 1 - y, bmpRow, xend, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// draw 16-bit colour (RGB565) bitmap
|
||||
void drawbmRgb565(File *f, int16_t u, int16_t v, uint32_t xend)
|
||||
{
|
||||
int16_t i, ystart;
|
||||
uint32_t x, y;
|
||||
byte lo, hi;
|
||||
bmbpl = ((bmbpp * bmwidth + 31) / 32) * 4; //bytes per line, due to 32bit chunks
|
||||
ystart = 0;
|
||||
if (bmheight > _heightLimit)
|
||||
{
|
||||
ystart = bmheight - _heightLimit; //don't draw if it's outside screen
|
||||
}
|
||||
Serial.println(xend);
|
||||
for (y = ystart; y < bmheight; y++)
|
||||
{ //invert in calculation (y=0 is bottom)
|
||||
f->seek(bmdataptr + (y * bmbpl)); //seek at start of line
|
||||
for (x = 0; x < xend; x++)
|
||||
{
|
||||
lo = f->read();
|
||||
hi = f->read();
|
||||
if (_useBigEndian)
|
||||
{
|
||||
bmpRow[x] = hi | lo << 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
bmpRow[x] = lo | hi << 8;
|
||||
}
|
||||
}
|
||||
_bmpDrawCallback(u, v + bmheight - 1 - y, bmpRow, xend, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// draw true colour bitmap at (u,v) handles 24/32 not 16bpp yet
|
||||
void drawbmtrue(File *f, int16_t u, int16_t v, uint32_t xend)
|
||||
{
|
||||
int16_t i, ystart;
|
||||
uint32_t x, y;
|
||||
byte r, g, b;
|
||||
bmbpl = ((bmbpp * bmwidth + 31) / 32) * 4; //bytes per line, due to 32bit chunks
|
||||
ystart = 0;
|
||||
if (bmheight > _heightLimit)
|
||||
{
|
||||
ystart = bmheight - _heightLimit; //don't draw if it's outside screen
|
||||
}
|
||||
for (y = ystart; y < bmheight; y++)
|
||||
{ //invert in calculation (y=0 is bottom)
|
||||
f->seek(bmdataptr + y * bmbpl); //seek at start of line
|
||||
for (x = 0; x < xend; x++)
|
||||
{
|
||||
b = f->read();
|
||||
g = f->read();
|
||||
r = f->read();
|
||||
if (bmbpp == 32)
|
||||
{
|
||||
f->read(); //dummy byte for 32bit
|
||||
}
|
||||
bmpRow[x] = (_useBigEndian) ? ((r & 0xf8) | (g >> 5) | ((g & 0x1c) << 11) | ((b & 0xf8) << 5)) : (((r & 0xf8) << 8) | ((g & 0xfc) << 3) | (b >> 3));
|
||||
}
|
||||
_bmpDrawCallback(u, v + bmheight - 1 - y, bmpRow, xend, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void getbmpparms(File *f)
|
||||
{ //load into globals as ints-some parameters are 32 bit, but we can't handle this size anyway
|
||||
byte h[48]; //header is 54 bytes typically, but we don't need it all
|
||||
int16_t i;
|
||||
f->seek(0); //set start of file
|
||||
for (i = 0; i < 48; i++)
|
||||
{
|
||||
h[i] = f->read(); //read header
|
||||
}
|
||||
bmtype = h[0] + (h[1] << 8); //offset 0 'BM'
|
||||
bmdataptr = h[10] + (h[11] << 8); //offset 0xA pointer to image data
|
||||
bmhdrsize = h[14] + (h[15] << 8); //dib header size (0x28 is usual)
|
||||
//files may vary here, if !=28, unsupported type, put default values
|
||||
bmwidth = 0;
|
||||
bmheight = 0;
|
||||
bmbpp = 0;
|
||||
bmpltsize = 0;
|
||||
if ((bmhdrsize == 0x28) || (bmhdrsize == 0x38))
|
||||
{
|
||||
bmwidth = h[18] + (h[19] << 8); //width
|
||||
bmheight = h[22] + (h[23] << 8); //height
|
||||
bmbpp = h[28] + (h[29] << 8); //bits per pixel
|
||||
bmpltsize = h[46] + (h[47] << 8); //palette size
|
||||
}
|
||||
// Serial.printf("bmtype: %d, bmhdrsize: %d, bmwidth: %d, bmheight: %d, bmbpp: %d\n", bmtype, bmhdrsize, bmwidth, bmheight, bmbpp);
|
||||
}
|
||||
|
||||
byte isbmp(char n[])
|
||||
{ //check if bmp extension
|
||||
int16_t k;
|
||||
k = strlen(n);
|
||||
if (k < 5)
|
||||
{
|
||||
return 0; //name not long enough
|
||||
}
|
||||
if (n[k - 1] != 'P')
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (n[k - 2] != 'M')
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (n[k - 3] != 'B')
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (n[k - 4] != '.')
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return 1; //passes all tests
|
||||
}
|
||||
|
||||
BMP_DRAW_CALLBACK *_bmpDrawCallback;
|
||||
bool _useBigEndian;
|
||||
int16_t _heightLimit;
|
||||
|
||||
uint16_t bmtype, bmdataptr; //from header
|
||||
uint32_t bmhdrsize, bmwidth, bmheight, bmbpp, bmpltsize; //from DIB Header
|
||||
uint16_t bmbpl; //bytes per line- derived
|
||||
uint16_t *bmplt; //palette- stored encoded for LCD
|
||||
uint16_t *bmpRow;
|
||||
};
|
||||
|
||||
#endif // _BMPCLASS_H_
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef __INC_BTN_H
|
||||
#define __INC_BTN_H
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#define SR_CLK 0
|
||||
#define SR_DAT 1
|
||||
#define SR_LAT 16
|
||||
|
||||
#define BTN_STICK_UP (1 << 14)
|
||||
#define BTN_STICK_DN (1 << 11)
|
||||
#define BTN_STICK_LF (1 << 12)
|
||||
#define BTN_STICK_RT (1 << 15)
|
||||
#define BTN_STICK_SEL (1 << 13)
|
||||
|
||||
#define BTN_READ0 17
|
||||
#define BTN_READ1 18
|
||||
|
||||
|
||||
uint16_t btn_read();
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,17 @@
|
|||
#ifndef _INC_PNGFILE_H
|
||||
#define _ING_PNGFILE_H
|
||||
|
||||
|
||||
#include <PNGDEC.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <FS.h>
|
||||
|
||||
|
||||
void *png_open(const char *filename, int32_t *size);
|
||||
void png_close(void *handle);
|
||||
int32_t png_read(PNGFILE *handle, uint8_t *buffer, int32_t length);
|
||||
int32_t png_seek(PNGFILE *handle, int32_t position);
|
||||
|
||||
|
||||
#endif
|
|
@ -12,7 +12,6 @@
|
|||
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
|
||||
board = rpipico
|
||||
framework = arduino
|
||||
|
||||
board_build.filesystem_size = 1.4m
|
||||
|
||||
debug_build_flags =
|
||||
|
@ -22,6 +21,7 @@ debug_build_flags =
|
|||
lib_deps =
|
||||
moononournation/GFX Library for Arduino@^1.3.8
|
||||
olikraus/U8g2@^2.35.7
|
||||
bitbank2/PNGdec@^1.0.1
|
||||
|
||||
platform_packages =
|
||||
toolchain-gccarmnoneeabi@1.100301.220327
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
#include <Arduino.h>
|
||||
|
||||
#include "btn.h"
|
||||
|
||||
|
||||
|
||||
uint16_t btn_mask;
|
||||
uint16_t btn_last;
|
||||
uint16_t btn_flip;
|
||||
|
||||
|
||||
|
||||
void sr_send(uint16_t dat)
|
||||
{
|
||||
digitalWrite(SR_LAT, LOW);
|
||||
|
||||
uint16_t mask = 0x8000;
|
||||
|
||||
for (uint8_t i = 0; i < 16; i++) {
|
||||
digitalWrite(SR_DAT, dat & mask ? HIGH : LOW);
|
||||
digitalWrite(SR_CLK, HIGH);
|
||||
mask >>= 1;
|
||||
digitalWrite(SR_CLK, LOW);
|
||||
}
|
||||
|
||||
digitalWrite(SR_LAT, HIGH);
|
||||
__NOP(); __NOP();
|
||||
digitalWrite(SR_LAT, LOW);
|
||||
}
|
||||
|
||||
uint16_t btn_read()
|
||||
{
|
||||
btn_last = btn_mask;
|
||||
|
||||
// read joystick only for now
|
||||
for (uint8_t i = 11; i < 16; i++) {
|
||||
sr_send(1 << i);
|
||||
btn_mask &= ~(1 << i);
|
||||
if (!digitalRead(BTN_READ1)) {
|
||||
btn_mask |= (1 << i);
|
||||
}
|
||||
}
|
||||
|
||||
btn_flip = btn_mask ^ btn_last;
|
||||
|
||||
return btn_flip & btn_mask;
|
||||
}
|
454
src/main.cpp
454
src/main.cpp
|
@ -9,9 +9,22 @@ extern "C" {
|
|||
#include "sin1.h"
|
||||
}
|
||||
|
||||
#include <LittleFS.h>
|
||||
#include <SD.h>
|
||||
|
||||
#include "bmp.h"
|
||||
static BmpClass bmp;
|
||||
File fbmp;
|
||||
|
||||
#include "btn.h"
|
||||
|
||||
|
||||
|
||||
const char name[] = "Your Name";
|
||||
|
||||
uint8_t fgprog = 1; // default
|
||||
uint8_t bgprog = 7; // programs
|
||||
|
||||
|
||||
|
||||
#define SPI0_SCK 2
|
||||
|
@ -30,17 +43,47 @@ const char name[] = "Your Name";
|
|||
|
||||
#define LETTER_SPACING 1942 // user-configurable
|
||||
|
||||
#define MAX_TOASTERS 9
|
||||
#define TOAST_RANDOM 9
|
||||
|
||||
|
||||
Arduino_DataBus *bus = new Arduino_RPiPicoSPI(DISP_DC, DISP_NSS, SPI0_SCK, SPI0_MOSI, SPI0_MISO, spi0);
|
||||
Arduino_GFX *disp = new Arduino_GC9A01(bus, DISP_RESET, 0 /* rotation */, true /* IPS */);
|
||||
|
||||
Arduino_Canvas *dout = new Arduino_Canvas(240 /* width */, 240 /* height */, disp);
|
||||
Arduino_Canvas *drot = new Arduino_Canvas(ROT_SIZE, ROT_SIZE, disp);
|
||||
Arduino_Canvas *drot = new Arduino_Canvas(ROT_SIZE, ROT_SIZE, NULL);
|
||||
Arduino_Canvas *d64 = new Arduino_Canvas(64, 64, NULL);
|
||||
Arduino_Canvas *toastbmp[6] = {
|
||||
new Arduino_Canvas(64, 64, NULL),
|
||||
new Arduino_Canvas(64, 64, NULL),
|
||||
new Arduino_Canvas(64, 64, NULL),
|
||||
new Arduino_Canvas(64, 64, NULL),
|
||||
new Arduino_Canvas(64, 64, NULL),
|
||||
new Arduino_Canvas(64, 64, NULL)
|
||||
};
|
||||
|
||||
color_hsv hsv = {0, 255, 255};
|
||||
color_rgb rgb;
|
||||
|
||||
|
||||
uint8_t toast_cb_idx = 0;
|
||||
static void bmp_cb(int16_t x, int16_t y, uint16_t *bitmap, int16_t w, int16_t h)
|
||||
{
|
||||
uint16_t *src, *dst;
|
||||
|
||||
// Serial.printf("Draw pos = %d, %d. size = %d x %d\n", x, y, w, h);
|
||||
d64->draw16bitRGBBitmap(x, y, bitmap, w, h);
|
||||
|
||||
// was having problems printing directly to the toastbmp buffer
|
||||
// so rendering to temporary one and then copying
|
||||
src = d64->getFramebuffer();
|
||||
dst = toastbmp[toast_cb_idx]->getFramebuffer();
|
||||
|
||||
for (x = 0; x < (64 * 64); x++) {
|
||||
*dst++ = *src++; // [(x % 64) + ((x / 64) * ROT_SIZE)];
|
||||
}
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
@ -51,16 +94,44 @@ void setup()
|
|||
|
||||
bus->begin(90000000);
|
||||
|
||||
if (!disp->begin()) {
|
||||
Serial.println("failed to start disp");
|
||||
}
|
||||
|
||||
disp->begin();
|
||||
|
||||
dout->begin();
|
||||
dout->fillScreen(BLACK);
|
||||
dout->flush();
|
||||
|
||||
drot->begin();
|
||||
drot->setFont(u8g2_font_cubic11_h_cjk); // u8g2_font_spleen16x32_mr
|
||||
|
||||
d64->begin();
|
||||
d64->fillScreen(BLACK);
|
||||
|
||||
// buttons
|
||||
pinMode(SR_CLK, OUTPUT);
|
||||
pinMode(SR_DAT, OUTPUT);
|
||||
pinMode(SR_LAT, OUTPUT);
|
||||
|
||||
pinMode(BTN_READ0, INPUT);
|
||||
pinMode(BTN_READ1, INPUT);
|
||||
|
||||
// filesystem
|
||||
LittleFS.begin();
|
||||
|
||||
// preload toasters
|
||||
char fn[20];
|
||||
for (uint8_t i = 0; i < 6; i++) {
|
||||
// start toast
|
||||
toastbmp[i] = new Arduino_Canvas(64, 64, NULL);
|
||||
toastbmp[i]->begin();
|
||||
toastbmp[i]->fillScreen(BLUE); // should not be visible
|
||||
|
||||
// select toast file
|
||||
sprintf(fn, "toast%i.bmp", i);
|
||||
fbmp = LittleFS.open(fn, "r");
|
||||
toast_cb_idx = i;
|
||||
bmp.draw(&fbmp, bmp_cb, false /* useBigEndian */, 0 /* x */, 0 /* y */, 64, 64);
|
||||
fbmp.close();
|
||||
}
|
||||
}
|
||||
|
||||
int16_t render_drot_printchar(const char *str, uint8_t idx, uint8_t size, uint16_t color)
|
||||
|
@ -123,7 +194,8 @@ void render_drot_border(int8_t x_width, uint16_t text_color, uint16_t border_col
|
|||
}
|
||||
}
|
||||
|
||||
void render_drot_rotate(int16_t x_width, int16_t rot, int16_t out_x, int16_t out_y)
|
||||
/*
|
||||
int16_t render_drot_wobble(int16_t x_width, int16_t rot, uint16_t idx, uint8_t len)
|
||||
{
|
||||
int16_t x, y;
|
||||
int16_t nx, ny;
|
||||
|
@ -132,10 +204,22 @@ void render_drot_rotate(int16_t x_width, int16_t rot, int16_t out_x, int16_t out
|
|||
uint16_t *src, *dst;
|
||||
uint16_t src_pxl;
|
||||
|
||||
uint8_t r;
|
||||
|
||||
r = rot >> 4;
|
||||
|
||||
|
||||
// rotation
|
||||
rx = cos1(rot);
|
||||
rx = (out_x >> 9) + (out_x >> 11) + (out_x >> 12);
|
||||
|
||||
ry = sin1(rot);
|
||||
ry = (out_y >> 9) + (out_y >> 11) + (out_y >> 12);
|
||||
|
||||
// position
|
||||
int16_t start_x = out_x + 120;
|
||||
int16_t start_y = out_y + 120;
|
||||
rot += 0x6000;
|
||||
|
||||
// framebuffer pointers
|
||||
src = drot->getFramebuffer();
|
||||
|
@ -163,55 +247,109 @@ void render_drot_rotate(int16_t x_width, int16_t rot, int16_t out_x, int16_t out
|
|||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
void text_print_circular(const char *str, uint8_t text_size, int16_t spacing, uint16_t fcolor, uint16_t bcolor, int16_t rot)
|
||||
int16_t render_drot_rotate(int16_t x_width, int16_t rot, int16_t idx, uint8_t len)
|
||||
{
|
||||
int16_t x, y;
|
||||
int16_t nx, ny;
|
||||
int16_t sx, sy;
|
||||
|
||||
int16_t out_x, out_y;
|
||||
|
||||
uint16_t *src, *dst;
|
||||
uint16_t src_pxl;
|
||||
|
||||
int16_t spacing;
|
||||
|
||||
|
||||
// spacing
|
||||
spacing = rot - LETTER_SPACING;
|
||||
|
||||
// rotation
|
||||
out_x = cos1(rot);
|
||||
out_x = (out_x >> 9) + (out_x >> 11) + (out_x >> 12);
|
||||
|
||||
out_y = sin1(rot);
|
||||
out_y = (out_y >> 9) + (out_y >> 11) + (out_y >> 12);
|
||||
|
||||
// position
|
||||
int16_t start_x = out_x + 120;
|
||||
int16_t start_y = out_y + 120;
|
||||
rot += 0x6000;
|
||||
|
||||
// framebuffer pointers
|
||||
src = drot->getFramebuffer();
|
||||
dst = dout->getFramebuffer();
|
||||
|
||||
// rotate+copy the buffer
|
||||
for (y = 0; y < ROT_SIZE; y++) {
|
||||
for (x = 0; x < x_width; x++) {
|
||||
src_pxl = src[x + (y * ROT_SIZE)];
|
||||
sx = x + 1 - (x_width >> 1);
|
||||
sy = y - (ROT_SIZE/2) + 1;
|
||||
if (src_pxl != TRANSPARENT_BG) {
|
||||
nx = ((sx * cos1(rot)) - (sy * sin1(rot))) >> 15;
|
||||
ny = ((sx * sin1(rot)) + (sy * cos1(rot))) >> 15;
|
||||
|
||||
nx += start_x;
|
||||
ny += start_y;
|
||||
|
||||
if ((nx >= 0) && (nx < 240)) {
|
||||
if ((ny >= 0) && (ny < 240)) {
|
||||
dst[nx + (ny*240)] = src_pxl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return spacing;
|
||||
}
|
||||
|
||||
void text_print_standard(
|
||||
const char *str,
|
||||
uint8_t text_size,
|
||||
uint16_t fcolor,
|
||||
uint16_t bcolor,
|
||||
int16_t (*render)(int16_t, int16_t, int16_t, uint8_t),
|
||||
int16_t rot)
|
||||
{
|
||||
uint8_t i;
|
||||
int16_t x_width;
|
||||
|
||||
int16_t x, y;
|
||||
int16_t out_x, out_y;
|
||||
int16_t x_width;
|
||||
|
||||
if (text_size > TEXT_MAX_SIZE) text_size = TEXT_MAX_SIZE;
|
||||
drot->setTextSize(text_size);
|
||||
|
||||
for (i = 0; i < strlen(name); i++) {
|
||||
x = cos1(rot);
|
||||
x = (x >> 9) + (x >> 11) + (x >> 12);
|
||||
|
||||
y = sin1(rot);
|
||||
y = (y >> 9) + (y >> 11) + (y >> 12);
|
||||
|
||||
for (i = 0; i < strlen(str); i++) {
|
||||
x_width = render_drot_printchar(str, i, text_size, fcolor); // render character
|
||||
render_drot_border(x_width, fcolor, bcolor); // add border to character
|
||||
render_drot_rotate(x_width, rot + 0x6000, x, y);
|
||||
rot -= spacing;
|
||||
if (render) {
|
||||
rot = render(x_width, rot, i, strlen(str));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int16_t trot = 0;
|
||||
int16_t brot = 0;
|
||||
|
||||
#define HUE_MIN 0x2000-300
|
||||
#define HUE_MAX 0x2000+300
|
||||
#define HUE_STEP 3
|
||||
|
||||
int16_t huecycle = 0;
|
||||
uint8_t huedir = 0;
|
||||
int16_t satcycle = 0;
|
||||
uint8_t satdir = 0;
|
||||
|
||||
void bg_huesatcycle()
|
||||
void bg_huesatcycle(uint16_t hue_max, uint16_t hue_min, uint16_t hue_step)
|
||||
{
|
||||
dout->fillScreen(BLACK);
|
||||
|
||||
// hue between limits
|
||||
if (!huedir) huecycle += HUE_STEP; else huecycle -= HUE_STEP;
|
||||
if (huecycle > HUE_MAX) {
|
||||
huedir = 1; huecycle = HUE_MAX;
|
||||
if (!huedir) huecycle += hue_step; else huecycle -= hue_step;
|
||||
if (huecycle > hue_max) {
|
||||
huedir = 1; huecycle = hue_max;
|
||||
}
|
||||
if (huecycle < HUE_MIN) {
|
||||
huedir = 0; huecycle = HUE_MIN;
|
||||
if (huecycle < hue_min) {
|
||||
huedir = 0; huecycle = hue_min;
|
||||
}
|
||||
|
||||
// saturation
|
||||
|
@ -238,9 +376,10 @@ void bg_huesatcycle()
|
|||
}
|
||||
}
|
||||
|
||||
void bg_rainbow_circles(uint8_t saturation)
|
||||
void bg_rainbow_circles(uint8_t saturation, uint16_t hue_offset, uint8_t tunnelmode, uint16_t fillcolor)
|
||||
{
|
||||
uint16_t hue;
|
||||
uint8_t val;
|
||||
|
||||
// speed
|
||||
hsv.h += 24;
|
||||
|
@ -250,20 +389,17 @@ void bg_rainbow_circles(uint8_t saturation)
|
|||
// hsv.h %= 1536;
|
||||
// hsv2rgb_8b(hue, 255, 128, &rgb.r, &rgb.g, &rgb.b);
|
||||
// dout->fillScreen(dout->color565(rgb.r, rgb.g, rgb.b));
|
||||
dout->fillScreen(BLACK);
|
||||
dout->fillScreen(fillcolor);
|
||||
|
||||
// draw some circles
|
||||
hue = hsv.h;
|
||||
for (int8_t i = 120; i > 0; i--) {
|
||||
hue += 2;
|
||||
hue += hue_offset;
|
||||
hue %= 1536;
|
||||
|
||||
// "flat" mode, same brightness
|
||||
hsv2rgb_8b(hue, saturation, 192, &rgb.r, &rgb.g, &rgb.b);
|
||||
|
||||
// "tunnel" mode, darker center
|
||||
// hsv2rgb_8b(hue, saturation, (i * 2), &rgb.r, &rgb.g, &rgb.b);
|
||||
|
||||
val = tunnelmode ? (i * 2) : 192;
|
||||
|
||||
hsv2rgb_8b(hue, saturation, val, &rgb.r, &rgb.g, &rgb.b);
|
||||
dout->drawCircle(120, 120, i, dout->color565(rgb.r, rgb.g, rgb.b));
|
||||
}
|
||||
}
|
||||
|
@ -301,22 +437,126 @@ void bg_radarsweep(int16_t rot, int16_t offset, uint8_t lines)
|
|||
}
|
||||
}
|
||||
|
||||
void texthue_180degree()
|
||||
|
||||
struct Toasters {
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
uint16_t speed;
|
||||
uint8_t type;
|
||||
uint8_t frame;
|
||||
} Toasters;
|
||||
|
||||
|
||||
static struct Toasters toast[MAX_TOASTERS];
|
||||
uint8_t toaster_count;
|
||||
uint8_t toaster_frametimer;
|
||||
|
||||
|
||||
void print_toast(uint8_t idx, int16_t out_x, int16_t out_y)
|
||||
{
|
||||
int16_t x, y;
|
||||
int16_t nx, ny;
|
||||
|
||||
uint16_t *src, *dst;
|
||||
|
||||
uint16_t src_pxl;
|
||||
|
||||
uint8_t frame = toast[idx].frame;
|
||||
|
||||
// framebuffer pointers
|
||||
src = toastbmp[frame]->getFramebuffer();
|
||||
dst = dout->getFramebuffer();
|
||||
|
||||
// copy to destination with transparency
|
||||
for (y = 0; y < 64; y++) {
|
||||
for (x = 0; x < 64; x++) {
|
||||
src_pxl = src[x + (y * 64)];
|
||||
if (src_pxl != TRANSPARENT_BG) {
|
||||
nx = x + out_x;
|
||||
ny = y + out_y;
|
||||
|
||||
if ((nx < 0) || (ny < 0)) continue;
|
||||
if ((nx >= 240) || (ny >= 240)) continue;
|
||||
|
||||
dst[nx + (ny*240)] = src_pxl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void bg_toasters()
|
||||
{
|
||||
uint16_t i;
|
||||
|
||||
// frame counter
|
||||
toaster_frametimer++;
|
||||
if (toaster_frametimer >= 2) {
|
||||
toaster_frametimer = 0;
|
||||
for (i = 0; i < MAX_TOASTERS; i++) {
|
||||
if (toast[i].type) {
|
||||
toast[i].frame++;
|
||||
if (toast[i].frame >= 6) toast[i].frame = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// clear screen
|
||||
dout->fillScreen(BLACK);
|
||||
|
||||
// determine if we are doing new toasts
|
||||
if (random(200) < TOAST_RANDOM) {
|
||||
for (i = 0; i < MAX_TOASTERS; i++) {
|
||||
if (!toast[i].type) {
|
||||
toast[i].type = 1;
|
||||
toast[i].frame = 0;
|
||||
toast[i].x = 240;
|
||||
toast[i].y = 64 - random(240);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < MAX_TOASTERS; i++) {
|
||||
switch (toast[i].type) {
|
||||
case 0: continue;
|
||||
case 1: { // normal toast
|
||||
if (toast[i].x < -64) {
|
||||
// toast is toasted
|
||||
toast[i].type = 0;
|
||||
} else {
|
||||
// move toast
|
||||
toast[i].x -= 3;
|
||||
toast[i].y += 2;
|
||||
|
||||
print_toast(i, toast[i].x, toast[i].y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void texthue_180degree(color_rgb *fc, color_rgb *bc)
|
||||
{
|
||||
uint16_t hue;
|
||||
|
||||
hue = hsv.h + 768;
|
||||
hue %= 1536;
|
||||
hsv2rgb_8b(hue, 224, 64, &rgb.r, &rgb.g, &rgb.b);
|
||||
hsv2rgb_8b(hue, 224, 64, &fc->r, &fc->g, &fc->b);
|
||||
|
||||
// white border, screw it
|
||||
bc->r = bc->g = bc->b = 255;
|
||||
}
|
||||
|
||||
void texthue_huesatcycle_circles()
|
||||
void texthue_huesatcycle(color_rgb *fc, color_rgb *bc)
|
||||
{
|
||||
uint16_t hue;
|
||||
|
||||
hue = (huecycle - 0x2000);
|
||||
if (hue > (1536 << 3)) hue += (1536 << 3);
|
||||
hsv2rgb_8b(hue >> 3, 224, 64, &rgb.r, &rgb.g, &rgb.b);
|
||||
hsv2rgb_8b(hue >> 3, 224, 64, &fc->r, &fc->g, &fc->b);
|
||||
|
||||
// white border, screw it
|
||||
bc->r = bc->g = bc->b = 255;
|
||||
}
|
||||
|
||||
|
||||
|
@ -325,24 +565,126 @@ void loop()
|
|||
uint16_t hue;
|
||||
color_rgb fc, bc;
|
||||
|
||||
// rainbow circles program
|
||||
// bg_rainbow_circles(200);
|
||||
// texthue_180degree();
|
||||
brot += 400;
|
||||
bg_radarsweep(brot, 25, 200);
|
||||
switch (bgprog) {
|
||||
case 0: { // rainbow
|
||||
bg_rainbow_circles(200, 2, 0, BLACK);
|
||||
texthue_180degree(&fc, &bc);
|
||||
break;
|
||||
}
|
||||
case 1: { // more colorful rainbow
|
||||
hue = hsv.h;
|
||||
hue += 768;
|
||||
hue %= 1536;
|
||||
hsv2rgb_8b(hue, 255, 128, &fc.r, &fc.g, &fc.b);
|
||||
bg_rainbow_circles(200, 6, 0, dout->color565(fc.r, fc.g, fc.b));
|
||||
texthue_180degree(&fc, &bc);
|
||||
break;
|
||||
}
|
||||
case 2: { // rainbow tunnel
|
||||
bg_rainbow_circles(200, 2, 1, BLACK);
|
||||
texthue_180degree(&fc, &bc);
|
||||
break;
|
||||
}
|
||||
|
||||
// small hue shift with larger saturation shifts circles
|
||||
// bg_huesatcycle_circles();
|
||||
// texthue_huesatcycle();
|
||||
case 3: { // desat red tunnel
|
||||
bg_huesatcycle(0x0000, 0x0300, 3);
|
||||
texthue_huesatcycle(&fc, &bc);
|
||||
break;
|
||||
}
|
||||
case 4: { // desat green tunnel
|
||||
bg_huesatcycle(0x0d00, 0x1300, 3);
|
||||
texthue_huesatcycle(&fc, &bc);
|
||||
break;
|
||||
}
|
||||
case 5: { // desat blue tunnel
|
||||
bg_huesatcycle(0x1d00, 0x2300, 3);
|
||||
texthue_huesatcycle(&fc, &bc);
|
||||
break;
|
||||
}
|
||||
|
||||
// text rotation - black text, default border
|
||||
trot += 420 - 69;
|
||||
fc.r = fc.g = fc.b = 240;
|
||||
bc.r = bc.g = bc.b = 32;
|
||||
text_print_circular(name, TEXT_MAX_SIZE, LETTER_SPACING,
|
||||
case 6: { // radar sweep
|
||||
brot += 400;
|
||||
bg_radarsweep(brot, 25, 200);
|
||||
fc.r = fc.g = fc.b = 240;
|
||||
bc.r = bc.g = bc.b = 32;
|
||||
break;
|
||||
}
|
||||
|
||||
case 7: { // toasters
|
||||
bg_toasters();
|
||||
fc.r = fc.g = fc.b = 240;
|
||||
bc.r = bc.g = bc.b = 32;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (fgprog) {
|
||||
case 0: { // circular rotation text
|
||||
trot += 100;
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
trot += 420 - 69;
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
trot += 888;
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
trot += 1500;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
text_print_standard(name, TEXT_MAX_SIZE,
|
||||
dout->color565(fc.r, fc.g, fc.b),
|
||||
dout->color565(bc.r, bc.g, bc.b),
|
||||
trot);
|
||||
&render_drot_rotate, trot);
|
||||
|
||||
/*
|
||||
case 2: { // sine loop
|
||||
text_print_standard(name, TEXT_MAX_SIZE,
|
||||
dout->color565(fc.r, fc.g, fc.b),
|
||||
dout->color565(bc.r, bc.g, bc.b),
|
||||
&render_drot_wobble, trot);
|
||||
}
|
||||
}
|
||||
|
||||
case 3: { // wobbly + sine loop
|
||||
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
dout->flush();
|
||||
|
||||
// read buttons
|
||||
uint16_t btn;
|
||||
btn = btn_read();
|
||||
|
||||
switch (btn) {
|
||||
case BTN_STICK_UP: {
|
||||
bgprog++;
|
||||
bgprog %= 8;
|
||||
break;
|
||||
}
|
||||
case BTN_STICK_DN: {
|
||||
if (!bgprog) {
|
||||
bgprog = 7;
|
||||
} else bgprog--;
|
||||
break;
|
||||
}
|
||||
|
||||
case BTN_STICK_RT: {
|
||||
fgprog++;
|
||||
fgprog %= 4;
|
||||
break;
|
||||
}
|
||||
case BTN_STICK_LF: {
|
||||
if (!fgprog) {
|
||||
fgprog = 3;
|
||||
} else fgprog--;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
#include "pngfile.h"
|
||||
#include <LittleFS.h>
|
||||
|
||||
|
||||
File fpng;
|
||||
|
||||
|
||||
void *png_open(const char *filename, int32_t *size)
|
||||
{
|
||||
fpng = LittleFS.open(filename, "r");
|
||||
|
||||
if (!fpng || fpng.isDirectory()) {
|
||||
// error
|
||||
} else {
|
||||
// good
|
||||
}
|
||||
|
||||
return &fpng;
|
||||
}
|
||||
|
||||
void png_close(void *handle)
|
||||
{
|
||||
if (fpng) fpng.close();
|
||||
}
|
||||
|
||||
int32_t png_read(PNGFILE *handle, uint8_t *buffer, int32_t length)
|
||||
{
|
||||
if (!fpng) return 0;
|
||||
|
||||
Serial.println("png: read");
|
||||
|
||||
return fpng.read(buffer, length);
|
||||
}
|
||||
|
||||
int32_t png_seek(PNGFILE *handle, int32_t position)
|
||||
{
|
||||
if (!fpng) return 0;
|
||||
|
||||
Serial.printf("png: seek %i\n", position);
|
||||
|
||||
return fpng.seek(position);
|
||||
}
|
Loading…
Reference in New Issue