Updated HIDDevices for new, modified Pluggable HID version

Keyboard got improved a bit as well.
This commit is contained in:
NicoHood 2015-09-19 13:15:32 +02:00
parent 36fdbb4987
commit 78c763e438
16 changed files with 60 additions and 74 deletions

View file

@ -10,7 +10,6 @@
https://github.com/NicoHood/HID/wiki/AbsoluteMouse-API
*/
#include "HID.h"
#include "HID-Project.h"
const int pinLed = LED_BUILTIN;

View file

@ -1,15 +1,14 @@
/*
Copyright (c) 2014-2015 NicoHood
See the readme for credit to other people.
Copyright (c) 2014-2015 NicoHood
See the readme for credit to other people.
Consumer example
Press a button to play/pause music player
See HID Project documentation for more Consumer keys.
https://github.com/NicoHood/HID/wiki/Consumer-API
Consumer example
Press a button to play/pause music player
See HID Project documentation for more Consumer keys.
https://github.com/NicoHood/HID/wiki/Consumer-API
*/
#include "HID.h"
#include "HID-Project.h"
const int pinLed = LED_BUILTIN;

View file

@ -9,7 +9,6 @@
https://github.com/NicoHood/HID/wiki/Gamepad-API
*/
#include "HID.h"
#include "HID-Project.h"
const int pinLed = LED_BUILTIN;

View file

