From 43c12c65a5ab95776e1c28f9403d456ff3266488 Mon Sep 17 00:00:00 2001 From: radex Date: Thu, 22 Feb 2024 15:09:10 +0100 Subject: [PATCH] custom characters contd --- firmware/src/characters.cpp | 155 ++++++++++++++++++++++++++++++++++++ firmware/src/characters.h | 24 ++++++ firmware/src/debug.cpp | 14 ++-- firmware/src/screen.cpp | 83 +++---------------- 4 files changed, 198 insertions(+), 78 deletions(-) create mode 100644 firmware/src/characters.cpp create mode 100644 firmware/src/characters.h diff --git a/firmware/src/characters.cpp b/firmware/src/characters.cpp new file mode 100644 index 0000000..18885f2 --- /dev/null +++ b/firmware/src/characters.cpp @@ -0,0 +1,155 @@ +#include "characters.h" + +uint8_t invertedA[8] = { + 0b11111, + 0b10001, + 0b10101, + 0b10001, + 0b10101, + 0b10101, + 0b11111, + 0b00000, +}; + +uint8_t invertedB[8] = { + 0b11111, + 0b10011, + 0b10101, + 0b10011, + 0b10101, + 0b10011, + 0b11111, + 0b00000, +}; + +uint8_t invertedC[8] = { + 0b11111, + 0b11001, + 0b10111, + 0b10111, + 0b10111, + 0b11001, + 0b11111, + 0b00000, +}; + +uint8_t invertedD[8] = { + 0b11111, + 0b10011, + 0b10101, + 0b10101, + 0b10101, + 0b10011, + 0b11111, + 0b00000, +}; + +uint8_t encoder[8] = { + 0b01110, + 0b10001, + 0b00011, + 0b11000, + 0b10001, + 0b01110, + 0b00000, + 0b00000, +}; + +uint8_t encoderSwitch[8] = { + 0b00000, + 0b01110, + 0b10001, + 0b10101, + 0b10001, + 0b01110, + 0b00000, + 0b00000, +}; + +uint8_t progressLeftMask[8] = { + 0b10000, + 0b00000, + 0b00000, + 0b00000, + 0b00000, + 0b00000, + 0b10000, + 0b00000, +}; + +uint8_t progressRightMask[8] = { + 0b00001, + 0b00000, + 0b00000, + 0b00000, + 0b00000, + 0b00000, + 0b00001, + 0b00000, +}; + +uint8_t progress0[8] = { + 0b11111, + 0b00000, + 0b00000, + 0b00000, + 0b00000, + 0b00000, + 0b11111, + 0b00000, +}; + +uint8_t progress1[8] = { + 0b11111, + 0b10000, + 0b10000, + 0b10000, + 0b10000, + 0b10000, + 0b11111, + 0b00000, +}; + +uint8_t progress2[8] = { + 0b11111, + 0b11000, + 0b11000, + 0b11000, + 0b11000, + 0b11000, + 0b11111, + 0b00000, +}; + +uint8_t progress3[8] = { + 0b11111, + 0b11100, + 0b11100, + 0b11100, + 0b11100, + 0b11100, + 0b11111, + 0b00000, +}; + +uint8_t progress4[8] = { + 0b11111, + 0b11110, + 0b11110, + 0b11110, + 0b11110, + 0b11110, + 0b11111, + 0b00000, +}; + +uint8_t progress5[8] = { + 0b11111, + 0b11111, + 0b11111, + 0b11111, + 0b11111, + 0b11111, + 0b11111, + 0b00000, +}; diff --git a/firmware/src/characters.h b/firmware/src/characters.h new file mode 100644 index 0000000..0539a2d --- /dev/null +++ b/firmware/src/characters.h @@ -0,0 +1,24 @@ +#pragma once +#include + +#define CHAR_INVERTED_A 0 +#define CHAR_INVERTED_B 1 +#define CHAR_INVERTED_C 2 +#define CHAR_INVERTED_D 3 +#define CHAR_ENCODER 4 +#define CHAR_ENCODER_SWITCH 5 + +extern uint8_t invertedA[8]; +extern uint8_t invertedB[8]; +extern uint8_t invertedC[8]; +extern uint8_t invertedD[8]; +extern uint8_t encoder[8]; +extern uint8_t encoderSwitch[8]; +extern uint8_t progressLeftMask[8]; +extern uint8_t progressRightMask[8]; +extern uint8_t progress0[8]; +extern uint8_t progress1[8]; +extern uint8_t progress2[8]; +extern uint8_t progress3[8]; +extern uint8_t progress4[8]; +extern uint8_t progress5[8]; diff --git a/firmware/src/debug.cpp b/firmware/src/debug.cpp index 0c148c8..cc62b3c 100644 --- a/firmware/src/debug.cpp +++ b/firmware/src/debug.cpp @@ -9,6 +9,7 @@ I2CScanner scanner; #include "keyboard.h" #include "stepper.h" #include "input.h" +#include "characters.h" void setupDebug() { pinMode(LED_BUILTIN, OUTPUT); @@ -50,6 +51,7 @@ char getDebugKey() { } void handleDebugFunctions(char key) { + if (key){lcd.write(key);} if (key == 'h') { Serial.println("Debug functions:"); Serial.println(" h - print this help"); @@ -95,12 +97,12 @@ void handleDebugFunctions(char key) { quickAccelerate(); } else if (key == '\\') { lcd.clear(); - lcd.write(0); - lcd.write(1); - lcd.write(2); - lcd.write(3); - lcd.write(4); - lcd.write(5); + lcd.write(CHAR_INVERTED_A); + lcd.write(CHAR_INVERTED_B); + lcd.write(CHAR_INVERTED_C); + lcd.write(CHAR_INVERTED_D); + lcd.write(CHAR_ENCODER); + lcd.write(CHAR_ENCODER_SWITCH); } } diff --git a/firmware/src/screen.cpp b/firmware/src/screen.cpp index 8e28271..0d7b233 100644 --- a/firmware/src/screen.cpp +++ b/firmware/src/screen.cpp @@ -1,75 +1,10 @@ #include "constants.h" #include #include +#include "characters.h" LCD_I2C lcd(LCD_I2C_ADDR, LCD_COLS, LCD_ROWS); -uint8_t invertedA[8] = { - B11111, - B10001, - B10101, - B10001, - B10101, - B10101, - B11111, - B00000, -}; - -uint8_t invertedB[8] = { - B11111, - B10011, - B10101, - B10011, - B10101, - B10011, - B11111, - B00000, -}; - -uint8_t invertedC[8] = { - B11111, - B11001, - B10111, - B10111, - B10111, - B11001, - B11111, - B00000, -}; - -uint8_t invertedD[8] = { - B11111, - B10011, - B10101, - B10101, - B10101, - B10011, - B11111, - B00000, -}; - -uint8_t encoder[8] = { - B01110, - B10001, - B00011, - B11000, - B10001, - B01110, - B00000, - B00000, -}; - -uint8_t encoderSwitch[8] = { - B00000, - B01110, - B10001, - B10101, - B10001, - B01110, - B00000, - B00000, -}; - bool setupScreen() { lcd.begin(); @@ -81,11 +16,15 @@ bool setupScreen() { lcd.backlight(); lcd.clear(); - lcd.createChar(0, invertedA); - lcd.createChar(1, invertedB); - lcd.createChar(2, invertedC); - lcd.createChar(3, invertedD); - lcd.createChar(4, encoder); - lcd.createChar(5, encoderSwitch); + + // add custom characters to CGROM + // can only add 8 custom characters ,_, + lcd.createChar(CHAR_INVERTED_A, invertedA); + lcd.createChar(CHAR_INVERTED_B, invertedB); + lcd.createChar(CHAR_INVERTED_C, invertedC); + lcd.createChar(CHAR_INVERTED_D, invertedD); + lcd.createChar(CHAR_ENCODER, encoder); + lcd.createChar(CHAR_ENCODER_SWITCH, encoderSwitch); + return true; }