Added special character command
parent
25dd1b5166
commit
99c2c7d532
|
@ -1,5 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
|
||||
|
||||
|
||||
// Sent by host when connection is initiated.
|
||||
//
|
||||
// Packet structure:
|
||||
|
@ -7,6 +10,9 @@
|
|||
// # of Bytes: | 1 |
|
||||
#define CMD_HELLO 0x00
|
||||
|
||||
|
||||
|
||||
|
||||
// Sent periodically by host to test connection.
|
||||
// Keyboard should ignore this command.
|
||||
//
|
||||
|
@ -15,6 +21,9 @@
|
|||
// # of Bytes: | 1 |
|
||||
#define CMD_RUTHERE 0x01
|
||||
|
||||
|
||||
|
||||
|
||||
// Send keyboard state to host.
|
||||
//
|
||||
// Packet structure:
|
||||
|
@ -39,23 +48,8 @@
|
|||
// 0x01: russian
|
||||
#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.
|
||||
//
|
||||
|
@ -74,3 +68,39 @@
|
|||
// Data segment consists of 10 bits, each representing the height of a column.
|
||||
// Minimum height is 0, maximum is 250.
|
||||
#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
|
59
src/main.cpp
59
src/main.cpp
|
@ -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[]) {
|
||||
|
||||
Hunspell* hun = new Hunspell(HUNSPELL_AFF_EN, HUNSPELL_DIC_EN);
|
||||
|
@ -417,8 +447,8 @@ int main(int argc, char *argv[]) {
|
|||
if (Dox.read()) {
|
||||
uint8_t cmd = Dox.read_buf[0];
|
||||
|
||||
switch(cmd) {
|
||||
case CMD_SPELLCHECK_WORD:
|
||||
switch (cmd) {
|
||||
case CMD_SPELLCHECK_WORD: {
|
||||
char word_chars[Dox.read_buf[1] + 1];
|
||||
|
||||
if (Dox.get_layer_layout() == LAYOUT_EN) {
|
||||
|
@ -440,13 +470,36 @@ int main(int argc, char *argv[]) {
|
|||
if (!dp) {
|
||||
hid_buf[0] = 0x01;
|
||||
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;
|
||||
}
|
||||
|
||||
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 (
|
||||
(last_layer_layout != Dox.get_layer_layout()) &&
|
||||
(Dox.get_layer_layout() != LAYOUT_NULL)
|
||||
|
|
Loading…
Reference in New Issue