brailleMap <key char, value brailleChar>

This commit is contained in:
ethan merchant 2024-02-27 14:54:53 -05:00
parent 6cd1e20666
commit 4bd4003416

View file

@ -1,9 +1,11 @@
#include <unordered_map>
#include "WiFi.h" #include "WiFi.h"
#include "AsyncUDP.h" #include "AsyncUDP.h"
#include "wifi_config.h" #include "wifi_config.h"
AsyncUDP udp; AsyncUDP udp;
int bindex = 0; char in_char = ' ';
#include "ESP32Servo.h" #include "ESP32Servo.h"
struct ServoPin { struct ServoPin {
@ -28,115 +30,115 @@ ServoPin servos[6] = {
struct BrailleChar { struct BrailleChar {
int servoStates[6]; int servoStates[6];
}; };
BrailleChar brailleAlphabet[27] = { std::unordered_map<char, BrailleChar> brailleMap = {
{{0, 0, {'_', {{0, 0,
0, 0, 0, 0,
0, 0 0, 0
}}, // _ }}},
{{1, 0, {'a', {{1, 0,
0, 0, 0, 0,
0, 0 0, 0
}}, // a }}},
{{1, 0, {'b', {{1, 0,
1, 0, 1, 0,
0, 0 0, 0
}}, // b }}},
{{1, 1, {'c', {{1, 1,
0, 0, 0, 0,
0, 0 0, 0
}}, // c }}},
{{1, 1, {'d', {{1, 1,
0, 1, 0, 1,
0, 0 0, 0
}}, // d }}},
{{1, 0, {'e', {{1, 0,
0, 1, 0, 1,
0, 0 0, 0
}}, // e }}},
{{1, 1, {'f', {{1, 1,
1, 0, 1, 0,
0, 0 0, 0
}}, // f }}},
{{1, 1, {'g', {{1, 1,
1, 1, 1, 1,
0, 0 0, 0
}}, // g }}},
{{1, 0, {'h', {{1, 0,
1, 1, 1, 1,
0, 0 0, 0
}}, // h }}},
{{0, 1, {'i', {{0, 1,
1, 0, 1, 0,
0, 0 0, 0
}}, // i }}},
{{0, 1, {'j', {{0, 1,
1, 1, 1, 1,
0, 0 0, 0
}}, // j }}},
{{1, 0, {'k', {{1, 0,
0, 0, 0, 0,
1, 0 1, 0
}}, // k }}},
{{1, 0, {'l', {{1, 0,
1, 0, 1, 0,
1, 0 1, 0
}}, // l }}},
{{1, 1, {'m', {{1, 1,
0, 0, 0, 0,
1, 0 1, 0
}}, // m }}},
{{1, 1, {'n', {{1, 1,
0, 1, 0, 1,
1, 0 1, 0
}}, // n }}},
{{1, 0, {'o', {{1, 0,
0, 1, 0, 1,
1, 0 1, 0
}}, // o }}},
{{1, 1, {'p', {{1, 1,
1, 0, 1, 0,
1, 0 1, 0
}}, // p }}},
{{1, 1, {'q', {{1, 1,
1, 1, 1, 1,
1, 0 1, 0
}}, // q }}},
{{1, 0, {'r', {{1, 0,
1, 1, 1, 1,
1, 0 1, 0
}}, // r }}},
{{0, 1, {'s', {{0, 1,
1, 0, 1, 0,
1, 0 1, 0
}}, // s }}},
{{0, 1, {'t', {{0, 1,
1, 1, 1, 1,
1, 0 1, 0
}}, // t }}},
{{1, 0, {'u', {{1, 0,
0, 0, 0, 0,
1, 1 1, 1
}}, // u }}},
{{1, 0, {'v', {{1, 0,
1, 0, 1, 0,
1, 1 1, 1
}}, // v }}},
{{0, 1, {'w', {{0, 1,
1, 1, 1, 1,
0, 1 0, 1
}}, // w }}},
{{1, 1, {'x', {{1, 1,
0, 0, 0, 0,
1, 1 1, 1
}}, // x }}},
{{1, 1, {'y', {{1, 1,
0, 1, 0, 1,
1, 1 1, 1
}}, // y }}},
{{1, 0, {'z', {{1, 0,
0, 1, 0, 1,
1, 1 1, 1
}} // z }}}
}; };
void setup() void setup()
@ -147,7 +149,7 @@ void setup()
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
WiFi.begin(ssid, pass); WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) { while (WiFi.status() != WL_CONNECTED) {
delay(500); delay(1000);
Serial.print("."); Serial.print(".");
// and print status // and print status
Serial.println(WiFi.status()); Serial.println(WiFi.status());
@ -164,8 +166,9 @@ void setup()
// so do this instead // so do this instead
// Serial.print(packet.data()[0]); // Serial.print(packet.data()[0]);
// and set the bindex to that value // and set the bindex to that value
bindex = packet.data()[0]; // in_char = packet.data()[0];
Serial.print(bindex); in_char = (char)packet.data()[0];
Serial.print(in_char);
Serial.println(); Serial.println();
uint32_t receivedData; uint32_t receivedData;
memcpy(&receivedData, packet.data(), sizeof(receivedData)); memcpy(&receivedData, packet.data(), sizeof(receivedData));
@ -206,6 +209,6 @@ void loop()
// myservo.write(bindex); // myservo.write(bindex);
for (int i = 0; i < 6; i++) { 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);
} }
} }