Skip to content
Permalink
Browse files
Modifications to support volume buttons and change keymapping to incl…
…ude these.
  • Loading branch information
Schwolop committed Feb 5, 2014
1 parent f38de3e commit 866344048efe78565dd6cd65e9b04716e93a1600
@@ -417,6 +417,34 @@ const uint8_t _asciimap[128] =

uint8_t USBPutChar(uint8_t c);

// press_direct() adds the specified keycode (without interpreting it)
// to the persistent key report and sends the report. Because of the way
// USB HID works, the host acts like the key remains pressed until we
// call release(), releaseAll(), or otherwise clear the report and resend.
size_t Keyboard_::press_direct(uint8_t k)
{
uint8_t i;
// Add k to the key report only if it's not already present
// and if there is an empty slot.
if (_keyReport.keys[0] != k && _keyReport.keys[1] != k &&
_keyReport.keys[2] != k && _keyReport.keys[3] != k &&
_keyReport.keys[4] != k && _keyReport.keys[5] != k) {

for (i=0; i<6; i++) {
if (_keyReport.keys[i] == 0x00) {
_keyReport.keys[i] = k;
break;
}
}
if (i == 6) {
setWriteError();
return 0;
}
}
sendReport(&_keyReport);
return 1;
}

// press() adds the specified key (printing, non-printing, or modifier)
// to the persistent key report and sends the report. Because of the way
// USB HID works, the host acts like the key remains pressed until we
@@ -462,6 +490,24 @@ size_t Keyboard_::press(uint8_t k)
return 1;
}

// release_direct() 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.
size_t Keyboard_::release_direct(uint8_t k)
{
uint8_t i;
// Test the key report to see if k is present. Clear it if it exists.
// Check all positions in case the key is present more than once (which it shouldn't be)
for (i=0; i<6; i++) {
if (0 != k && _keyReport.keys[i] == k) {
_keyReport.keys[i] = 0x00;
}
}

sendReport(&_keyReport);
return 1;
}

// 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.
@@ -39,6 +39,7 @@ class Serial_ : public Stream
virtual int read(void);
virtual void flush(void);
virtual size_t write(uint8_t);
using Print::write; // pull in write(str) and write(buf, size) from Print
operator bool();
};
extern Serial_ Serial;
@@ -109,6 +110,9 @@ extern Mouse_ Mouse;
#define KEY_F10 0xCB
#define KEY_F11 0xCC
#define KEY_F12 0xCD
#define VOLUME_MUTE 0x7F
#define VOLUME_UP 0x80
#define VOLUME_DOWN 0x81

// Low level key report: up to 6 keys and shift, ctrl etc at once
typedef struct
@@ -122,14 +126,16 @@ class Keyboard_ : public Print
{
private:
KeyReport _keyReport;
public:
void sendReport(KeyReport* keys);
public:
Keyboard_(void);
void begin(void);
void end(void);
virtual size_t write(uint8_t k);
virtual size_t press(uint8_t k);
virtual size_t press_direct(uint8_t k);
virtual size_t release(uint8_t k);
virtual size_t release_direct(uint8_t k);
virtual void releaseAll(void);
};
extern Keyboard_ Keyboard;
@@ -312,7 +312,13 @@ void updateInputStates() {
inputChanged = true;
inputs[i].pressed = false;
if (inputs[i].isKey) {
Keyboard.release(inputs[i].keyCode);
if( inputs[i].keyCode == VOLUME_UP || inputs[i].keyCode == VOLUME_DOWN || inputs[i].keyCode == VOLUME_MUTE ) {
// Special case for volume keys.
Keyboard.release_direct(inputs[i].keyCode);
}
else {
Keyboard.release(inputs[i].keyCode);
}
}
if (inputs[i].isMouseMotion) {
mouseHoldCount[i] = 0; // input becomes released, reset mouse hold
@@ -327,7 +333,13 @@ void updateInputStates() {
inputChanged = true;
inputs[i].pressed = true;
if (inputs[i].isKey) {
Keyboard.press(inputs[i].keyCode);
if( inputs[i].keyCode == VOLUME_UP || inputs[i].keyCode == VOLUME_DOWN || inputs[i].keyCode == VOLUME_MUTE ) {
// Special case for volume keys:
Keyboard.press_direct(inputs[i].keyCode);
}
else {
Keyboard.press(inputs[i].keyCode);
}
}
}
}
@@ -35,12 +35,12 @@ int keyCodes[NUM_INPUTS] = {

// female header on the back right side

MOUSE_MOVE_UP, // pin A5
MOUSE_MOVE_DOWN, // pin A4
MOUSE_MOVE_LEFT, // pin A3
MOUSE_MOVE_RIGHT, // pin A2
VOLUME_UP, // pin A5
VOLUME_DOWN, // pin A4
'+', // pin A3
'-', // pin A2
MOUSE_LEFT, // pin A1
MOUSE_RIGHT // pin A0
VOLUME_MUTE // pin A0
};

///////////////////////////

0 comments on commit 8663440

Please sign in to comment.