Added special character command

master
Mark 2022-08-10 09:07:04 -07:00
parent 25dd1b5166
commit 99c2c7d532
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
2 changed files with 103 additions and 20 deletions

View File

@ -1,5 +1,8 @@
#pragma once #pragma once
// Sent by host when connection is initiated. // Sent by host when connection is initiated.
// //
// Packet structure: // Packet structure:
@ -7,6 +10,9 @@
// # of Bytes: | 1 | // # of Bytes: | 1 |
#define CMD_HELLO 0x00 #define CMD_HELLO 0x00
// Sent periodically by host to test connection. // Sent periodically by host to test connection.
// Keyboard should ignore this command. // Keyboard should ignore this command.
// //
@ -15,6 +21,9 @@
// # of Bytes: | 1 | // # of Bytes: | 1 |
#define CMD_RUTHERE 0x01 #define CMD_RUTHERE 0x01
// Send keyboard state to host. // Send keyboard state to host.
// //
// Packet structure: // Packet structure:
@ -39,23 +48,8 @@
// 0x01: russian // 0x01: russian
#define CMD_SEND_STATE 0x02 #define CMD_SEND_STATE 0x02
// Sent by keyboard to host when a complete word is typed.
// Host checks if this is a known word.
// If it is not, host responds with the same CMD (see below).
//
// Packet structure (sent by keyboard):
// Data: | cmd | word length | keycodes |
// # of Bytes: | 1 | 1 | ? |
//
// word length: number of bytes in `keycodes` block
//
//
// Packet structure (sent by host):
// Data: | cmd | typo? |
// # of Bytes: | 1 | 1 |
//
// typo: If this is 0x01, the word we got was a typo.
#define CMD_SPELLCHECK_WORD 0x04
// Animation data. Sent by host. // Animation data. Sent by host.
// //
@ -74,3 +68,39 @@
// Data segment consists of 10 bits, each representing the height of a column. // Data segment consists of 10 bits, each representing the height of a column.
// Minimum height is 0, maximum is 250. // Minimum height is 0, maximum is 250.
#define CMD_ANIM_DATA_fft 0x00 #define CMD_ANIM_DATA_fft 0x00
// Sent by keyboard to host when a complete word is typed.
// Host checks if this is a known word.
// If it is not, host responds with the same CMD (see below).
//
// Packet structure (sent by keyboard):
// Data: | cmd | word length | keycodes |
// # of Bytes: | 1 | 1 | ? |
//
// word length: number of bytes in `keycodes` block
//
//
// Packet structure (sent by host):
// Data: | cmd | typo? |
// # of Bytes: | 1 | 1 |
//
// typo: If this is 0x01, the word we got was a typo.
#define CMD_SPELLCHECK_WORD 0x04
// Sent by host when a "special char" key is pressed.
// Handled by host interface.
//
// Packet structure:
// Data: | cmd | character |
// # of Bytes: | 1 | 2 |
//
// character:
// uint16_t, character id
//
#define CMD_SPECIAL_CHAR 0x05

View File

@ -318,6 +318,36 @@ char ru_kc_to_char(uint8_t keycode) {
} }
std::string special_chars[] = {
// Usual characters
"\\`",
"~",
"'",
"[",
"]",
"{",
"}",
"«",
"»",
// Special characters
"Ѧ",
"Ѫ",
"Ԙ",
"¯\\_(ツ)_/¯"
};
// Ѧ ѧ little yus
// Ѫ ѫ big yus
// Ѩ ѩ iotified
// Ѭ ѭ iotofied
// Ԙ yae
//
// 🙃 upside-down
// 😁 big grin
// 🙄 rolling eyes
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
Hunspell* hun = new Hunspell(HUNSPELL_AFF_EN, HUNSPELL_DIC_EN); Hunspell* hun = new Hunspell(HUNSPELL_AFF_EN, HUNSPELL_DIC_EN);
@ -417,8 +447,8 @@ int main(int argc, char *argv[]) {
if (Dox.read()) { if (Dox.read()) {
uint8_t cmd = Dox.read_buf[0]; uint8_t cmd = Dox.read_buf[0];
switch(cmd) { switch (cmd) {
case CMD_SPELLCHECK_WORD: case CMD_SPELLCHECK_WORD: {
char word_chars[Dox.read_buf[1] + 1]; char word_chars[Dox.read_buf[1] + 1];
if (Dox.get_layer_layout() == LAYOUT_EN) { if (Dox.get_layer_layout() == LAYOUT_EN) {
@ -440,13 +470,36 @@ int main(int argc, char *argv[]) {
if (!dp) { if (!dp) {
hid_buf[0] = 0x01; hid_buf[0] = 0x01;
Dox.write(CMD_SPELLCHECK_WORD, hid_buf, Dox.packet_size); Dox.write(CMD_SPELLCHECK_WORD, hid_buf, Dox.packet_size);
spdlog::info("Got typo: \"{0:s}\" not in dict", word); //spdlog::info("Got typo: \"{0:s}\" not in dict", word);
} }
break; break;
}
case CMD_SPECIAL_CHAR: {
// Bytes 1,2: char id
uint16_t char_id =
(Dox.read_buf[2] << 8) |
(Dox.read_buf[1] << 0);
spdlog::info("{0:d}", char_id);
if (char_id < (sizeof(special_chars) / sizeof(std::string)) ) {
std::system(
(
std::string("xdotool type \"") +
special_chars[char_id] +
std::string("\"")
).c_str()
);
}
break;
}
} }
} }
// Switch layer if necessary.
if ( if (
(last_layer_layout != Dox.get_layer_layout()) && (last_layer_layout != Dox.get_layer_layout()) &&
(Dox.get_layer_layout() != LAYOUT_NULL) (Dox.get_layer_layout() != LAYOUT_NULL)