Minor cleanup

This commit is contained in:
2022-07-08 16:56:32 -07:00
parent a9eb47debe
commit 3c154a7679
4 changed files with 68 additions and 41 deletions
+32 -39
View File
@@ -5,9 +5,6 @@
// For reading FIFO
#include <fcntl.h>
#include <unistd.h>
// For sleep
#include <chrono>
#include <thread>
// Local files
#include "utility/bitmap.hpp"
@@ -15,31 +12,36 @@
#include "signal_processing/fft.hpp"
#include "ergodox.hpp"
#include "commands.h"
#include "config.h"
// TODO:
// stereo support (and maybe different bitrates?)
// Optimization: don't copy filename in buffer?
// understand consumption rate
// understand BIN2HZ
// understand values and sizes (DFT_TOTAL, DFT_NONZERO, etc)
// note that wave and spectrum have different sizes
//
// MPD interface
// beat detection
// How many keys in a column * resolution per key.
// this MUST fit inside a uint8_t.
const uint8_t kb_resolution = 5 * 50;
// How many resolution steps to skip at the top and bottom.
const size_t bottom_skip = 25;
const size_t top_skip = 50;
// FFT:
// stereo support (and maybe different bitrates?)
// Optimization: don't copy filename in buffer?
// understand consumption rate
// understand BIN2HZ
// understand values and sizes (DFT_TOTAL, DFT_NONZERO, etc)
// note that wave and spectrum have different sizes
// clear fft when not in use
//
// MPD interface
//
// Keyboard interface:
// Frame rate limit
// Clean up reconnect code
// Better log messages
//
// Get parameters from keyboard (width, height, etc)
//
// Later:
// beat detection
// waveform animation
const size_t width = 10;
const size_t height = bottom_skip + kb_resolution + top_skip;
const size_t height = BOTTOM_SKIP + KB_RESOLUTION + TOP_SKIP;
int main(int argc, char *argv[]) {
@@ -51,8 +53,7 @@ int main(int argc, char *argv[]) {
// FFT generator
FFT_Visualizer fft = FFT_Visualizer(
width, height,
100, 5000
width, height, MIN_HZ, MAX_HZ
);
// Audio buffer
@@ -64,20 +65,16 @@ int main(int argc, char *argv[]) {
// HID interface wrapper
Ergodox Dox = Ergodox::init(
0x3297,
0x4976,
0x61,
0xFF60
HID_VENDOR_ID,
HID_PRODUCT_ID,
HID_USAGE,
HID_USAGE_PAGE
);
// Write buffer
uint8_t hid_buf[Dox.packet_size];
wprintf(L"Trying to connect...\n");
while (!Dox.is_connected()) {
Dox.try_connect();
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
Dox.connect_loop();
while (1) {
@@ -90,11 +87,11 @@ int main(int argc, char *argv[]) {
hid_buf[0] = CMD_ANIM_DATA_fft;
for (size_t i = 0; i < 10; i++) {
// 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;
// Enforce max and min
// max implicitly enforces top_skip
h = h>kb_resolution ? kb_resolution : h;
h = h>KB_RESOLUTION ? KB_RESOLUTION : h;
h = h<0 ? 0 : h;
hid_buf[i + 1] = h;
@@ -118,11 +115,7 @@ int main(int argc, char *argv[]) {
}
}
} else {
wprintf(L"Trying to connect...\n");
while (!Dox.is_connected()) {
Dox.try_connect();
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
Dox.connect_loop();
}
}