Added Consumer + System HID APIs
This commit is contained in:
parent
3a0c30f393
commit
48c6b6dd81
7 changed files with 244 additions and 2 deletions
27
Consumer.cpp
Normal file
27
Consumer.cpp
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
Consumer.cpp
|
||||
Copyright (c) 2005-2014 Arduino. All right reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "Consumer.h"
|
||||
|
||||
//================================================================================
|
||||
// Consumer
|
||||
//================================================================================
|
||||
|
||||
// object instance
|
||||
Consumer_ Consumer;
|
||||
113
Consumer.h
Normal file
113
Consumer.h
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
Consumer.h
|
||||
Copyright (c) 2005-2014 Arduino. All right reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef __CONSUMERAPI__
|
||||
#define __CONSUMERAPI__
|
||||
|
||||
// to access the HID_SendReport via USBAPI.h and report number
|
||||
#include "Arduino.h"
|
||||
|
||||
//TODO workaround to access the weak sending function
|
||||
void HID_SendReport(uint8_t id, const void* data, int len);
|
||||
|
||||
//================================================================================
|
||||
// Consumer
|
||||
//================================================================================
|
||||
|
||||
// Media key definitions, see official USB docs for more
|
||||
#define MEDIA_FAST_FORWARD 0xB3
|
||||
#define MEDIA_REWIND 0xB4
|
||||
#define MEDIA_NEXT 0xB5
|
||||
#define MEDIA_PREVIOUS 0xB6
|
||||
#define MEDIA_STOP 0xB7
|
||||
#define MEDIA_PLAY_PAUSE 0xCD
|
||||
|
||||
#define MEDIA_VOLUME_MUTE 0xE2
|
||||
#define MEDIA_VOLUME_UP 0xE9
|
||||
#define MEDIA_VOLUME_DOWN 0xEA
|
||||
|
||||
#define CONSUMER_EMAIL_READER 0x18A
|
||||
#define CONSUMER_CALCULATOR 0x192
|
||||
#define CONSUMER_EXPLORER 0x194
|
||||
|
||||
#define CONSUMER_BROWSER_HOME 0x223
|
||||
#define CONSUMER_BROWSER_BACK 0x224
|
||||
#define CONSUMER_BROWSER_FORWARD 0x225
|
||||
#define CONSUMER_BROWSER_REFRESH 0x227
|
||||
#define CONSUMER_BROWSER_BOOKMARKS 0x22A
|
||||
|
||||
typedef union{
|
||||
// every usable Consumer key possible, up to 4 keys presses possible
|
||||
uint8_t whole8[8];
|
||||
uint16_t whole16[8 / 2];
|
||||
uint32_t whole32[8 / 4];
|
||||
struct{
|
||||
uint16_t key1;
|
||||
uint16_t key2;
|
||||
uint16_t key3;
|
||||
uint16_t key4;
|
||||
};
|
||||
} HID_ConsumerReport_Data_t;
|
||||
|
||||
class Consumer_{
|
||||
public:
|
||||
inline Consumer_(void){
|
||||
// empty
|
||||
}
|
||||
inline void begin(void){
|
||||
// release all buttons
|
||||
end();
|
||||
}
|
||||
inline void end(void){
|
||||
memset(&_report, 0, sizeof(_report));
|
||||
HID_SendReport(HID_REPORTID_CONSUMERCONTROL, &_report, sizeof(_report));
|
||||
}
|
||||
inline void write(uint16_t m){
|
||||
press(m);
|
||||
release(m);
|
||||
}
|
||||
inline void press(uint16_t m){
|
||||
// search for a free spot
|
||||
for (int i = 0; i < sizeof(HID_ConsumerReport_Data_t) / 2; i++) {
|
||||
if (_report.whole16[i] == 0x00) {
|
||||
_report.whole16[i] = m;
|
||||
break;
|
||||
}
|
||||
}
|
||||
HID_SendReport(HID_REPORTID_CONSUMERCONTROL, &_report, sizeof(_report));
|
||||
}
|
||||
inline void release(uint16_t m){
|
||||
// search and release the keypress
|
||||
for (int i = 0; i < sizeof(HID_ConsumerReport_Data_t) / 2; i++) {
|
||||
if (_report.whole16[i] == m) {
|
||||
_report.whole16[i] = 0x00;
|
||||
// no break to delete multiple keys
|
||||
}
|
||||
}
|
||||
HID_SendReport(HID_REPORTID_CONSUMERCONTROL, &_report, sizeof(_report));
|
||||
}
|
||||
inline void releaseAll(void){
|
||||
begin();
|
||||
}
|
||||
private:
|
||||
HID_ConsumerReport_Data_t _report;
|
||||
};
|
||||
extern Consumer_ Consumer;
|
||||
|
||||
#endif
|
||||
2
HID.h
2
HID.h
|
|
@ -262,6 +262,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
|
||||
#include "USBDesc.h"
|
||||
#include "USBCore.h"
|
||||
// only include HIDAPI if we have an USB AVR MCU.
|
||||
// The use can overwrite HID_SendReport() and manually include the APIs.
|
||||
#include "HIDAPI.h"
|
||||
|
||||
//================================================================================
|
||||
|
|
|
|||
3
HIDAPI.h
3
HIDAPI.h
|
|
@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
// include all HID APIs
|
||||
#include "Keyboard.h"
|
||||
#include "Mouse.h"
|
||||
//TODO
|
||||
#include "Consumer.h"
|
||||
#include "System.h"
|
||||
|
||||
#endif
|
||||
|
|
@ -7,7 +7,6 @@ Under Construction. This is a todo list for myself and a feature list so far.
|
|||
Keyboard Layout english only?
|
||||
more usb definitions instead of fixed values, noone understands
|
||||
someone has to add the keywords.txt definitions as well
|
||||
keyboard music vol (change descriptor)
|
||||
keyboard led move to usb function not to keyboard and from keyboard call this function?
|
||||
weak hidsendreport implement somewhere the prototype?
|
||||
move HID-Core to a seperate folder?
|
||||
|
|
@ -16,6 +15,8 @@ keycode/raw for keyboard
|
|||
magic key fix?
|
||||
add examples
|
||||
void Recv(volatile u8* data, u8 count) static inline??
|
||||
improve workaround for consumer + system weak hid send function prototype
|
||||
add gamepad
|
||||
|
||||
Bugs
|
||||
Mouse Abs only works with system report under special circumstances.
|
||||
|
|
|
|||
26
System.cpp
Normal file
26
System.cpp
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
System.cpp
|
||||
Copyright (c) 2005-2014 Arduino. All right reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "System.h"
|
||||
|
||||
//================================================================================
|
||||
// System
|
||||
//================================================================================
|
||||
|
||||
System_ System;
|
||||
72
System.h
Normal file
72
System.h
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
System.h
|
||||
Copyright (c) 2005-2014 Arduino. All right reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef __SYSTEMAPI__
|
||||
#define __SYSTEMAPI__
|
||||
|
||||
// to access the HID_SendReport via USBAPI.h and report number
|
||||
#include "Arduino.h"
|
||||
|
||||
//TODO workaround to access the weak sending function
|
||||
void HID_SendReport(uint8_t id, const void* data, int len);
|
||||
|
||||
//================================================================================
|
||||
// System
|
||||
//================================================================================
|
||||
|
||||
#define SYSTEM_POWER_DOWN 0x81
|
||||
#define SYSTEM_SLEEP 0x82
|
||||
#define SYSTEM_WAKE_UP 0x83
|
||||
|
||||
typedef union{
|
||||
// every usable system control key possible
|
||||
uint8_t whole8[1];
|
||||
uint8_t key;
|
||||
} HID_SystemReport_Data_t;
|
||||
|
||||
class System_{
|
||||
public:
|
||||
inline System_(void){
|
||||
// empty
|
||||
}
|
||||
inline void begin(void){
|
||||
// release all buttons
|
||||
end();
|
||||
}
|
||||
inline void end(void){
|
||||
uint8_t _report = 0;
|
||||
HID_SendReport(HID_REPORTID_SYSTEMCONTROL, &_report, sizeof(_report));
|
||||
}
|
||||
inline void write(uint8_t s){
|
||||
press(s);
|
||||
release();
|
||||
}
|
||||
inline void press(uint8_t s){
|
||||
HID_SendReport(HID_REPORTID_SYSTEMCONTROL, &s, sizeof(s));
|
||||
}
|
||||
inline void release(void){
|
||||
begin();
|
||||
}
|
||||
inline void releaseAll(void){
|
||||
begin();
|
||||
}
|
||||
};
|
||||
extern System_ System;
|
||||
|
||||
#endif
|
||||
Loading…
Reference in a new issue