Added ergodox hid manager
This commit is contained in:
+10
-57
@@ -1,27 +1,17 @@
|
||||
#include <stdio.h>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <stdexcept>
|
||||
|
||||
// For reading FIFO
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
// Math libs
|
||||
#include <math.h>
|
||||
#include <fftw3.h>
|
||||
// HIDapi
|
||||
#include <wchar.h>
|
||||
#include "hidapi.h"
|
||||
|
||||
// Local files
|
||||
#include "utility/bitmap.hpp"
|
||||
#include "utility/buffer.hpp"
|
||||
#include "signal_processing/fft.hpp"
|
||||
|
||||
|
||||
#define HID_VEND 0x3297
|
||||
#define HID_PROD 0x4976
|
||||
#define HID_USAGE 0x61
|
||||
#define HID_PAGE 0xff60
|
||||
#include "ergodox.hpp"
|
||||
|
||||
|
||||
// TODO:
|
||||
@@ -37,36 +27,6 @@
|
||||
// beat detection
|
||||
|
||||
|
||||
hid_device* get_keyboard() {
|
||||
struct hid_device_info *devs, *cur_dev;
|
||||
const char *path_to_open = NULL;
|
||||
hid_device *handle = NULL;
|
||||
|
||||
devs = hid_enumerate(HID_VEND, HID_PROD);
|
||||
cur_dev = devs;
|
||||
while (cur_dev) {
|
||||
if (cur_dev->vendor_id == HID_VEND &&
|
||||
cur_dev->product_id == HID_PROD &&
|
||||
cur_dev->usage == HID_USAGE&&
|
||||
cur_dev->usage_page == HID_PAGE
|
||||
) {
|
||||
path_to_open = cur_dev->path;
|
||||
break;
|
||||
}
|
||||
cur_dev = cur_dev->next;
|
||||
}
|
||||
|
||||
if (path_to_open) {
|
||||
handle = hid_open_path(path_to_open);
|
||||
} else {
|
||||
wprintf(L"Could not find device, exiting.\n");
|
||||
exit(1);
|
||||
}
|
||||
hid_free_enumeration(devs);
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
||||
void draw_spectrum_bitmap(
|
||||
const std::vector<size_t>& waveform,
|
||||
Bitmap& bitmap
|
||||
@@ -84,15 +44,13 @@ const size_t height = 150;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
|
||||
// HID connect
|
||||
int res;
|
||||
uint8_t hid_buf[65];
|
||||
hid_device *handle;
|
||||
// Initialize the hidapi library
|
||||
hid_init();
|
||||
// Get Ergodox
|
||||
handle = get_keyboard();
|
||||
uint8_t hid_buf[20];
|
||||
Ergodox Dox = Ergodox::init(
|
||||
0x3297,
|
||||
0x4976,
|
||||
0x61,
|
||||
0xFF60
|
||||
);
|
||||
|
||||
// buffer size for waveform:
|
||||
// (44100 / fps * 10), make 10 bigger for slower scrolling
|
||||
@@ -132,12 +90,7 @@ int main(int argc, char *argv[]) {
|
||||
hid_buf[i + 2] = h;
|
||||
}
|
||||
|
||||
res = hid_write(handle, hid_buf, 12);
|
||||
Dox.write(hid_buf, 12);
|
||||
}
|
||||
|
||||
// Close the device
|
||||
hid_close(handle);
|
||||
// Finalize the hidapi library
|
||||
hid_exit();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user