non-working first pass at systemcontrol and consumercontrol

pull/18/head
Jesse Vincent 11 years ago
parent 99a19b4c66
commit 7ade8381dc

@ -223,6 +223,16 @@ void send_key_events(byte layer)
}
}
} else if (mappedKey.flags & SYNTHETIC_KEY) {
if(mappedKey.flags & IS_CONSUMER) {
if (key_toggled_on (switchState)) {
Keyboard.consumerControl(mappedKey.rawKey);
}
}
if(mappedKey.flags & IS_SYSCTL) {
if (key_toggled_on (switchState)) {
Keyboard.systemControl(mappedKey.rawKey);
}
}
if(mappedKey.flags & IS_MACRO) {
if (key_toggled_on (switchState)) {
if (mappedKey.rawKey == 1) {

@ -51,6 +51,7 @@ Keyboard_ Keyboard;
#define HID_REPORTID_SYSTEMCONTROL (4)
#define HID_REPORTID_MOUSE_ABS (5)
#define HID_REPORTID_CONSUMERCONTROL (6)
extern const u8 _hidReportDescriptor[] PROGMEM;
const u8 _hidReportDescriptor[] = {
@ -377,90 +378,7 @@ bool Mouse_::isPressed(uint8_t b)
}
//================================================================================
//================================================================================
// ConsumerControl
ConsumerControl_::ConsumerControl_(void)
{
}
void ConsumerControl_::begin(void)
{
}
void ConsumerControl_::end(void)
{
}
void ConsumerControl_::sendReport(u8 cmd, u8 val)
{
u8 data[2] = {cmd, val};
HID_SendReport(2,data,2);
}
void ConsumerControl_::mute (void){
sendReport(0x01, 0);
}
void ConsumerControl_::volumeUp (void)
{
sendReport(0x02, 0);
}
void ConsumerControl_::volumeDown (void)
{
sendReport(0x03, 0);
}
void ConsumerControl_::playPause (void)
{
sendReport(0x04, 0);
}
void ConsumerControl_::stop (void)
{
sendReport(0x05, 0);
}
void ConsumerControl_::previousTrack (void)
{
sendReport(0x06, 0);
}
void ConsumerControl_::nextTrack (void)
{
sendReport(0x07, 0);
}
void ConsumerControl_::mail (void)
{
sendReport(0x08, 0);
}
void ConsumerControl_::calculator (void)
{
sendReport(0x09, 0);
}
void ConsumerControl_::wwwSearch (void)
{
sendReport(0x0a, 0);
}
void ConsumerControl_::wwwHome (void)
{
sendReport(0x0b, 0);
}
void ConsumerControl_::wwwFavorites (void)
{
sendReport(0x0c, 0);
}
void ConsumerControl_::wwwRefresh (void)
{
sendReport(0x0d, 0);
}
void ConsumerControl_::wwwStop (void)
{
sendReport(0x0e, 0);
}
void ConsumerControl_::wwwForward (void)
{
sendReport(0x0f, 0);
}
void ConsumerControl_::wwwBack (void)
{
sendReport(0x10, 0);
}
//================================================================================
//================================================================================
@ -699,6 +617,39 @@ size_t Keyboard_::systemControl(uint8_t k)
}
}
// Consumer Control
// k is one of the CONSUMER_CONTROL defines which come from the HID usage table "Consumer Devices Page (0x0c)"
// in "HID Usage Tables" (HUT1_12v2.pdf)
size_t Keyboard_::consumerControl(uint8_t k)
{
if(k <= 16)
{
u16 mask = 0;
u8 m[2];
if(k > 0)
{
mask = 1 << (k - 1);
}
m[0] = LSB(mask);
m[1] = MSB(mask);
HID_SendReport(HID_REPORTID_CONSUMERCONTROL,m,sizeof(m));
// these are all OSCs, so send a clear to make it possible to send it again later
m[0] = 0;
m[1] = 0;
HID_SendReport(HID_REPORTID_CONSUMERCONTROL,m,sizeof(m));
return 1;
}
else
{
setWriteError();
return 0;
}
}
// release() takes the specified key out of the persistent key report and
// sends the report. This tells the OS the key is no longer pressed and that
// it shouldn't be repeated any more.

@ -141,6 +141,31 @@ extern Mouse_ Mouse;
#define SYSTEM_CONTROL_DISPLAY_TOGGLE_INT_EXT 15
#define SYSTEM_CONTROL_DISPLAY_SWAP 16
// Consumer Control values for Keyboard_::systemControl()
// these defines come from the HID usage table "Consumer Device Page (0x0c)"
// in the USB standard document "HID Usage Tables" (HUT1_12v2.pdf)
// Currently this list contains only OSC (one shot control) values,
// the implementation of systemControl will have to be changed when
// adding OOC or RTC values.
#define CONSUMER_CONTROL_VOLUME_MUTE 1
#define CONSUMER_CONTROL_VOLUME_UP 2
#define CONSUMER_CONTROL_VOLUME_DOWN 3
#define CONSUMER_CONTROL_PLAY_PAUSE 4
#define CONSUMER_CONTROL_STOP 5
#define CONSUMER_CONTROL_PREV_TRACK 6
#define CONSUMER_CONTROL_NEXT_TRACK 7
#define CONSUMER_CONTROL_MAIL 8
#define CONSUMER_CONTROL_CALCULATOR 9
#define CONSUMER_CONTROL_WWW_SEARCH 10
#define CONSUMER_CONTROL_WWW_HOME 11
#define CONSUMER_CONTROL_WWW_FAVORITES 12
#define CONSUMER_CONTROL_WWW_REFRESH 13
#define CONSUMER_CONTROL_WWW_STOP 14
#define CONSUMER_CONTROL_WWW_FORWARD 15
#define CONSUMER_CONTROL_WWW_BACK 16
// Low level key report: up to 6 keys and shift, ctrl etc at once
typedef struct
{
@ -163,42 +188,10 @@ public:
virtual size_t release(uint8_t k);
virtual void releaseAll(void);
virtual size_t systemControl(uint8_t k);
virtual size_t consumerControl(uint8_t k);
};
extern Keyboard_ Keyboard;
//================================================================================
//================================================================================
class ConsumerControl_
{
private:
void sendReport(uint8_t cmd, uint8_t val);
public:
ConsumerControl_(void);
void begin(void);
void end(void);
void mute (void);
void volumeUp (void);
void volumeDown (void);
void playPause (void);
void stop (void);
void previousTrack (void);
void nextTrack (void);
void mail (void);
void calculator (void);
void wwwSearch (void);
void wwwHome (void);
void wwwFavorites (void);
void wwwRefresh (void);
void wwwStop (void);
void wwwForward (void);
void wwwBack (void);
};
extern ConsumerControl_ ConsumerControl;
//================================================================================
//================================================================================
// Low level API

@ -10,6 +10,9 @@
// we assert that synthetic keys can never have keys held, so we reuse the _HELD bits
#define IS_MACRO B00000001
#define IS_SYSCTL B00000010
#define IS_CONSUMER B00000100
#define MOUSE_UP B0001
#define MOUSE_DN B0010
@ -59,6 +62,10 @@
#define Key_sleep (Key) {KEY_FLAGS | SYNTHETIC_KEY|IS_SYSCTL, SYSTEM_CONTROL_SLEEP }
#define Key_volumeUp (Key) {KEY_FLAGS | SYNTHETIC_KEY|IS_CONSUMER, CONSUMER_CONTROL_VOLUME_UP}
#define Key_LCtrl (Key){ KEY_FLAGS, KEY_LEFT_CTRL }
#define KEY_LEFT_CTRL 0x80
#define Key_LCtrl (Key){ KEY_FLAGS, KEY_LEFT_CTRL }

@ -42,7 +42,7 @@
},
#define KEYMAP_QWERTY_FN2 { /* Generated keymap for QWERTY_FN2 */ {Key_skip, Key_F1, Key_F2, Key_F3, Key_F4, Key_F5, Key_skip, Key_skip, Key_F6, Key_F7, Key_F8, Key_F9, Key_F10, Key_skip},\
{Key_Tab, Key_macroKey1, Key_mouseBtnL, Key_mouseBtnM, Key_mouseBtnR, Key_T, Key_NoKey, Key_NoKey, Key_LCurlyBracket, Key_RCurlyBracket, Key_LSquareBracket, Key_RSquareBracket, Key_P, Key_Equals},\
{Key_PageUp, Key_mouseL, Key_mouseUp, Key_mouseDn, Key_mouseR, Key_G, Key_Tab, Key_Return, Key_LArrow, Key_DnArrow, Key_UpArrow, Key_RArrow, Key_Semicolon, Key_Quote},\
{Key_PageUp, Key_mouseL, Key_mouseUp, Key_mouseDn, Key_mouseR, Key_G, Key_Tab, Key_Return, Key_LArrow, Key_DnArrow, Key_UpArrow, Key_RArrow, Key_sleep, Key_volumeUp},\
{Key_PageDn, Key_Keymap2, Key_mouseBtnL, Key_mouseBtnM, Key_mouseBtnR, Key_B, Key_Esc, Key_Enter, Key_Pipe, Key_M, Key_Comma, Key_Period, Key_Backslash, Key_Minus},\
{Key_LGUI, Key_Backspace, Key_LShift, Key_LCtrl, Key_NoKey, Key_skip, Key_skip, Key_skip, Key_skip, Key_NoKey, Key_RCtrl, Key_RShift, Key_Space, Key_RAlt},\
},

@ -1,6 +1,6 @@
#NAME: QWERTY_FN2
skip F1 F2 F3 F4 F5 skip skip F6 F7 F8 F9 F10 skip
Tab macroKey1 mouseBtnL mouseBtnM mouseBtnR T NoKey NoKey { } [ ] P =
PageUp mouseL mouseUp mouseDn mouseR G Tab Return LArrow DnArrow UpArrow RArrow ; '
PageUp mouseL mouseUp mouseDn mouseR G Tab Return LArrow DnArrow UpArrow RArrow sleep volumeUp
PageDn Keymap2 mouseBtnL mouseBtnM mouseBtnR B Esc Enter | M , . \ -
LGUI Backspace LShift LCtrl NoKey skip skip skip skip NoKey RCtrl RShift Space RAlt

Loading…
Cancel
Save