Skip to content

Commit 5d40c9d

Browse files
committed
generalize for any size display
1 parent 9250270 commit 5d40c9d

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

Factory_Tests/Qualia_ESP32S3_RGB666_FactoryTest/Qualia_ESP32S3_RGB666_FactoryTest.ino

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ Arduino_RGB_Display *gfx = new Arduino_RGB_Display(
3434
// 480 /* width */, 480 /* height */, rgbpanel, 0 /* rotation */, true /* auto_flush */,
3535
// expander, GFX_NOT_DEFINED /* RST */, tl034wvs05_b1477a_init_operations, sizeof(tl034wvs05_b1477a_init_operations));
3636

37+
// 3.2" 320x820 rectangle bar display
38+
// 320 /* width */, 820 /* height */, rgbpanel, 0 /* rotation */, true /* auto_flush */,
39+
// expander, GFX_NOT_DEFINED /* RST */, tl032fwv01_init_operations, sizeof(tl032fwv01_init_operations));
40+
3741
uint16_t *colorWheel;
3842

3943
void setup(void)
@@ -61,7 +65,7 @@ void setup(void)
6165
expander->digitalWrite(PCA_TFT_BACKLIGHT, HIGH);
6266

6367
TB.begin();
64-
colorWheel = (uint16_t *) ps_malloc(480 * 480 * sizeof(uint16_t));
68+
colorWheel = (uint16_t *) ps_malloc(gfx->width() * gfx->height() * sizeof(uint16_t));
6569
if (colorWheel) generateColorWheel(colorWheel);
6670
}
6771

@@ -70,29 +74,34 @@ uint8_t allpins[] = {SS, SCK, MOSI, MISO, A1, A0};
7074

7175
void loop()
7276
{
73-
gfx->draw16bitRGBBitmap(0, 0, colorWheel, 480, 480);
77+
gfx->draw16bitRGBBitmap(0, 0, colorWheel, gfx->width(), gfx->height());
7478
delay(100);
7579
return;
7680
}
7781

7882
// https://chat.openai.com/share/8edee522-7875-444f-9fea-ae93a8dfa4ec
7983
void generateColorWheel(uint16_t *colorWheel) {
84+
int width = gfx->width();
85+
int height = gfx->height();
86+
int half_width = width / 2;
87+
int half_height = height / 2;
8088
float angle;
8189
uint8_t r, g, b;
82-
int scaled_index;
90+
int index, scaled_index;
8391

84-
for(int y = 0; y < 240; y++) {
85-
for(int x = 0; x < 240; x++) {
86-
angle = atan2(y - 120, x - 120);
92+
for(int y = 0; y < half_height; y++) {
93+
for(int x = 0; x < half_width; x++) {
94+
index = y * half_width + x;
95+
angle = atan2(y - half_height / 2, x - half_width / 2);
8796
r = uint8_t(127.5 * (cos(angle) + 1));
8897
g = uint8_t(127.5 * (sin(angle) + 1));
8998
b = uint8_t(255 - (r + g) / 2);
9099
uint16_t color = RGB565(r, g, b);
91100

92-
// Scale this pixel into 4 pixels in the 480x480 buffer
101+
// Scale this pixel into 4 pixels in the full buffer
93102
for(int dy = 0; dy < 2; dy++) {
94103
for(int dx = 0; dx < 2; dx++) {
95-
scaled_index = (y * 2 + dy) * 480 + (x * 2 + dx);
104+
scaled_index = (y * 2 + dy) * width + (x * 2 + dx);
96105
colorWheel[scaled_index] = color;
97106
}
98107
}

0 commit comments

Comments
 (0)