From 0726cbe25f82ef79f089688bcd38cac29b2e7898 Mon Sep 17 00:00:00 2001 From: true Date: Sat, 4 Nov 2023 09:51:00 -0700 Subject: [PATCH] Remove dead code; clean up programs --- src/main.cpp | 251 ++++++++++++++++++++------------------------------- 1 file changed, 96 insertions(+), 155 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 57ae560..b5e62c4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,18 +1,16 @@ #include #include "SPI.h" -// #include "GC9A01.h" #include #include extern "C" { #include "hsv2rgb.h" #include "sin1.h" -#include "sin7.h" } -const char name[] = "true"; +const char name[] = "Your Name"; @@ -41,143 +39,6 @@ color_hsv hsv = {0, 255, 255}; color_rgb rgb; -/* -void GC9A01_set_reset(uint8_t val) { - digitalWrite(DISP_RESET, val); -} - -void GC9A01_set_data_command(uint8_t val) { - digitalWrite(DISP_DC, val); -} - -void GC9A01_set_chip_select(uint8_t val) { - digitalWrite(DISP_NSS, val); -} - -void GC9A01_spi_tx(uint8_t *data, size_t len) { - while (len--) { - SPI.transfer(*data); - data++; - } -} - -void GC9A01_delay(uint16_t ms) { - delay(ms); -} - -void setup() { - - pinMode(DISP_RESET, OUTPUT); - pinMode(DISP_DC, OUTPUT); - pinMode(DISP_NSS, OUTPUT); - - SPI.setRX(SPI0_MISO); - SPI.setSCK(SPI0_SCK); - SPI.setTX(SPI0_MOSI); - - SPI.begin(); - - GC9A01_init(); - struct GC9A01_frame frame = {{0,0},{239,239}}; - GC9A01_set_frame(frame); -} - -void loop() { - uint8_t color[3]; - - // Triangle - color[0] = 0xFF; - color[1] = 0xFF; - for (int x = 0; x < 240; x++) { - for (int y = 0; y < 240; y++) { - if (x < y) { - color[2] = 0xFF; - } else { - color[2] = 0x00; - } - if (x == 0 && y == 0) { - GC9A01_write(color, sizeof(color)); - } else { - GC9A01_write_continue(color, sizeof(color)); - } - } - } - - delay(1000); - - // Rainbow - float frequency = 0.026; - for (int x = 0; x < 240; x++) { - color[0] = sin(frequency*x + 0) * 127 + 128; - color[1] = sin(frequency*x + 2) * 127 + 128; - color[2] = sin(frequency*x + 4) * 127 + 128; - for (int y = 0; y < 240; y++) { - if (x == 0 && y == 0) { - GC9A01_write(color, sizeof(color)); - } else { - GC9A01_write_continue(color, sizeof(color)); - } - } - } - - delay(1000); - - // Checkerboard - for (int x = 0; x < 240; x++) { - for (int y = 0; y < 240; y++) { - if ((x / 10) % 2 == (y / 10) % 2) { - color[0] = 0xFF; - color[1] = 0xFF; - color[2] = 0xFF; - } else { - color[0] = 0x00; - color[1] = 0x00; - color[2] = 0x00; - } - if (x == 0 && y == 0) { - GC9A01_write(color, sizeof(color)); - } else { - GC9A01_write_continue(color, sizeof(color)); - } - } - } - - delay(1000); -} -*/ - -#define FONT_JUMPTABLE_BYTES 4 - -#define FONT_JUMPTABLE_MSB 0 -#define FONT_JUMPTABLE_LSB 1 -#define FONT_JUMPTABLE_SIZE 2 -#define FONT_JUMPTABLE_WIDTH 3 -#define FONT_JUMPTABLE_START 4 - -#define FONT_WIDTH_POS 0 -#define FONT_HEIGHT_POS 1 -#define FONT_FIRST_CHAR_POS 2 -#define FONT_CHAR_NUM_POS 3 - -int16_t font_get_str_width(const uint8_t *font, const char *str, uint8_t len, int8_t extra_spacing) -{ - uint8_t first = font[FONT_FIRST_CHAR_POS]; - uint8_t chr_width; - uint8_t str_width = 0; - uint8_t w; - - w = len; - - while (w--) { - chr_width = font[FONT_JUMPTABLE_START + (str[w] - first) * FONT_JUMPTABLE_BYTES + FONT_JUMPTABLE_WIDTH]; - str_width += chr_width; - } - - str_width += extra_spacing * (len - 1); - - return str_width; -} - void setup() { Serial.begin(115200); @@ -257,33 +118,113 @@ void rotate_letter(uint8_t idx, int16_t rot, int16_t out_x, int16_t out_y, uint1 int16_t rot = 0; -void loop() +#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() { - uint16_t hue; - - hsv.h += 24; - - // background fill - hue = hsv.h + 512; - 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); - hue = hsv.h; - + // hue between limits + 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; + } + + // saturation + if (!satdir) satcycle++; else satcycle--; + if (satcycle > 240) { + satdir = 1; + satcycle = 240; + } + if (satcycle < 20) { + satdir = 0; + satcycle = 60; + } + + hsv.h = huecycle >> 3; + hsv.s = satcycle; + + // draw some circles for (int8_t i = 120; i > 0; i--) { - hue += 2; - hue %= 1536; - hsv2rgb_8b(hue, 220, (i * 2), &rgb.r, &rgb.g, &rgb.b); + hsv.h += 2; + hsv.h %= 1536; + hsv2rgb_8b(hsv.h, hsv.s, (i * 2), &rgb.r, &rgb.g, &rgb.b); dout->drawCircle(120, 120, i, dout->color565(rgb.r, rgb.g, rgb.b)); } +} + +void bg_rainbow_circles(uint8_t saturation) +{ + uint16_t hue; + + // speed + hsv.h += 24; + + // background fill ("X" pattern) + // hue = hsv.h + 512; + // hsv.h %= 1536; + // hsv2rgb_8b(hue, 255, 128, &rgb.r, &rgb.g, &rgb.b); + // dout->fillScreen(dout->color565(rgb.r, rgb.g, rgb.b)); + + // draw some circles + hue = hsv.h; + for (int8_t i = 120; i > 0; i--) { + hue += 2; + 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); + + dout->drawCircle(120, 120, i, dout->color565(rgb.r, rgb.g, rgb.b)); + } +} + +void texthue_180degree() +{ + uint16_t hue; hue = hsv.h + 768; hue %= 1536; hsv2rgb_8b(hue, 224, 64, &rgb.r, &rgb.g, &rgb.b); +} +void texthue_huesatcycle_circles() +{ + 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); +} + + +void loop() +{ + uint16_t hue; + + // rainbow circles program + bg_rainbow_circles(200); + texthue_180degree(); + + // small hue shift with larger saturation shifts circles + // bg_huesatcycle_circles(); + // texthue_huesatcycle(); + + // text rotation rot += 420 - 69; int16_t x, y;