From 649f838121952c2a83f2e8a1416eb4fbab4c1c1c Mon Sep 17 00:00:00 2001 From: Andrej Antunovikj Date: Fri, 14 Jul 2023 12:39:27 +0200 Subject: [PATCH] Adding capitalization and numbers to T9 library --- libs/keyboard/t9.hpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/libs/keyboard/t9.hpp b/libs/keyboard/t9.hpp index e30fd78..586a4d0 100644 --- a/libs/keyboard/t9.hpp +++ b/libs/keyboard/t9.hpp @@ -11,6 +11,18 @@ public: void ProcessButton(unsigned char key) { + if (key == 15) + { + number_mode = !number_mode; + return; // add a return to prevent processing this key normally + } + + if (number_mode && key <= 9) + { + C8WorkingBuff[c_index++] = '0' + key; // add the number to the working buffer + C8WorkingBuff[c_index] = '\0'; // ensure string is null-terminated + return; // add a return to prevent processing this key normally + } if (key == 0) { // key 0 for space prev_key = 0; @@ -19,11 +31,6 @@ public: return; } - if (key == 1) - { - return; - } - else if (key == 13) { ProcessBackSpace(); @@ -68,9 +75,11 @@ public: } char (&C8WorkingBuff)[u8BuffSize]; + private: - static constexpr char T9_table[10][4] = {{' ', '\0', '\0', '\0'}, {'\0', '\0', '\0', '\0'}, {'a', 'b', 'c', '\0'}, {'d', 'e', 'f', '\0'}, {'g', 'h', 'i', '\0'}, {'j', 'k', 'l', '\0'}, {'m', 'n', 'o', '\0'}, {'p', 'q', 'r', 's'}, {'t', 'u', 'v', '\0'}, {'w', 'x', 'y', 'z'}}; - static constexpr unsigned char numberOfLettersAssignedToKey[10] = {1, 0, 3, 3, 3, 3, 3, 4, 3, 4}; + static constexpr char T9_table[10][8] = {{' ', '\0', '\0', '\0', '\0', '\0', '\0', '\0'}, {'.', ',', '\'', '!', '?', '/', '#', '$'}, {'a', 'b', 'c', 'A', 'B', 'C', '\0', '\0'}, {'d', 'e', 'f', 'D', 'E', 'F', '\0', '\0'}, {'g', 'h', 'i', 'G', 'H', 'I', '\0', '\0'}, {'j', 'k', 'l', 'J', 'K', 'L', '\0', '\0'}, {'m', 'n', 'o', 'M', 'N', 'O', '\0', '\0'}, {'p', 'q', 'r', 's', 'P', 'Q', 'R', 'S'}, {'t', 'u', 'v', 'T', 'U', 'V', '\0', '\0'}, {'w', 'x', 'y', 'z', 'W', 'X', 'Y', 'Z'}}; + static constexpr unsigned char numberOfLettersAssignedToKey[10] = {1, 8, 6, 6, 6, 6, 6, 8, 6, 8}; unsigned char prev_key = 0, prev_letter = 0; unsigned char c_index = 0; + bool number_mode = false; }; \ No newline at end of file