@ -9,7 +9,6 @@
https://github.com/NicoHood/HID/wiki/System-API
*/
#include "HID.h"
#include "HID-Project.h"
const int pinLed = LED_BUILTIN;
@ -30,7 +29,7 @@ void loop() {
if (!digitalRead(pinButtonS)) {
digitalWrite(pinLed, HIGH);
// Puts pc into sleep mode/shuts it down
// Puts PC into sleep mode/shuts it down
System.write(SYSTEM_SLEEP);
//System.write(SYSTEM_POWER_DOWN);
@ -42,7 +41,7 @@ void loop() {
if (!digitalRead(pinButtonW)) {
digitalWrite(pinLed, HIGH);
// Tries to wake up the PC
// Try to wake up the PC
// This might fail on some PCs/Laptops where USB wakeup is not supported
System.write(SYSTEM_WAKE_UP);

View file

@ -98,7 +98,7 @@ typedef union{
};
} HID_MouseAbsoluteReport_Data_t;
class AbsMouse_
class AbsMouse_ : private HIDDevice
{
private:
int16_t xAxis = 0;
@ -131,13 +131,10 @@ private:
}
public:
inline AbsMouse_(void) {
static HID_Descriptor cb = {
.length = sizeof(_absmouseReportDescriptor),
.descriptor = _absmouseReportDescriptor,
};
static HIDDescriptorListNode node(&cb);
HID.AppendDescriptor(&node);
inline AbsMouse_(void):
HIDDevice((uint8_t*)_absmouseReportDescriptor, sizeof(_absmouseReportDescriptor), HID_REPORTID_MOUSE_ABSOLUTE)
{
// HID Descriptor is appended via the inherited HIDDevice class
}
inline void begin(void){
@ -165,7 +162,7 @@ public:
report.xAxis = x;
report.yAxis = y;
report.wheel = wheel;
HID.SendReport(HID_REPORTID_MOUSE_ABSOLUTE, &report, sizeof(report));
SendReport(&report, sizeof(report));
}
inline void move(int x, int y, signed char wheel = 0){

View file

@ -97,15 +97,12 @@ typedef union {
};
} HID_ConsumerControlReport_Data_t;
class Consumer_ {
class Consumer_ : private HIDDevice {
public:
inline Consumer_(void) {
static HID_Descriptor cb = {
.length = sizeof(_consumerReportDescriptor),
.descriptor = _consumerReportDescriptor,
};
static HIDDescriptorListNode node(&cb);
HID.AppendDescriptor(&node);
inline Consumer_(void) :
HIDDevice((uint8_t*)_consumerReportDescriptor, sizeof(_consumerReportDescriptor), HID_REPORTID_CONSUMERCONTROL)
{
// HID Descriptor is appended via the inherited HIDDevice class
}
inline void begin(void) {
@ -115,7 +112,7 @@ public:
inline void end(void) {
memset(&_report, 0, sizeof(_report));
HID.SendReport(HID_REPORTID_CONSUMERCONTROL, &_report, sizeof(_report));
SendReport(&_report, sizeof(_report));
}
inline void write(uint16_t m) {
@ -131,7 +128,7 @@ public:
break;
}
}
HID.SendReport(HID_REPORTID_CONSUMERCONTROL, &_report, sizeof(_report));
SendReport(&_report, sizeof(_report));
}
inline void release(uint16_t m) {
@ -142,7 +139,7 @@ public:
// no break to delete multiple keys
}
}
HID.SendReport(HID_REPORTID_CONSUMERCONTROL, &_report, sizeof(_report));
SendReport(&_report, sizeof(_report));
}
inline void releaseAll(void) {

View file

@ -154,15 +154,12 @@ typedef union {
};
} HID_GamepadReport_Data_t;
class Gamepad_{
class Gamepad_ : private HIDDevice{
public:
inline Gamepad_(void){
static HID_Descriptor cb = {
.length = sizeof(_gamepadReportDescriptor),
.descriptor = _gamepadReportDescriptor,
};
static HIDDescriptorListNode node(&cb);
HID.AppendDescriptor(&node);
inline Gamepad_(void) :
HIDDevice((uint8_t*)_gamepadReportDescriptor, sizeof(_gamepadReportDescriptor), HID_REPORTID_GAMEPAD)
{
// HID Descriptor is appended via the inherited HIDDevice class
}
inline void begin(void){
@ -172,10 +169,10 @@ public:
inline void end(void){
memset(&_report, 0, sizeof(_report));
HID.SendReport(HID_REPORTID_GAMEPAD, &_report, sizeof(_report));
SendReport(&_report, sizeof(_report));
}
inline void write(void){ HID.SendReport(HID_REPORTID_GAMEPAD, &_report, sizeof(_report)); }
inline void write(void){ SendReport(&_report, sizeof(_report)); }
inline void press(uint8_t b){ _report.buttons |= (uint32_t)1 << (b - 1); }
inline void release(uint8_t b){ _report.buttons &= ~((uint32_t)1 << (b - 1)); }
inline void releaseAll(void){ memset(&_report, 0x00, sizeof(_report)); }

View file

@ -109,10 +109,10 @@ THE SOFTWARE.
#include "HID-Tables.h"
// Include all HID libraries (.a linkage required to work) properly
//#include "AbsoluteMouse.h"
//#include "Consumer.h"
//#include "Gamepad.h"
//#include "System.h"
#include "AbsoluteMouse.h"
#include "Consumer.h"
#include "Gamepad.h"
#include "System.h"
// Include Teensy HID afterwards to overwrite key definitions if used
#ifdef USE_TEENSY_KEYBOARD

View file

@ -1 +1,2 @@
#include "PluggableHID/HID.h"
#include "PluggableHID/HIDDevice.h"

View file

@ -36,7 +36,6 @@ THE SOFTWARE.
// Keyboard
#include "HID-Project.h"
#include "PluggableHID/HIDDevice.h"
#include "ImprovedKeylayouts.h"
// Low level key report: up to 6 keys and shift, ctrl etc at once
@ -52,7 +51,7 @@ typedef union{
};
} HID_KeyboardReport_Data_t;
class Keyboard_ : public Print, public HIDDevice
class Keyboard_ : public Print, private HIDDevice
{
private:
HID_KeyboardReport_Data_t _keyReport;

View file

@ -12,9 +12,6 @@
HIDDevice::HIDDevice(uint8_t* data, uint16_t length, uint8_t ID) :
descriptorData(data), descriptorLength(length), reportID(ID)
{
// TODO call Append
// TODO init const data
// TODO template?
HID.AppendDescriptor(this);
}

View file

@ -40,6 +40,7 @@ public:
HIDDevice(uint8_t* data, uint16_t length, uint8_t ID);
// Needs to be public for static HID_ function access
// Inherit this device private and everything should be fine
//private:
HIDDevice* next = NULL;
@ -50,8 +51,9 @@ public:
virtual void setReportData(const void* data, int len);
// Public for custom, professional usage, like raw Keyboard
//protected:
protected:
// Could be used and inherited public for custom, professional usage, like raw Keyboard
// As an alternative you may still call the HID singleton.
void SendReport(const void* data, int len);
};

View file

@ -37,7 +37,7 @@ void System_::press(uint8_t s){
USBDevice.wakeupHost();
else
#endif
HID.SendReport(HID_REPORTID_SYSTEMCONTROL, &s, sizeof(s));
SendReport(&s, sizeof(s));
}
#endif

View file

@ -65,32 +65,35 @@ typedef union{
uint8_t key;
} HID_SystemControlReport_Data_t;
class System_{
class System_ : private HIDDevice{
public:
inline System_(void){
static HID_Descriptor cb = {
.length = sizeof(_systemReportDescriptor),
.descriptor = _systemReportDescriptor,
};
static HIDDescriptorListNode node(&cb);
HID.AppendDescriptor(&node);
inline System_(void) :
HIDDevice((uint8_t*)_systemReportDescriptor, sizeof(_systemReportDescriptor), HID_REPORTID_SYSTEMCONTROL)
{
// HID Descriptor is appended via the inherited HIDDevice class
}
inline void begin(void){
// release all buttons
end();
}
inline void end(void){
uint8_t _report = 0;
HID.SendReport(HID_REPORTID_SYSTEMCONTROL, &_report, sizeof(_report));
SendReport(&_report, sizeof(_report));
}
inline void write(uint8_t s){
press(s);
release();
}
void press(uint8_t s);
inline void release(void){
begin();
}
inline void releaseAll(void){
begin();
}

View file

@ -23,13 +23,10 @@
#include "TeensyKeyboard.h"
usb_keyboard_class::usb_keyboard_class(void){
static HID_Descriptor cb = {
.length = sizeof(keyboard_hid_report_desc),
.descriptor = keyboard_hid_report_desc,
};
static HIDDescriptorListNode node(&cb);
HID.AppendDescriptor(&node);
usb_keyboard_class::usb_keyboard_class(void) :
HIDDevice((uint8_t*)teensykeyboard_hid_report_desc, sizeof(teensykeyboard_hid_report_desc), HID_REPORTID_TEENSY_KEYBOARD)
{
// HID Descriptor is appended via the inherited HIDDevice class
}
// Step #1, decode UTF8 to Unicode code points
@ -256,7 +253,7 @@ void usb_keyboard_class::set_media(uint8_t c)
void usb_keyboard_class::send_now(void)
{
HID.SendReport(HID_REPORTID_TEENSY_KEYBOARD,keyboard_report_data,sizeof(keyboard_report_data));
SendReport(keyboard_report_data,sizeof(keyboard_report_data));
}

View file

@ -35,7 +35,7 @@
#include "TeensyKeylayouts.h"
// Keyboard Protocol 1, HID 1.11 spec, Appendix B, page 59-60
static const uint8_t PROGMEM keyboard_hid_report_desc[] = {
static const uint8_t PROGMEM teensykeyboard_hid_report_desc[] = {
0x05, 0x01, // Usage Page (Generic Desktop),
0x09, 0x06, // Usage (Keyboard),
0xA1, 0x01, // Collection (Application),
@ -82,7 +82,7 @@ static const uint8_t PROGMEM keyboard_hid_report_desc[] = {
0xc0 // End Collection
};
class usb_keyboard_class : public Print
class usb_keyboard_class : public Print, private HIDDevice
{
public:
usb_keyboard_class(void);