Added basic spellchecker
This commit is contained in:
+26
-1
@@ -11,6 +11,8 @@
|
||||
// MPD client
|
||||
#include "mpd/client.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
// Local files
|
||||
#include "utility/bitmap.hpp"
|
||||
#include "utility/buffer.hpp"
|
||||
@@ -21,6 +23,7 @@
|
||||
|
||||
#include "spdlog/spdlog.h"
|
||||
|
||||
#include "dict.hpp"
|
||||
|
||||
// TODO:
|
||||
//
|
||||
@@ -58,6 +61,11 @@ const size_t height = BOTTOM_SKIP + KB_RESOLUTION + TOP_SKIP;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
spdlog::info("Loading dictionary...");
|
||||
load_file();
|
||||
spdlog::info("done!");
|
||||
|
||||
|
||||
spdlog::set_level(spdlog::level::info);
|
||||
|
||||
// buffer size for waveform:
|
||||
@@ -147,7 +155,24 @@ int main(int argc, char *argv[]) {
|
||||
uint8_t cmd = Dox.read_buf[0];
|
||||
|
||||
switch(cmd) {
|
||||
case CMD_SEND_STATE:
|
||||
case CMD_SPELLCHECK_WORD:
|
||||
char word_chars[Dox.read_buf[1] + 1];
|
||||
|
||||
for (int i=0; i < Dox.read_buf[1]; i++) {
|
||||
// A in ascii:
|
||||
// a in ascii: 0x61
|
||||
// KC_A: 0x04
|
||||
word_chars[i] = Dox.read_buf[i + 2] + 0x5D;
|
||||
}
|
||||
word_chars[Dox.read_buf[1]] = 0x00; // Terminate with null char
|
||||
|
||||
std::string word = std::string(word_chars);
|
||||
|
||||
if (word_dict.find(word) == word_dict.end()) {
|
||||
hid_buf[0] = 0x01;
|
||||
Dox.write(CMD_SPELLCHECK_WORD, hid_buf, Dox.packet_size);
|
||||
spdlog::info("Got typo: \"{0:s}\" not in dict", word);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user