Multiple program support
This commit is contained in:
parent
e3f23a1427
commit
7013cac8f1
132
src/main.cpp
132
src/main.cpp
|
@ -12,6 +12,9 @@ extern "C" {
|
|||
|
||||
const char name[] = "Your Name";
|
||||
|
||||
uint8_t fgprog = 0;
|
||||
uint8_t bgprog = 6;
|
||||
|
||||
|
||||
|
||||
#define SPI0_SCK 2
|
||||
|
@ -192,26 +195,22 @@ void text_print_circular(const char *str, uint8_t text_size, int16_t spacing, ui
|
|||
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 +237,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 +250,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 +298,28 @@ void bg_radarsweep(int16_t rot, int16_t offset, uint8_t lines)
|
|||
}
|
||||
}
|
||||
|
||||
void texthue_180degree()
|
||||
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 +328,75 @@ 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,
|
||||
dout->color565(fc.r, fc.g, fc.b),
|
||||
dout->color565(bc.r, bc.g, bc.b),
|
||||
trot);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
switch (fgprog) {
|
||||
case 0: { // circular rotation text
|
||||
trot += 420 - 69;
|
||||
|
||||
text_print_circular(name, TEXT_MAX_SIZE, LETTER_SPACING,
|
||||
dout->color565(fc.r, fc.g, fc.b),
|
||||
dout->color565(bc.r, bc.g, bc.b),
|
||||
trot);
|
||||
|
||||
break;
|
||||
}
|
||||
case 1: { // wobbly
|
||||
|
||||
}
|
||||
|
||||
case 2: { // sine loop
|
||||
|
||||
}
|
||||
|
||||
case 3: { // wobbly + sine loop
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
dout->flush();
|
||||
}
|
Loading…
Reference in New Issue