Upgraded hid interface

This commit is contained in:
2022-07-08 10:41:19 -07:00
parent dacb8d820d
commit 6f2c2e313e
5 changed files with 167 additions and 30 deletions
+24 -10
View File
@@ -5,12 +5,24 @@
#include <wchar.h>
#include "hidapi.h"
#include "config.h"
#include "commands.h"
/*
A singleton Ergodox interface. Wraps all hidapi methods, including
hid_init() and hid_exit().
*/
class Ergodox {
public:
// USB Device paramaters
const unsigned short vendor_id;
const unsigned short product_id;
const unsigned short usage;
const unsigned short usage_page;
const uint8_t packet_size = RAW_EPSIZE;
static Ergodox& init(
unsigned short vendor_id,
unsigned short product_id,
@@ -20,11 +32,15 @@ class Ergodox {
~Ergodox();
int write(
uint8_t* data,
size_t length
) const;
int write(uint8_t cmd, const uint8_t* data, uint8_t data_len) const;
bool read();
// Read buffer, len = packet_size.
// Filled by read().
uint8_t read_buf[RAW_EPSIZE];
uint8_t get_animation_mode() const { return animation_mode; }
private:
Ergodox(
@@ -42,13 +58,11 @@ class Ergodox {
void open();
void close();
// USB Device paramaters
const unsigned short vendor_id;
const unsigned short product_id;
const unsigned short usage;
const unsigned short usage_page;
// HID device.
// NULL if not opened.
hid_device* handle;
// Keyboard state variables.
// Updated by read().
uint8_t animation_mode;
};