Compare commits

..

No commits in common. "cbea2cd66343ab553db0459fd530dec627907dc2" and "f450a88e91985a0fbc5e42b9b4a90130bfaba253" have entirely different histories.

7 changed files with 6 additions and 9972 deletions

File diff suppressed because it is too large Load Diff

View File

@ -27,23 +27,6 @@
// 0x02: FFT Animation // 0x02: FFT Animation
#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.
// //

View File

@ -1,11 +1,5 @@
#pragma once #pragma once
// Sleep this many millis after each loop.
// Prevents absurd cpu usage.
#define LOOP_SLEEP_MS 20
// USB device params // USB device params
#define HID_VENDOR_ID 0x3297 #define HID_VENDOR_ID 0x3297
#define HID_PRODUCT_ID 0x4976 #define HID_PRODUCT_ID 0x4976

View File

@ -1,16 +0,0 @@
#include "dict.hpp"
std::unordered_set<std::string> word_dict;
void load_file() {
std::ifstream file("resources/google-10000-english-usa-no-swears.txt");
if (file.is_open()) {
std::string line;
while (std::getline(file, line)) {
// using printf() in all tests for consistency
//printf("%s", line.c_str());
word_dict.insert(line.c_str());
}
file.close();
}
}

View File

@ -1,10 +0,0 @@
#pragma once
#include <fstream>
#include <unordered_set>
#include <string>
extern std::unordered_set<std::string> word_dict;
void load_file();

View File

@ -206,9 +206,10 @@ bool Ergodox::read() {
// If keyboard sends a state packet, parse it. // If keyboard sends a state packet, parse it.
case CMD_SEND_STATE: case CMD_SEND_STATE:
if (animation_mode != read_buf[1]) { if (animation_mode != read_buf[1]) {
spdlog::info("Mode set to 0x{0:02x}", read_buf[1]); spdlog::info("Mode set to {0:x}", read_buf[1]);
animation_mode = read_buf[1]; animation_mode = read_buf[1];
} }
// Main code should not parse state packets. // Main code should not parse state packets.
return false; return false;
} }

View File

@ -11,8 +11,6 @@
// MPD client // MPD client
#include "mpd/client.h" #include "mpd/client.h"
#include <string>
// Local files // Local files
#include "utility/bitmap.hpp" #include "utility/bitmap.hpp"
#include "utility/buffer.hpp" #include "utility/buffer.hpp"
@ -23,7 +21,6 @@
#include "spdlog/spdlog.h" #include "spdlog/spdlog.h"
#include "dict.hpp"
// TODO: // TODO:
// //
@ -61,11 +58,6 @@ const size_t height = BOTTOM_SKIP + KB_RESOLUTION + TOP_SKIP;
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
spdlog::info("Loading dictionary...");
load_file();
spdlog::info("done!");
spdlog::set_level(spdlog::level::info); spdlog::set_level(spdlog::level::info);
// buffer size for waveform: // buffer size for waveform:
@ -127,6 +119,7 @@ int main(int argc, char *argv[]) {
buf.update(); buf.update();
fft.update(buf); fft.update(buf);
hid_buf[0] = CMD_ANIM_DATA_fft;
for (size_t i = 0; i < 10; i++) { for (size_t i = 0; i < 10; i++) {
// Get height from fft, apply bottom_skip // Get height from fft, apply bottom_skip
ssize_t h = fft.get_output()[i] - BOTTOM_SKIP; ssize_t h = fft.get_output()[i] - BOTTOM_SKIP;
@ -136,11 +129,11 @@ int main(int argc, char *argv[]) {
h = h>KB_RESOLUTION ? KB_RESOLUTION : h; h = h>KB_RESOLUTION ? KB_RESOLUTION : h;
h = h<0 ? 0 : h; h = h<0 ? 0 : h;
hid_buf[i] = h; hid_buf[i + 1] = h;
} }
Dox.write(CMD_ANIM_DATA, hid_buf, Dox.packet_size);
} }
Dox.write(CMD_ANIM_DATA, hid_buf, Dox.packet_size);
t = std::chrono::steady_clock::now(); t = std::chrono::steady_clock::now();
} }
@ -155,37 +148,13 @@ int main(int argc, char *argv[]) {
uint8_t cmd = Dox.read_buf[0]; uint8_t cmd = Dox.read_buf[0];
switch(cmd) { switch(cmd) {
case CMD_SPELLCHECK_WORD: case CMD_SEND_STATE:
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; break;
} }
} }
} else { } else {
Dox.connect_loop(); Dox.connect_loop();
} }
// Sleep for a bit so we don't consume
// 100% of a cpu.
std::this_thread::sleep_for(
std::chrono::milliseconds(LOOP_SLEEP_MS)
);
} }
mpd_connection_free(conn); mpd_connection_free(conn);