#pragma once #include #include #include // For sleep #include #include #include "spdlog/spdlog.h" #include "hidapi.h" #include "utility/misc.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, unsigned short usage, unsigned short usage_page ); ~Ergodox(); bool try_connect(); void disconnect(); void test_connection(); void connect_loop(); bool read(); bool write(uint8_t cmd, const uint8_t* data, uint8_t data_len); // Read buffer, len = packet_size. // Filled by read(). uint8_t read_buf[RAW_EPSIZE]; // Getter methods uint8_t get_animation_mode() const { return animation_mode; } bool is_connected() const { return connected; } private: Ergodox( unsigned short vendor_id, unsigned short product_id, unsigned short usage, unsigned short usage_page ); // Disable copy and assignment //Ergodox(void); //Ergodox(Ergodox& other); //Ergodox& operator=(Ergodox& other); // HID device. // NULL if not opened. hid_device* handle; // Keyboard state variables. // Updated by read(). // Which animation is the keyboard running right now? // See CMD_SEND_STATE in commands.h for docs. uint8_t animation_mode; // Are we connected to a keyboard right now? bool connected; };