aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgamerdonkey2024-08-30 16:09:56 -0500
committergamerdonkey2024-08-30 16:09:56 -0500
commit17312be86b2b22f461bedc4469da8878ec793aa7 (patch)
treee5f5b8296323b3676069d3c2280998e0aee3e0b3
parent844c3c8f671c83cf2d9b39831d7873cb0615fba0 (diff)
downloadesp32-inova-led-controller-17312be86b2b22f461bedc4469da8878ec793aa7.tar.gz
esp32-inova-led-controller-17312be86b2b22f461bedc4469da8878ec793aa7.tar.bz2
esp32-inova-led-controller-17312be86b2b22f461bedc4469da8878ec793aa7.zip
Refactoring how we draw on the display.
-rw-r--r--main/main.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/main/main.c b/main/main.c
index f2822a8..97a78b5 100644
--- a/main/main.c
+++ b/main/main.c
@@ -33,14 +33,24 @@
static uint16_t pattern[NUM_ROW][NUM_COL / 8]; // each column is two bits, so 8 can fit in 16-bit integer
-void draw_char_at_position(char character, uint16_t col_start, uint16_t row_start, uint16_t color) {
+void setPixel(uint16_t x, uint16_t y, uint16_t color) {
+ pattern[y][x / 8] = pattern[y][x / 8] & ~(0b0000000000000011 << (2 * (x % 8))); // clear this column (note the bitwise inversion)
+ pattern[y][x / 8] = pattern[y][x / 8] | (color << (2 * (x % 8))); // write color to column
+}
+
+
+void drawCharAtPosition(char character, int x_start, int y_start, uint16_t color) {
uint8_t cur_char_row;
- for(int row = row_start; (row - row_start) < CHAR_HEIGHT && row < NUM_ROW; row++) {
- cur_char_row = atascii_font[(uint8_t) character][row - row_start];
- for(int col = col_start; (col - col_start) < CHAR_WIDTH && col < NUM_COL; col++) {
- pattern[row][col / 8] = (pattern[row][col / 8] & ~(0b0000000000000011 << (2 * (col - col_start)))); // clear this column (note the bitwise inversion)
- if((1 << (col - col_start)) & cur_char_row) {
- pattern[row][col / 8] = ((pattern[row][col / 8]) | color << (2 * (col - col_start))); // write color to column
+ for(int y = y_start; (y - y_start) < CHAR_HEIGHT && y < NUM_ROW; y++) {
+ cur_char_row = atascii_font[(uint8_t) character][y - y_start];
+ for(int x = x_start; (x - x_start) < CHAR_WIDTH && x < NUM_COL; x++) {
+ if(x >= 0) {
+ if((1 << (x - x_start)) & cur_char_row) {
+ setPixel(x, y, color);
+ }
+ else {
+ setPixel(x, y, 0);
+ }
}
}
}
@@ -145,13 +155,13 @@ void app_main(void)
char* hello = "Hello World!!";
for(int i = 0; i < strlen(hello); i++) {
- draw_char_at_position(hello[i], i * CHAR_WIDTH, 0, j % 2 + 1);
+ drawCharAtPosition(hello[i], i * CHAR_WIDTH, 0, j % 2 + 1);
}
char* numbers = "0123456789";
int offset = strlen(hello) + 1;
for(int i = 0; i < strlen(numbers); i++) {
- draw_char_at_position(numbers[i], (i + offset) * CHAR_WIDTH, 0, j % 2 + 2);
+ drawCharAtPosition(numbers[i], (i + offset) * CHAR_WIDTH, 0, j % 2 + 2);
}
j++;