Compare commits

...

2 commits

Author SHA1 Message Date
4bd4003416 brailleMap <key char, value brailleChar> 2024-02-27 14:54:53 -05:00
6cd1e20666 index to char 2024-02-27 14:53:42 -05:00
3 changed files with 170 additions and 167 deletions

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);
} }
} }

View file

@ -28,159 +28,159 @@ public class Mono {
} }
} }
// key:(string) value:(int[] dots) // key:(char) value:(int[] dots)
Dictionary<string, int[]> char_cell = new Dictionary<string, int[]> { Dictionary<char, int[]> char_cell = new Dictionary<char, int[]> {
{ "a", new int[] { { ' ', new int[] {
0, 0,
0, 0,
0, 0
} },
{ 'a', new int[] {
1, 0, 1, 0,
0, 0, 0, 0,
0, 0 0, 0
} }, } },
{ "b", new int[] { { 'b', new int[] {
1, 0, 1, 0,
1, 0, 1, 0,
0, 0 0, 0
} }, } },
{ "c", new int[] { { 'c', new int[] {
1, 1, 1, 1,
0, 0, 0, 0,
0, 0 0, 0
} }, } },
{ "d", new int[] { { 'd', new int[] {
1, 1, 1, 1,
0, 1, 0, 1,
0, 0 0, 0
} }, } },
{ "e", new int[] { { 'e', new int[] {
1, 0, 1, 0,
0, 1, 0, 1,
0, 0 0, 0
} }, } },
{ "f", new int[] { { 'f', new int[] {
1, 1, 1, 1,
1, 0, 1, 0,
0, 0 0, 0
} }, } },
{ "g", new int[] { { 'g', new int[] {
1, 1, 1, 1,
1, 1, 1, 1,
0, 0 0, 0
} }, } },
{ "h", new int[] { { 'h', new int[] {
1, 0, 1, 0,
1, 1, 1, 1,
0, 0 0, 0
} }, } },
{ "i", new int[] { { 'i', new int[] {
0, 1, 0, 1,
1, 0, 1, 0,
0, 0 0, 0
} }, } },
{ "j", new int[] { { 'j', new int[] {
0, 1, 0, 1,
1, 1, 1, 1,
0, 0 0, 0
} }, } },
{ "k", new int[] { { 'k', new int[] {
1, 0, 1, 0,
0, 0, 0, 0,
1, 0 1, 0
} }, } },
{ "l", new int[] { { 'l', new int[] {
1, 0, 1, 0,
1, 0, 1, 0,
1, 0 1, 0
} }, } },
{ "m", new int[] { { 'm', new int[] {
1, 1, 1, 1,
0, 0, 0, 0,
1, 0 1, 0
} }, } },
{ "n", new int[] { { 'n', new int[] {
1, 1, 1, 1,
0, 1, 0, 1,
1, 0 1, 0
} }, } },
{ "o", new int[] { { 'o', new int[] {
1, 0, 1, 0,
0, 1, 0, 1,
1, 0 1, 0
} }, } },
{ "p", new int[] { { 'p', new int[] {
1, 1, 1, 1,
1, 0, 1, 0,
1, 0 1, 0
} }, } },
{ "q", new int[] { { 'q', new int[] {
1, 1, 1, 1,
1, 1, 1, 1,
1, 0 1, 0
} }, } },
{ "r", new int[] { { 'r', new int[] {
1, 0, 1, 0,
1, 1, 1, 1,
1, 0 1, 0
} }, } },
{ "s", new int[] { { 's', new int[] {
0, 1, 0, 1,
1, 0, 1, 0,
1, 0 1, 0
} }, } },
{ "t", new int[] { { 't', new int[] {
0, 1, 0, 1,
1, 1, 1, 1,
1, 0 1, 0
} }, } },
{ "u", new int[] { { 'u', new int[] {
1, 0, 1, 0,
0, 0, 0, 0,
1, 1 1, 1
} }, } },
{ "v", new int[] { { 'v', new int[] {
1, 0, 1, 0,
1, 0, 1, 0,
1, 1 1, 1
} }, } },
{ "w", new int[] { { 'w', new int[] {
0, 1, 0, 1,
1, 1, 1, 1,
0, 1 0, 1
} }, } },
{ "x", new int[] { { 'x', new int[] {
1, 1, 1, 1,
0, 0, 0, 0,
1, 1 1, 1
} }, } },
{ "y", new int[] { { 'y', new int[] {
1, 1, 1, 1,
0, 1, 0, 1,
1, 1 1, 1
} }, } },
{ "z", new int[] { { 'z', new int[] {
1, 0, 1, 0,
0, 1, 0, 1,
1, 1 1, 1
} }, } },
{ " ", new int[] { { ',', new int[] {
0, 0,
0, 0,
0, 0
} },
{ ",", new int[] {
0, 0, 0, 0,
1, 0, 1, 0,
0, 0 0, 0
} }, } },
{ ".", new int[] { { '.', new int[] {
0, 0, 0, 0,
1, 1, 1, 1,
0, 1 0, 1
} }, } },
{ "/", new int[] { { '/', new int[] {
0, 1, 0, 1,
0, 0, 0, 0,
1, 0 1, 0
} }, } },
{ ";", new int[] { { ';', new int[] {
0, 0, 0, 0,
1, 0, 1, 0,
1, 0 1, 0
@ -193,20 +193,20 @@ public class Mono {
Colemak Colemak
} }
Dictionary<Layout, string[]> layouts = new Dictionary<Layout, string[]> { Dictionary<Layout, char[]> layouts = new Dictionary<Layout, char[]> {
{ Layout.Colemak, new string[] { { Layout.Colemak, new char[] {
"q", "w", "f", "p", "g", "j", "l", "u", "y", ";", 'q', 'w', 'f', 'p', 'g', 'j', 'l', 'u', 'y', ';',
"a", "r", "s", "t", "d", "h", "n", "e", "i", "o", 'a', 'r', 's', 't', 'd', 'h', 'n', 'e', 'i', 'o',
"z", "x", "c", "v", "b", "k", "m", ",", ".", "/", 'z', 'x', 'c', 'v', 'b', 'k', 'm', ',', '.', '/',
} }, } },
{ Layout.Qwerty, new string[] { { Layout.Qwerty, new char[] {
"q", "w", "e", "r", "t", "y", "u", "i", "o", "p", 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p',
"a", "s", "d", "f", "g", "h", "j", "k", "l", ";", 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';',
"z", "x", "c", "v", "b", "n", "m", ",", ".", "/", 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/',
} }, } },
}; };
public string KeyToChar(int index) { public char KeyToChar(int index) {
return layouts[Layout.Colemak][index]; return layouts[Layout.Colemak][index];
} }
@ -248,7 +248,7 @@ public class Mono {
// xi = 0; // xi = 0;
// } // }
if (Input.Key(Key.Down).IsJustActive()) { if (Input.Key(Key.Down).IsJustActive()) {
monoNet.value = 0; monoNet.value = ' ';
monoNet.send = true; monoNet.send = true;
} }
@ -267,7 +267,7 @@ public class Mono {
if (index_i != last_index_i) { if (index_i != last_index_i) {
last_index_i = index_i; last_index_i = index_i;
// Log.Info($"index_i: {index_i}"); // Log.Info($"index_i: {index_i}");
monoNet.value = index_i; monoNet.value = KeyToChar(index_i);
monoNet.send = true; monoNet.send = true;
} }
} }
@ -295,10 +295,10 @@ public class Mono {
int index = y * 10 + x; int index = y * 10 + x;
// string text = characters[index].character; // string text = characters[index].character;
string keychar = KeyToChar(index); char keychar = KeyToChar(index);
Text.Add( Text.Add(
keychar, keychar.ToString(),
Matrix.TS( Matrix.TS(
pos + V.XYZ(-0.3f, -0.3f, 0), pos + V.XYZ(-0.3f, -0.3f, 0),
V.XYZ(-1, -1, 0) * 8.0f V.XYZ(-1, -1, 0) * 8.0f

View file

@ -9,13 +9,13 @@ public class MonoNet {
byte[] wData; int wHead; byte[] wData; int wHead;
public bool send = true; public bool send = true;
public int value = 0; public char value = ' ';
public MonoNet() { public MonoNet() {
socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
string ip = "192.168.1.81"; string ip = "192.168.0.23";
EndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse(ip), 1234); EndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse(ip), 1234);
socket.Connect(serverEndPoint); socket.Connect(serverEndPoint);