Compare commits
11 Commits
cbea2cd663
...
master
Author | SHA1 | Date | |
---|---|---|---|
2c9131f197
|
|||
40f6ddee8a
|
|||
0e446769ed
|
|||
b478f2bf82
|
|||
99c2c7d532
|
|||
25dd1b5166
|
|||
30422df0da
|
|||
dcfe86f661
|
|||
720c12ae87
|
|||
dfa3cc6c5b
|
|||
665f0b6dae
|
17
Makefile
17
Makefile
@ -4,7 +4,7 @@ SRC_DIRS := ./src
|
|||||||
|
|
||||||
# False targets
|
# False targets
|
||||||
# (these are the only ones you manually run)
|
# (these are the only ones you manually run)
|
||||||
all: $(TARGET_EXEC)
|
all: libs $(TARGET_EXEC)
|
||||||
|
|
||||||
run: all
|
run: all
|
||||||
./$(TARGET_EXEC)
|
./$(TARGET_EXEC)
|
||||||
@ -16,7 +16,10 @@ clean:
|
|||||||
|
|
||||||
libs: $(BUILD_DIR)/hid.o $(BUILD_DIR)/libmpdclient.o
|
libs: $(BUILD_DIR)/hid.o $(BUILD_DIR)/libmpdclient.o
|
||||||
|
|
||||||
.PHONY: clean all run libs
|
submodules:
|
||||||
|
git submodule update --init --recursive
|
||||||
|
|
||||||
|
.PHONY: clean all run libs submodules
|
||||||
|
|
||||||
#################################################
|
#################################################
|
||||||
# Flags and autodetection
|
# Flags and autodetection
|
||||||
@ -28,10 +31,14 @@ CPPFLAGS := -MMD -MP \
|
|||||||
-I libs/hidapi/hidapi \
|
-I libs/hidapi/hidapi \
|
||||||
-I libs/spdlog/include \
|
-I libs/spdlog/include \
|
||||||
-I libs/libmpdclient/include \
|
-I libs/libmpdclient/include \
|
||||||
-I libs/libmpdclient/output
|
-I libs/libmpdclient/output \
|
||||||
|
$(shell pkg-config --cflags hunspell)
|
||||||
|
|
||||||
# udev: required by hidapi
|
# udev: required by hidapi
|
||||||
LDFLAGS := -l fftw3 -l udev
|
LDFLAGS := \
|
||||||
|
-l fftw3 \
|
||||||
|
-l udev \
|
||||||
|
$(shell pkg-config --libs hunspell)
|
||||||
|
|
||||||
# Find all cpp files in source dirs
|
# Find all cpp files in source dirs
|
||||||
SRCS := $(shell find $(SRC_DIRS) -name '*.cpp')
|
SRCS := $(shell find $(SRC_DIRS) -name '*.cpp')
|
||||||
@ -62,6 +69,8 @@ $(BUILD_DIR)/hid.o:
|
|||||||
|
|
||||||
# Build libmpdclient
|
# Build libmpdclient
|
||||||
$(BUILD_DIR)/libmpdclient.o:
|
$(BUILD_DIR)/libmpdclient.o:
|
||||||
|
@mkdir -p $(BUILD_DIR)
|
||||||
|
|
||||||
@cd libs/libmpdclient && \
|
@cd libs/libmpdclient && \
|
||||||
meson . output && \
|
meson . output && \
|
||||||
ninja -C output
|
ninja -C output
|
||||||
|
34
README.md
Normal file
34
README.md
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
# Ergodox Host Interface
|
||||||
|
|
||||||
|
Host software for [Betalupi Ergodox](https://git.betalupi.com/Mark/QMK).
|
||||||
|
|
||||||
|
## Features:
|
||||||
|
- Music visualizer ([here](https://git.betalupi.com/Mark/hostdox/src/branch/master/src/signal_processing))
|
||||||
|
- Spell checking with hunspell
|
||||||
|
|
||||||
|
|
||||||
|
## Permissions
|
||||||
|
|
||||||
|
You'll need to run this binary as a regular user. To allow access to raw hid, add the following udev rule and reboot:
|
||||||
|
|
||||||
|
```conf
|
||||||
|
KERNEL=="hidraw*", ATTRS{idVendor}=="3297", ATTRS{idProduct}=="4976", TAG+="uaccess", GROUP="mark", MODE="660"
|
||||||
|
```
|
||||||
|
|
||||||
|
See the hidraw repo for more information.
|
||||||
|
|
||||||
|
|
||||||
|
## Dependencies:
|
||||||
|
Run:
|
||||||
|
- hunspell
|
||||||
|
|
||||||
|
Build:
|
||||||
|
- meson (for libmpdclient)
|
||||||
|
- ninja (for libmpdclient)
|
||||||
|
- gcc
|
||||||
|
|
||||||
|
|
||||||
|
## Building
|
||||||
|
|
||||||
|
``make submodules`` to initialize git submodules \
|
||||||
|
``make all`` to build, or ``make run`` to build and run.
|
Submodule libs/hidapi updated: eaa5c7c6f1...bb792a1f7e
File diff suppressed because it is too large
Load Diff
@ -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,18 +21,57 @@
|
|||||||
// # 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:
|
||||||
// Data: | cmd | anim state |
|
// Data: | cmd | anim state | layer state | layer layout |
|
||||||
// # of Bytes: | 1 | 1 |
|
// # of Bytes: | 1 | 1 | 4 | 1 |
|
||||||
//
|
//
|
||||||
// anim state:
|
// anim state:
|
||||||
// 0x00: RGBMatrix disabled
|
// 0x00: RGBMatrix disabled
|
||||||
// 0x01: normal animation, no HID data.
|
// 0x01: normal animation, no HID data.
|
||||||
// 0x02: FFT Animation
|
// 0x02: FFT Animation
|
||||||
|
//
|
||||||
|
// layer state: layer state right now.
|
||||||
|
// This is a uint32_t, where each bit corresponds to a layer index.
|
||||||
|
// Lowest-order bit is base layer, highest bit is layer 31.
|
||||||
|
// Layer indices are defined by the LAYER_* enum in layer.h,
|
||||||
|
// host interface should have a matching enum.
|
||||||
|
// Make sure to update it when you change your layers!
|
||||||
|
//
|
||||||
|
// layer layout:
|
||||||
|
// The layout this layer was designed for.
|
||||||
|
// 0x00: en_us
|
||||||
|
// 0x01: russian
|
||||||
#define CMD_SEND_STATE 0x02
|
#define CMD_SEND_STATE 0x02
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Animation data. Sent by host.
|
||||||
|
//
|
||||||
|
// Packet structure:
|
||||||
|
// Data: | cmd | data type | data |
|
||||||
|
// # of Bytes: | 1 | 1 | ? |
|
||||||
|
//
|
||||||
|
// data type:
|
||||||
|
// Which animation this data is for. These are defined below.
|
||||||
|
//
|
||||||
|
// data:
|
||||||
|
// Animation data. Content depends on data type.
|
||||||
|
#define CMD_ANIM_DATA 0x03
|
||||||
|
|
||||||
|
// Data for FFT animation.
|
||||||
|
// 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.
|
// Sent by keyboard to host when a complete word is typed.
|
||||||
// Host checks if this is a known word.
|
// Host checks if this is a known word.
|
||||||
// If it is not, host responds with the same CMD (see below).
|
// If it is not, host responds with the same CMD (see below).
|
||||||
@ -45,20 +90,17 @@
|
|||||||
// typo: If this is 0x01, the word we got was a typo.
|
// typo: If this is 0x01, the word we got was a typo.
|
||||||
#define CMD_SPELLCHECK_WORD 0x04
|
#define CMD_SPELLCHECK_WORD 0x04
|
||||||
|
|
||||||
// Animation data. Sent by host.
|
|
||||||
|
|
||||||
|
|
||||||
|
// Sent by host when a "special char" key is pressed.
|
||||||
|
// Handled by host interface.
|
||||||
//
|
//
|
||||||
// Packet structure:
|
// Packet structure:
|
||||||
// Data: | cmd | data type | data |
|
// Data: | cmd | character |
|
||||||
// # of Bytes: | 1 | 1 | ? |
|
// # of Bytes: | 1 | 2 |
|
||||||
//
|
//
|
||||||
// data type:
|
// character:
|
||||||
// Which animation this data is for. These are defined below.
|
// uint16_t, character id
|
||||||
//
|
//
|
||||||
// data:
|
#define CMD_SPECIAL_CHAR 0x05
|
||||||
// Animation data. Content depends on data type.
|
|
||||||
#define CMD_ANIM_DATA 0x03
|
|
||||||
|
|
||||||
// Data for FFT animation.
|
|
||||||
// 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
|
|
79
src/config.h
79
src/config.h
@ -1,10 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
// Sleep this many millis after each loop.
|
/*
|
||||||
// Prevents absurd cpu usage.
|
General Setup
|
||||||
#define LOOP_SLEEP_MS 20
|
*/
|
||||||
|
|
||||||
|
|
||||||
// USB device params
|
// USB device params
|
||||||
#define HID_VENDOR_ID 0x3297
|
#define HID_VENDOR_ID 0x3297
|
||||||
@ -19,14 +18,68 @@
|
|||||||
// How many milliseconds to wait between reconnect attempts
|
// How many milliseconds to wait between reconnect attempts
|
||||||
#define RECONNECT_SLEEP_MS 500
|
#define RECONNECT_SLEEP_MS 500
|
||||||
|
|
||||||
// How many keys in a column * resolution per key.
|
// Keyboard layers.
|
||||||
// this MUST fit inside a uint8_t (i.e, <= 255).
|
// These must have the same indices as
|
||||||
#define KB_RESOLUTION (5 * 50)
|
// your layers in QMK.
|
||||||
|
enum keyboard_layers {
|
||||||
|
LAYER_MAIN,
|
||||||
|
LAYER_RUSSIAN,
|
||||||
|
LAYER_SYMBOLS,
|
||||||
|
LAYER_SYMBOLS_RU,
|
||||||
|
LAYER_ARROWS,
|
||||||
|
LAYER_DESKTOP,
|
||||||
|
LAYER_FKEYS,
|
||||||
|
LAYER_KEYBOARD,
|
||||||
|
LAYER_NUMPAD
|
||||||
|
};
|
||||||
|
|
||||||
// How many resolution steps to skip at the top and bottom.
|
// Must match enum in keyboard
|
||||||
#define BOTTOM_SKIP 100
|
enum layer_layout_ids {
|
||||||
#define TOP_SKIP 0
|
LAYOUT_NULL, // This layer doesn't care what keymap the OS is using
|
||||||
|
LAYOUT_EN, // This layer is designed for the standard keymapping
|
||||||
|
LAYOUT_RU,
|
||||||
|
};
|
||||||
|
|
||||||
// Spectrum visualizer range
|
// Sleep this many millis after each loop.
|
||||||
#define MIN_HZ 100
|
// Prevents absurd cpu usage.
|
||||||
#define MAX_HZ 5000
|
#define LOOP_SLEEP_MS 20
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Autotype Special Characters
|
||||||
|
*/
|
||||||
|
//#define DISABLE_SPECIAL_CHAR
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Spellcheck
|
||||||
|
*/
|
||||||
|
#define DISABLE_SPELL
|
||||||
|
#ifndef DISABLE_SPELL
|
||||||
|
#define HUNSPELL_AFF_EN "/usr/share/hunspell/en_US.aff"
|
||||||
|
#define HUNSPELL_DIC_EN "/usr/share/hunspell/en_US.dic"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Music Visualizer Animation
|
||||||
|
*/
|
||||||
|
#define DISABLE_VISUALIZER
|
||||||
|
#ifndef DISABLE_VISUALIZER
|
||||||
|
// How many keys in a column * resolution per key.
|
||||||
|
// this MUST fit inside a uint8_t (i.e, <= 255).
|
||||||
|
#define KB_RESOLUTION (5 * 50)
|
||||||
|
|
||||||
|
// How many resolution steps to skip at the top and bottom.
|
||||||
|
#define BOTTOM_SKIP 100
|
||||||
|
#define TOP_SKIP 0
|
||||||
|
|
||||||
|
// Spectrum visualizer range
|
||||||
|
#define MIN_HZ 100
|
||||||
|
#define MAX_HZ 5000
|
||||||
|
#endif
|
16
src/dict.cpp
16
src/dict.cpp
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
10
src/dict.hpp
10
src/dict.hpp
@ -1,10 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
#include <unordered_set>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
extern std::unordered_set<std::string> word_dict;
|
|
||||||
|
|
||||||
|
|
||||||
void load_file();
|
|
@ -205,10 +205,32 @@ 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:
|
||||||
|
|
||||||
|
// Byte 1: animation mode
|
||||||
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 0x{0:02x}", read_buf[1]);
|
||||||
animation_mode = read_buf[1];
|
animation_mode = read_buf[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Bytes 2,3,4,5: layer state
|
||||||
|
uint32_t new_layer_state =
|
||||||
|
(read_buf[5] << 24) |
|
||||||
|
(read_buf[4] << 16) |
|
||||||
|
(read_buf[3] << 8) |
|
||||||
|
(read_buf[2] << 0);
|
||||||
|
|
||||||
|
if (layer_state != new_layer_state) {
|
||||||
|
layer_state = new_layer_state;
|
||||||
|
spdlog::info("Layer set to 0b{0:032b}", layer_state);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Byte 6: desired OS layout for layer
|
||||||
|
if (layer_layout != read_buf[6]) {
|
||||||
|
layer_layout = read_buf[6];
|
||||||
|
spdlog::info("Layout set to 0x{0:02x}", read_buf[6]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Main code should not parse state packets.
|
// Main code should not parse state packets.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ hid_init() and hid_exit().
|
|||||||
class Ergodox {
|
class Ergodox {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// USB Device paramaters
|
// USB Device parameters
|
||||||
const unsigned short vendor_id;
|
const unsigned short vendor_id;
|
||||||
const unsigned short product_id;
|
const unsigned short product_id;
|
||||||
const unsigned short usage;
|
const unsigned short usage;
|
||||||
@ -54,6 +54,9 @@ class Ergodox {
|
|||||||
// Getter methods
|
// Getter methods
|
||||||
uint8_t get_animation_mode() const { return animation_mode; }
|
uint8_t get_animation_mode() const { return animation_mode; }
|
||||||
bool is_connected() const { return connected; }
|
bool is_connected() const { return connected; }
|
||||||
|
uint32_t get_layer_state() const {return layer_state; }
|
||||||
|
uint8_t get_layer_layout() const { return layer_layout; }
|
||||||
|
bool is_layer_on(uint8_t layer) const { return (layer_state >> layer) % 2; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ergodox(
|
Ergodox(
|
||||||
@ -78,6 +81,12 @@ class Ergodox {
|
|||||||
// Which animation is the keyboard running right now?
|
// Which animation is the keyboard running right now?
|
||||||
// See CMD_SEND_STATE in commands.h for docs.
|
// See CMD_SEND_STATE in commands.h for docs.
|
||||||
uint8_t animation_mode;
|
uint8_t animation_mode;
|
||||||
|
// Active layer bitmask.
|
||||||
|
// See CMD_SEND_STATE in commands.h for docs.
|
||||||
|
uint32_t layer_state;
|
||||||
|
// Desired layout for active layer.
|
||||||
|
// See CMD_SEND_STATE in commands.h for docs.
|
||||||
|
uint8_t layer_layout;
|
||||||
// Are we connected to a keyboard right now?
|
// Are we connected to a keyboard right now?
|
||||||
bool connected;
|
bool connected;
|
||||||
};
|
};
|
168
src/main.cpp
168
src/main.cpp
@ -2,28 +2,34 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
// For reading FIFO
|
// For reading FIFO
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
// For sleep
|
|
||||||
#include <chrono>
|
|
||||||
#include <thread>
|
|
||||||
// MPD client
|
|
||||||
#include "mpd/client.h"
|
|
||||||
|
|
||||||
#include <string>
|
// For sleep
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
// Local files
|
// Local files
|
||||||
#include "utility/bitmap.hpp"
|
|
||||||
#include "utility/buffer.hpp"
|
|
||||||
#include "signal_processing/fft.hpp"
|
|
||||||
#include "ergodox.hpp"
|
#include "ergodox.hpp"
|
||||||
#include "commands.h"
|
#include "commands.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
|
||||||
#include "spdlog/spdlog.h"
|
#include "spdlog/spdlog.h"
|
||||||
|
|
||||||
#include "dict.hpp"
|
#ifndef DISABLE_SPECIAL_CHAR
|
||||||
|
#include "modules/special_chars.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef DISABLE_SPELL
|
||||||
|
#include "modules/spell.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef DISABLE_VISUALIZER
|
||||||
|
#include "modules/visualizer.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
//
|
//
|
||||||
@ -53,97 +59,33 @@
|
|||||||
// pcm from pulse
|
// pcm from pulse
|
||||||
|
|
||||||
|
|
||||||
const size_t width = 10;
|
// HID interface wrapper
|
||||||
const size_t height = BOTTOM_SKIP + KB_RESOLUTION + TOP_SKIP;
|
Ergodox Dox = Ergodox::init(
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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:
|
|
||||||
// (44100 / fps * 10), make 10 bigger for slower scrolling
|
|
||||||
//
|
|
||||||
// Double both buffer sizes if stereo
|
|
||||||
|
|
||||||
// FFT generator
|
|
||||||
FFT_Visualizer fft = FFT_Visualizer(
|
|
||||||
width, height, MIN_HZ, MAX_HZ
|
|
||||||
);
|
|
||||||
|
|
||||||
// Audio buffer
|
|
||||||
Buffer buf = Buffer(
|
|
||||||
"/tmp/mpd.fifo",
|
|
||||||
44100 / 2, // Keep 500ms of data in buffer
|
|
||||||
fft.compute_buffer_output_size()
|
|
||||||
);
|
|
||||||
|
|
||||||
// HID interface wrapper
|
|
||||||
Ergodox Dox = Ergodox::init(
|
|
||||||
HID_VENDOR_ID,
|
HID_VENDOR_ID,
|
||||||
HID_PRODUCT_ID,
|
HID_PRODUCT_ID,
|
||||||
HID_USAGE,
|
HID_USAGE,
|
||||||
HID_USAGE_PAGE
|
HID_USAGE_PAGE
|
||||||
);
|
);
|
||||||
|
|
||||||
// Write buffer
|
|
||||||
uint8_t hid_buf[Dox.packet_size];
|
int main(int argc, char *argv[]) {
|
||||||
|
spdlog::set_level(spdlog::level::info);
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t last_layer_layout;
|
||||||
|
|
||||||
Dox.connect_loop();
|
Dox.connect_loop();
|
||||||
|
|
||||||
|
#ifndef DISABLE_VISUALIZER
|
||||||
// Frame rate limiter
|
Visualizer::init();
|
||||||
std::chrono::time_point<
|
#endif
|
||||||
std::chrono::steady_clock,
|
|
||||||
std::chrono::nanoseconds
|
|
||||||
> t = std::chrono::steady_clock::now();
|
|
||||||
|
|
||||||
std::chrono::time_point<
|
|
||||||
std::chrono::steady_clock,
|
|
||||||
std::chrono::nanoseconds
|
|
||||||
> last_fifo_sync = std::chrono::steady_clock::now();
|
|
||||||
|
|
||||||
struct mpd_connection *conn = mpd_connection_new(NULL, 0, 0);
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
||||||
if (Dox.is_connected()) {
|
if (Dox.is_connected()) {
|
||||||
if (std::chrono::steady_clock::now() > t + std::chrono::milliseconds(30)) {
|
#ifndef DISABLE_VISUALIZER
|
||||||
if (Dox.get_animation_mode() == 0x02) {
|
Visualizer::fn(Dox);
|
||||||
if (std::chrono::steady_clock::now() > last_fifo_sync + std::chrono::seconds(10)) {
|
#endif
|
||||||
mpd_run_disable_output(conn, 1);
|
|
||||||
mpd_run_enable_output(conn, 1);
|
|
||||||
last_fifo_sync = std::chrono::steady_clock::now();
|
|
||||||
spdlog::info("Synchronized fifo");
|
|
||||||
}
|
|
||||||
|
|
||||||
buf.update();
|
|
||||||
fft.update(buf);
|
|
||||||
|
|
||||||
for (size_t i = 0; i < 10; i++) {
|
|
||||||
// Get height from fft, apply bottom_skip
|
|
||||||
ssize_t h = fft.get_output()[i] - BOTTOM_SKIP;
|
|
||||||
|
|
||||||
// Enforce max and min
|
|
||||||
// max implicitly enforces top_skip
|
|
||||||
h = h>KB_RESOLUTION ? KB_RESOLUTION : h;
|
|
||||||
h = h<0 ? 0 : h;
|
|
||||||
|
|
||||||
hid_buf[i] = h;
|
|
||||||
}
|
|
||||||
Dox.write(CMD_ANIM_DATA, hid_buf, Dox.packet_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
t = std::chrono::steady_clock::now();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dox.write might detect that we've been disconnected,
|
// Dox.write might detect that we've been disconnected,
|
||||||
// and Dox.read will fail if we are.
|
// and Dox.read will fail if we are.
|
||||||
@ -154,25 +96,39 @@ 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:
|
|
||||||
char word_chars[Dox.read_buf[1] + 1];
|
|
||||||
|
|
||||||
for (int i=0; i < Dox.read_buf[1]; i++) {
|
#ifndef DISABLE_SPELL
|
||||||
// A in ascii:
|
case CMD_SPELLCHECK_WORD: {
|
||||||
// a in ascii: 0x61
|
Spell::do_cmd(Dox);
|
||||||
// KC_A: 0x04
|
break;
|
||||||
word_chars[i] = Dox.read_buf[i + 2] + 0x5D;
|
|
||||||
}
|
}
|
||||||
word_chars[Dox.read_buf[1]] = 0x00; // Terminate with null char
|
#endif
|
||||||
|
|
||||||
std::string word = std::string(word_chars);
|
#ifndef DISABLE_SPECIAL_CHAR
|
||||||
|
case CMD_SPECIAL_CHAR: {
|
||||||
if (word_dict.find(word) == word_dict.end()) {
|
SpecialChars::do_cmd(Dox);
|
||||||
hid_buf[0] = 0x01;
|
break;
|
||||||
Dox.write(CMD_SPELLCHECK_WORD, hid_buf, Dox.packet_size);
|
|
||||||
spdlog::info("Got typo: \"{0:s}\" not in dict", word);
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Switch layer if necessary.
|
||||||
|
if (
|
||||||
|
(last_layer_layout != Dox.get_layer_layout()) &&
|
||||||
|
(Dox.get_layer_layout() != LAYOUT_NULL)
|
||||||
|
) {
|
||||||
|
|
||||||
|
last_layer_layout = Dox.get_layer_layout();
|
||||||
|
|
||||||
|
switch(last_layer_layout) {
|
||||||
|
case (LAYOUT_EN):
|
||||||
|
std::system("awesome-client \"modules.ibus.set('en')\"");
|
||||||
|
break;
|
||||||
|
case (LAYOUT_RU):
|
||||||
|
std::system("awesome-client \"modules.ibus.set('ru')\"");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -188,6 +144,8 @@ int main(int argc, char *argv[]) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
mpd_connection_free(conn);
|
#ifndef DISABLE_VISUALIZER
|
||||||
|
Visualizer::cleanup();
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
25
src/modules/special_chars.cpp
Normal file
25
src/modules/special_chars.cpp
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#include "special_chars.hpp"
|
||||||
|
#ifndef DISABLE_SPECIAL_CHAR
|
||||||
|
|
||||||
|
|
||||||
|
namespace SpecialChars {
|
||||||
|
void do_cmd(Ergodox &Dox) {
|
||||||
|
// 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()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
28
src/modules/special_chars.hpp
Normal file
28
src/modules/special_chars.hpp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "config.h"
|
||||||
|
#ifndef DISABLE_SPECIAL_CHAR
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include "ergodox.hpp"
|
||||||
|
|
||||||
|
namespace SpecialChars {
|
||||||
|
const std::string special_chars[] = {
|
||||||
|
|
||||||
|
// These characters are used to type
|
||||||
|
// symbols on layouts that don't have
|
||||||
|
// them.
|
||||||
|
"\\`",
|
||||||
|
"~",
|
||||||
|
"'",
|
||||||
|
"[",
|
||||||
|
"]",
|
||||||
|
"{",
|
||||||
|
"}",
|
||||||
|
"«",
|
||||||
|
"»"
|
||||||
|
};
|
||||||
|
|
||||||
|
void do_cmd(Ergodox &Dox);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
133
src/modules/spell.cpp
Normal file
133
src/modules/spell.cpp
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
#include "spell.hpp"
|
||||||
|
#ifndef DISABLE_SPELL
|
||||||
|
|
||||||
|
namespace Spell {
|
||||||
|
Hunspell* hun = new Hunspell(HUNSPELL_AFF_EN, HUNSPELL_DIC_EN);
|
||||||
|
uint8_t hid_buf[RAW_EPSIZE]; // Write buffer
|
||||||
|
|
||||||
|
|
||||||
|
// Replacement chars for now, since wide strings are hard.
|
||||||
|
char ru_kc_to_char(uint8_t keycode) {
|
||||||
|
switch (keycode) {
|
||||||
|
case KC_GRAVE:
|
||||||
|
return '~';//L"ё";
|
||||||
|
case KC_1:
|
||||||
|
return '1';//L"1";
|
||||||
|
case KC_2:
|
||||||
|
return '2';//L"2";
|
||||||
|
case KC_3:
|
||||||
|
return '3';//L"3";
|
||||||
|
case KC_4:
|
||||||
|
return '4';//L"4";
|
||||||
|
case KC_5:
|
||||||
|
return '5';//L"5";
|
||||||
|
case KC_6:
|
||||||
|
return '6';//L"6";
|
||||||
|
case KC_7:
|
||||||
|
return '7';//L"7";
|
||||||
|
case KC_8:
|
||||||
|
return '8';//L"8";
|
||||||
|
case KC_9:
|
||||||
|
return '9';//L"9";
|
||||||
|
case KC_0:
|
||||||
|
return '0';//L"0";
|
||||||
|
case KC_Q:
|
||||||
|
return '^';//L"й";
|
||||||
|
case KC_W:
|
||||||
|
return '*';//L"ц";
|
||||||
|
case KC_E:
|
||||||
|
return 'y';//L"у";
|
||||||
|
case KC_R:
|
||||||
|
return 'k';//L"к";
|
||||||
|
case KC_T:
|
||||||
|
return 'e';//L"е";
|
||||||
|
case KC_Y:
|
||||||
|
return 'H';//L"н";
|
||||||
|
case KC_U:
|
||||||
|
return 'g';//L"г";
|
||||||
|
case KC_I:
|
||||||
|
return 'w';//L"ш";
|
||||||
|
case KC_O:
|
||||||
|
return 'W';//L"щ";
|
||||||
|
case KC_P:
|
||||||
|
return 'z';//L"з";
|
||||||
|
case KC_LEFT_BRACKET:
|
||||||
|
return 'x';//L"х";
|
||||||
|
case KC_RIGHT_BRACKET:
|
||||||
|
return '!';//L"ъ";
|
||||||
|
case KC_A:
|
||||||
|
return 'f';//L"ф";
|
||||||
|
case KC_S:
|
||||||
|
return 'i';//L"ы";
|
||||||
|
case KC_D:
|
||||||
|
return 'B';//L"в";
|
||||||
|
case KC_F:
|
||||||
|
return 'a';//L"а";
|
||||||
|
case KC_G:
|
||||||
|
return 'n';//L"п";
|
||||||
|
case KC_H:
|
||||||
|
return 'p';//L"р";
|
||||||
|
case KC_J:
|
||||||
|
return 'o';//L"о";
|
||||||
|
case KC_K:
|
||||||
|
return 'l';//L"л";
|
||||||
|
case KC_L:
|
||||||
|
return 'd';//L"д";
|
||||||
|
case KC_SEMICOLON:
|
||||||
|
return 'j';//L"ж";
|
||||||
|
case KC_QUOTE:
|
||||||
|
return 'E';//L"э";
|
||||||
|
case KC_Z:
|
||||||
|
return 'R';//L"я";
|
||||||
|
case KC_X:
|
||||||
|
return 'q';//L"ч";
|
||||||
|
case KC_C:
|
||||||
|
return 'c';//L"с";
|
||||||
|
case KC_V:
|
||||||
|
return 'm';//L"м";
|
||||||
|
case KC_B:
|
||||||
|
return 'n';//L"и";
|
||||||
|
case KC_N:
|
||||||
|
return 't';//L"т";
|
||||||
|
case KC_M:
|
||||||
|
return '=';//L"ь";
|
||||||
|
case KC_COMMA:
|
||||||
|
return 'b';//L"б";
|
||||||
|
case KC_DOT:
|
||||||
|
return 'u';//L"ю";
|
||||||
|
default:
|
||||||
|
spdlog::warn("Unknown keycode passed to ru_kc_to_char");
|
||||||
|
return '?';//L"?";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void do_cmd(Ergodox &Dox) {
|
||||||
|
char word_chars[Dox.read_buf[1] + 1];
|
||||||
|
|
||||||
|
if (Dox.get_layer_layout() == LAYOUT_EN) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
} else if (Dox.get_layer_layout() == LAYOUT_RU) {
|
||||||
|
for (int i=0; i < Dox.read_buf[1]; i++) {
|
||||||
|
word_chars[i] = ru_kc_to_char(Dox.read_buf[i + 2]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
word_chars[Dox.read_buf[1]] = 0x00; // Terminate with null char
|
||||||
|
std::string word = std::string(word_chars);
|
||||||
|
|
||||||
|
int dp = hun->spell(word);
|
||||||
|
if (!dp) {
|
||||||
|
memset(hid_buf, 0, sizeof(uint8_t) * Dox.packet_size);
|
||||||
|
hid_buf[0] = 0x01;
|
||||||
|
Dox.write(CMD_SPELLCHECK_WORD, hid_buf, Dox.packet_size);
|
||||||
|
//spdlog::info("Got typo: \"{0:s}\" not in dict", word);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
181
src/modules/spell.hpp
Normal file
181
src/modules/spell.hpp
Normal file
@ -0,0 +1,181 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "config.h"
|
||||||
|
#ifndef DISABLE_SPELL
|
||||||
|
|
||||||
|
#include "hunspell.hxx"
|
||||||
|
#include "ergodox.hpp"
|
||||||
|
|
||||||
|
namespace Spell {
|
||||||
|
char ru_kc_to_char(uint8_t keycode);
|
||||||
|
void do_cmd(Ergodox &Dox);
|
||||||
|
}
|
||||||
|
|
||||||
|
enum hid_keyboard_keypad_usage {
|
||||||
|
KC_NO = 0x00,
|
||||||
|
KC_ROLL_OVER,
|
||||||
|
KC_POST_FAIL,
|
||||||
|
KC_UNDEFINED,
|
||||||
|
KC_A,
|
||||||
|
KC_B,
|
||||||
|
KC_C,
|
||||||
|
KC_D,
|
||||||
|
KC_E,
|
||||||
|
KC_F,
|
||||||
|
KC_G,
|
||||||
|
KC_H,
|
||||||
|
KC_I,
|
||||||
|
KC_J,
|
||||||
|
KC_K,
|
||||||
|
KC_L,
|
||||||
|
KC_M, // 0x10
|
||||||
|
KC_N,
|
||||||
|
KC_O,
|
||||||
|
KC_P,
|
||||||
|
KC_Q,
|
||||||
|
KC_R,
|
||||||
|
KC_S,
|
||||||
|
KC_T,
|
||||||
|
KC_U,
|
||||||
|
KC_V,
|
||||||
|
KC_W,
|
||||||
|
KC_X,
|
||||||
|
KC_Y,
|
||||||
|
KC_Z,
|
||||||
|
KC_1,
|
||||||
|
KC_2,
|
||||||
|
KC_3, // 0x20
|
||||||
|
KC_4,
|
||||||
|
KC_5,
|
||||||
|
KC_6,
|
||||||
|
KC_7,
|
||||||
|
KC_8,
|
||||||
|
KC_9,
|
||||||
|
KC_0,
|
||||||
|
KC_ENTER,
|
||||||
|
KC_ESCAPE,
|
||||||
|
KC_BACKSPACE,
|
||||||
|
KC_TAB,
|
||||||
|
KC_SPACE,
|
||||||
|
KC_MINUS,
|
||||||
|
KC_EQUAL,
|
||||||
|
KC_LEFT_BRACKET,
|
||||||
|
KC_RIGHT_BRACKET, // 0x30
|
||||||
|
KC_BACKSLASH,
|
||||||
|
KC_NONUS_HASH,
|
||||||
|
KC_SEMICOLON,
|
||||||
|
KC_QUOTE,
|
||||||
|
KC_GRAVE,
|
||||||
|
KC_COMMA,
|
||||||
|
KC_DOT,
|
||||||
|
KC_SLASH,
|
||||||
|
KC_CAPS_LOCK,
|
||||||
|
KC_F1,
|
||||||
|
KC_F2,
|
||||||
|
KC_F3,
|
||||||
|
KC_F4,
|
||||||
|
KC_F5,
|
||||||
|
KC_F6,
|
||||||
|
KC_F7, // 0x40
|
||||||
|
KC_F8,
|
||||||
|
KC_F9,
|
||||||
|
KC_F10,
|
||||||
|
KC_F11,
|
||||||
|
KC_F12,
|
||||||
|
KC_PRINT_SCREEN,
|
||||||
|
KC_SCROLL_LOCK,
|
||||||
|
KC_PAUSE,
|
||||||
|
KC_INSERT,
|
||||||
|
KC_HOME,
|
||||||
|
KC_PAGE_UP,
|
||||||
|
KC_DELETE,
|
||||||
|
KC_END,
|
||||||
|
KC_PAGE_DOWN,
|
||||||
|
KC_RIGHT,
|
||||||
|
KC_LEFT, // 0x50
|
||||||
|
KC_DOWN,
|
||||||
|
KC_UP,
|
||||||
|
KC_NUM_LOCK,
|
||||||
|
KC_KP_SLASH,
|
||||||
|
KC_KP_ASTERISK,
|
||||||
|
KC_KP_MINUS,
|
||||||
|
KC_KP_PLUS,
|
||||||
|
KC_KP_ENTER,
|
||||||
|
KC_KP_1,
|
||||||
|
KC_KP_2,
|
||||||
|
KC_KP_3,
|
||||||
|
KC_KP_4,
|
||||||
|
KC_KP_5,
|
||||||
|
KC_KP_6,
|
||||||
|
KC_KP_7,
|
||||||
|
KC_KP_8, // 0x60
|
||||||
|
KC_KP_9,
|
||||||
|
KC_KP_0,
|
||||||
|
KC_KP_DOT,
|
||||||
|
KC_NONUS_BACKSLASH,
|
||||||
|
KC_APPLICATION,
|
||||||
|
KC_KB_POWER,
|
||||||
|
KC_KP_EQUAL,
|
||||||
|
KC_F13,
|
||||||
|
KC_F14,
|
||||||
|
KC_F15,
|
||||||
|
KC_F16,
|
||||||
|
KC_F17,
|
||||||
|
KC_F18,
|
||||||
|
KC_F19,
|
||||||
|
KC_F20,
|
||||||
|
KC_F21, // 0x70
|
||||||
|
KC_F22,
|
||||||
|
KC_F23,
|
||||||
|
KC_F24,
|
||||||
|
KC_EXECUTE,
|
||||||
|
KC_HELP,
|
||||||
|
KC_MENU,
|
||||||
|
KC_SELECT,
|
||||||
|
KC_STOP,
|
||||||
|
KC_AGAIN,
|
||||||
|
KC_UNDO,
|
||||||
|
KC_CUT,
|
||||||
|
KC_COPY,
|
||||||
|
KC_PASTE,
|
||||||
|
KC_FIND,
|
||||||
|
KC_KB_MUTE,
|
||||||
|
KC_KB_VOLUME_UP, // 0x80
|
||||||
|
KC_KB_VOLUME_DOWN,
|
||||||
|
KC_LOCKING_CAPS_LOCK,
|
||||||
|
KC_LOCKING_NUM_LOCK,
|
||||||
|
KC_LOCKING_SCROLL_LOCK,
|
||||||
|
KC_KP_COMMA,
|
||||||
|
KC_KP_EQUAL_AS400,
|
||||||
|
KC_INTERNATIONAL_1,
|
||||||
|
KC_INTERNATIONAL_2,
|
||||||
|
KC_INTERNATIONAL_3,
|
||||||
|
KC_INTERNATIONAL_4,
|
||||||
|
KC_INTERNATIONAL_5,
|
||||||
|
KC_INTERNATIONAL_6,
|
||||||
|
KC_INTERNATIONAL_7,
|
||||||
|
KC_INTERNATIONAL_8,
|
||||||
|
KC_INTERNATIONAL_9,
|
||||||
|
KC_LANGUAGE_1, // 0x90
|
||||||
|
KC_LANGUAGE_2,
|
||||||
|
KC_LANGUAGE_3,
|
||||||
|
KC_LANGUAGE_4,
|
||||||
|
KC_LANGUAGE_5,
|
||||||
|
KC_LANGUAGE_6,
|
||||||
|
KC_LANGUAGE_7,
|
||||||
|
KC_LANGUAGE_8,
|
||||||
|
KC_LANGUAGE_9,
|
||||||
|
KC_ALTERNATE_ERASE,
|
||||||
|
KC_SYSTEM_REQUEST,
|
||||||
|
KC_CANCEL,
|
||||||
|
KC_CLEAR,
|
||||||
|
KC_PRIOR,
|
||||||
|
KC_RETURN,
|
||||||
|
KC_SEPARATOR,
|
||||||
|
KC_OUT, // 0xA0
|
||||||
|
KC_OPER,
|
||||||
|
KC_CLEAR_AGAIN,
|
||||||
|
KC_CRSEL,
|
||||||
|
KC_EXSEL,
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
80
src/modules/visualizer.cpp
Normal file
80
src/modules/visualizer.cpp
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
#include "visualizer.hpp"
|
||||||
|
#ifndef DISABLE_VISUALIZER
|
||||||
|
|
||||||
|
namespace Visualizer {
|
||||||
|
uint8_t hid_buf[RAW_EPSIZE]; // Write buffer
|
||||||
|
struct mpd_connection *conn;
|
||||||
|
|
||||||
|
FFT_Visualizer fft = FFT_Visualizer(
|
||||||
|
width, height, MIN_HZ, MAX_HZ
|
||||||
|
);
|
||||||
|
|
||||||
|
std::chrono::time_point<
|
||||||
|
std::chrono::steady_clock,
|
||||||
|
std::chrono::nanoseconds
|
||||||
|
> t;
|
||||||
|
|
||||||
|
std::chrono::time_point<
|
||||||
|
std::chrono::steady_clock,
|
||||||
|
std::chrono::nanoseconds
|
||||||
|
> last_fifo_sync;
|
||||||
|
|
||||||
|
// buffer size for waveform:
|
||||||
|
// (44100 / fps * 10), make 10 bigger for slower scrolling
|
||||||
|
//
|
||||||
|
// Double both buffer sizes if stereo
|
||||||
|
Buffer buf = Buffer(
|
||||||
|
"/tmp/mpd.fifo",
|
||||||
|
44100 / 2, // Keep 500ms of data in buffer
|
||||||
|
fft.compute_buffer_output_size()
|
||||||
|
);
|
||||||
|
|
||||||
|
void init() {
|
||||||
|
// Frame rate limiter
|
||||||
|
t = std::chrono::steady_clock::now();
|
||||||
|
last_fifo_sync = std::chrono::steady_clock::now();
|
||||||
|
conn = mpd_connection_new(NULL, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void cleanup() {
|
||||||
|
mpd_connection_free(Visualizer::conn);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fn(Ergodox &Dox) {
|
||||||
|
if (std::chrono::steady_clock::now() > t + std::chrono::milliseconds(30)) {
|
||||||
|
if (Dox.get_animation_mode() == 0x02) {
|
||||||
|
|
||||||
|
// Animation data type
|
||||||
|
hid_buf[1] = CMD_ANIM_DATA_fft;
|
||||||
|
|
||||||
|
if (std::chrono::steady_clock::now() > last_fifo_sync + std::chrono::seconds(10)) {
|
||||||
|
mpd_run_disable_output(conn, 1);
|
||||||
|
mpd_run_enable_output(conn, 1);
|
||||||
|
last_fifo_sync = std::chrono::steady_clock::now();
|
||||||
|
spdlog::info("Synchronized fifo");
|
||||||
|
}
|
||||||
|
|
||||||
|
buf.update();
|
||||||
|
fft.update(buf);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < 10; i++) {
|
||||||
|
// Get height from fft, apply bottom_skip
|
||||||
|
ssize_t h = fft.get_output()[i] - BOTTOM_SKIP;
|
||||||
|
|
||||||
|
// Enforce max and min
|
||||||
|
// max implicitly enforces top_skip
|
||||||
|
h = h>KB_RESOLUTION ? KB_RESOLUTION : h;
|
||||||
|
h = h<0 ? 0 : h;
|
||||||
|
|
||||||
|
hid_buf[i + 1] = h;
|
||||||
|
}
|
||||||
|
Dox.write(CMD_ANIM_DATA, hid_buf, Dox.packet_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
t = std::chrono::steady_clock::now();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
23
src/modules/visualizer.hpp
Normal file
23
src/modules/visualizer.hpp
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "config.h"
|
||||||
|
#ifndef DISABLE_VISUALIZER
|
||||||
|
|
||||||
|
#include "utility/buffer.hpp"
|
||||||
|
#include <chrono>
|
||||||
|
#include "mpd/client.h"
|
||||||
|
#include "signal_processing/fft.hpp"
|
||||||
|
#include "spdlog/spdlog.h"
|
||||||
|
#include "ergodox.hpp"
|
||||||
|
#include "commands.h"
|
||||||
|
|
||||||
|
namespace Visualizer {
|
||||||
|
|
||||||
|
const size_t width = 10;
|
||||||
|
const size_t height = BOTTOM_SKIP + KB_RESOLUTION + TOP_SKIP;
|
||||||
|
|
||||||
|
void cleanup();
|
||||||
|
void init();
|
||||||
|
void fn(Ergodox &Dox);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -1,5 +1,9 @@
|
|||||||
#include "bitmap.hpp"
|
#include "bitmap.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
// Simple bitmap library.
|
||||||
|
// Used to debug music visualizer.
|
||||||
|
|
||||||
Bitmap::Bitmap(size_t w, size_t h) {
|
Bitmap::Bitmap(size_t w, size_t h) {
|
||||||
this->width = w;
|
this->width = w;
|
||||||
this->height = h;
|
this->height = h;
|
||||||
|
Reference in New Issue
Block a user