From 4bd40034162410add3940c8a86d791e38fb78d28 Mon Sep 17 00:00:00 2001 From: spatialfree Date: Tue, 27 Feb 2024 14:54:53 -0500 Subject: [PATCH] brailleMap --- firmware/braille_xr/braille_xr.ino | 231 +++++++++++++++-------------- 1 file changed, 117 insertions(+), 114 deletions(-) diff --git a/firmware/braille_xr/braille_xr.ino b/firmware/braille_xr/braille_xr.ino index dc89c9a..4153cb9 100644 --- a/firmware/braille_xr/braille_xr.ino +++ b/firmware/braille_xr/braille_xr.ino @@ -1,9 +1,11 @@ +#include + #include "WiFi.h" #include "AsyncUDP.h" #include "wifi_config.h" AsyncUDP udp; -int bindex = 0; +char in_char = ' '; #include "ESP32Servo.h" struct ServoPin { @@ -28,115 +30,115 @@ ServoPin servos[6] = { struct BrailleChar { int servoStates[6]; }; -BrailleChar brailleAlphabet[27] = { - {{0, 0, - 0, 0, - 0, 0 - }}, // _ - {{1, 0, - 0, 0, - 0, 0 - }}, // a - {{1, 0, - 1, 0, - 0, 0 - }}, // b - {{1, 1, - 0, 0, - 0, 0 - }}, // c - {{1, 1, - 0, 1, - 0, 0 - }}, // d - {{1, 0, - 0, 1, - 0, 0 - }}, // e - {{1, 1, - 1, 0, - 0, 0 - }}, // f - {{1, 1, - 1, 1, - 0, 0 - }}, // g - {{1, 0, - 1, 1, - 0, 0 - }}, // h - {{0, 1, - 1, 0, - 0, 0 - }}, // i - {{0, 1, - 1, 1, - 0, 0 - }}, // j - {{1, 0, - 0, 0, - 1, 0 - }}, // k - {{1, 0, - 1, 0, - 1, 0 - }}, // l - {{1, 1, - 0, 0, - 1, 0 - }}, // m - {{1, 1, - 0, 1, - 1, 0 - }}, // n - {{1, 0, - 0, 1, - 1, 0 - }}, // o - {{1, 1, - 1, 0, - 1, 0 - }}, // p - {{1, 1, - 1, 1, - 1, 0 - }}, // q - {{1, 0, - 1, 1, - 1, 0 - }}, // r - {{0, 1, - 1, 0, - 1, 0 - }}, // s - {{0, 1, - 1, 1, - 1, 0 - }}, // t - {{1, 0, - 0, 0, - 1, 1 - }}, // u - {{1, 0, - 1, 0, - 1, 1 - }}, // v - {{0, 1, - 1, 1, - 0, 1 - }}, // w - {{1, 1, - 0, 0, - 1, 1 - }}, // x - {{1, 1, - 0, 1, - 1, 1 - }}, // y - {{1, 0, - 0, 1, - 1, 1 - }} // z +std::unordered_map brailleMap = { + {'_', {{0, 0, + 0, 0, + 0, 0 + }}}, + {'a', {{1, 0, + 0, 0, + 0, 0 + }}}, + {'b', {{1, 0, + 1, 0, + 0, 0 + }}}, + {'c', {{1, 1, + 0, 0, + 0, 0 + }}}, + {'d', {{1, 1, + 0, 1, + 0, 0 + }}}, + {'e', {{1, 0, + 0, 1, + 0, 0 + }}}, + {'f', {{1, 1, + 1, 0, + 0, 0 + }}}, + {'g', {{1, 1, + 1, 1, + 0, 0 + }}}, + {'h', {{1, 0, + 1, 1, + 0, 0 + }}}, + {'i', {{0, 1, + 1, 0, + 0, 0 + }}}, + {'j', {{0, 1, + 1, 1, + 0, 0 + }}}, + {'k', {{1, 0, + 0, 0, + 1, 0 + }}}, + {'l', {{1, 0, + 1, 0, + 1, 0 + }}}, + {'m', {{1, 1, + 0, 0, + 1, 0 + }}}, + {'n', {{1, 1, + 0, 1, + 1, 0 + }}}, + {'o', {{1, 0, + 0, 1, + 1, 0 + }}}, + {'p', {{1, 1, + 1, 0, + 1, 0 + }}}, + {'q', {{1, 1, + 1, 1, + 1, 0 + }}}, + {'r', {{1, 0, + 1, 1, + 1, 0 + }}}, + {'s', {{0, 1, + 1, 0, + 1, 0 + }}}, + {'t', {{0, 1, + 1, 1, + 1, 0 + }}}, + {'u', {{1, 0, + 0, 0, + 1, 1 + }}}, + {'v', {{1, 0, + 1, 0, + 1, 1 + }}}, + {'w', {{0, 1, + 1, 1, + 0, 1 + }}}, + {'x', {{1, 1, + 0, 0, + 1, 1 + }}}, + {'y', {{1, 1, + 0, 1, + 1, 1 + }}}, + {'z', {{1, 0, + 0, 1, + 1, 1 + }}} }; void setup() @@ -147,7 +149,7 @@ void setup() WiFi.mode(WIFI_STA); WiFi.begin(ssid, pass); while (WiFi.status() != WL_CONNECTED) { - delay(500); + delay(1000); Serial.print("."); // and print status Serial.println(WiFi.status()); @@ -164,8 +166,9 @@ void setup() // so do this instead // Serial.print(packet.data()[0]); // and set the bindex to that value - bindex = packet.data()[0]; - Serial.print(bindex); + // in_char = packet.data()[0]; + in_char = (char)packet.data()[0]; + Serial.print(in_char); Serial.println(); uint32_t receivedData; memcpy(&receivedData, packet.data(), sizeof(receivedData)); @@ -206,6 +209,6 @@ void loop() // myservo.write(bindex); for (int i = 0; i < 6; i++) { - servos[i].servo.write(brailleAlphabet[bindex].servoStates[i] * 180); + servos[i].servo.write(brailleMap[in_char].servoStates[i] * 180); } } \ No newline at end of file