Added Consumer API

This commit is contained in:
NicoHood 2015-10-11 10:22:32 +02:00
parent 9250ff9835
commit 6ac9398a18
7 changed files with 268 additions and 3 deletions

View file

@ -53,7 +53,7 @@ typedef union{
class AbsoluteMouseAPI
{
private:
protected:
int16_t xAxis;
int16_t yAxis;
uint8_t _buttons;

View file

@ -0,0 +1,94 @@
/*
Copyright (c) 2014-2015 NicoHood
See the readme for credit to other people.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
// Include guard
#pragma once
#include <Arduino.h>
#include "HID-Settings.h"
// 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_PREV MEDIA_PREVIOUS
#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 MEDIA_VOL_MUTE MEDIA_VOLUME_MUTE
#define MEDIA_VOL_UP MEDIA_VOLUME_UP
#define MEDIA_VOL_DOWN MEDIA_VOLUME_DOWN
#define CONSUMER_SCREENSAVER 0x19e
#define CONSUMER_PROGRAMMABLE_BUTTON_CONFIGURATION 0x182
#define CONSUMER_CONTROL_CONFIGURATION 0x183
#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[];
uint16_t whole16[];
uint32_t whole32[];
struct {
uint16_t key1;
uint16_t key2;
uint16_t key3;
uint16_t key4;
};
} HID_ConsumerControlReport_Data_t;
class ConsumerAPI
{
public:
inline ConsumerAPI(void);
inline void begin(void);
inline void end(void);
inline void write(uint16_t m);
inline void press(uint16_t m);
inline void release(uint16_t m);
inline void releaseAll(void);
// Sending is public in the base class for advanced users.
virtual void SendReport(void* data, int length) = 0;
protected:
HID_ConsumerControlReport_Data_t _report;
};
// Implementation is inline
#include "ConsumerAPI.hpp"

View file

@ -0,0 +1,71 @@
/*
Copyright (c) 2014-2015 NicoHood
See the readme for credit to other people.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
// Include guard
#pragma once
ConsumerAPI::ConsumerAPI(void)
{
// Empty
}
void ConsumerAPI::begin(void) {
// release all buttons
end();
}
void ConsumerAPI::end(void) {
memset(&_report, 0, sizeof(_report));
SendReport(&_report, sizeof(_report));
}
void ConsumerAPI::write(uint16_t m) {
press(m);
release(m);
}
void ConsumerAPI::press(uint16_t m) {
// search for a free spot
for (uint8_t i = 0; i < sizeof(HID_ConsumerControlReport_Data_t) / 2; i++) {
if (_report.whole16[i] == 0x00) {
_report.whole16[i] = m;
break;
}
}
SendReport(&_report, sizeof(_report));
}
void ConsumerAPI::release(uint16_t m) {
// search and release the keypress
for (uint8_t i = 0; i < sizeof(HID_ConsumerControlReport_Data_t) / 2; i++) {
if (_report.whole16[i] == m) {
_report.whole16[i] = 0x00;
// no break to delete multiple keys
}
}
SendReport(&_report, sizeof(_report));
}
void ConsumerAPI::releaseAll(void) {
end();
}

View file

@ -78,7 +78,7 @@ public:
// Sending is public in the base class for advanced users.
virtual void SendReport(void* data, int length) = 0;
private:
protected:
uint8_t _buttons;
void buttons(uint8_t b);
};

View file

@ -41,7 +41,7 @@ THE SOFTWARE.
#include "MultiReport/AbsoluteMouse.h"
#include "SingleReport/BootMouse.h"
#include "MultiReport/ImprovedMouse.h"
//#include "Consumer.h"
#include "MultiReport/Consumer.h"
//#include "Gamepad.h"
#include "MultiReport/System.h"
//#include "RawHID.h"

View file

@ -0,0 +1,57 @@
/*
Copyright (c) 2014-2015 NicoHood
See the readme for credit to other people.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include "Consumer.h"
static const uint8_t _hidMultiReportDescriptorConsumer[] PROGMEM = {
/* Consumer Control (Sound/Media keys) */
0x05, 0x0C, /* usage page (consumer device) */
0x09, 0x01, /* usage -- consumer control */
0xA1, 0x01, /* collection (application) */
0x85, HID_REPORTID_CONSUMERCONTROL, /* report id */
/* 4 Media Keys */
0x15, 0x00, /* logical minimum */
0x26, 0xFF, 0x03, /* logical maximum (3ff) */
0x19, 0x00, /* usage minimum (0) */
0x2A, 0xFF, 0x03, /* usage maximum (3ff) */
0x95, 0x04, /* report count (4) */
0x75, 0x10, /* report size (16) */
0x81, 0x00, /* input */
0xC0 /* end collection */
};
Consumer_::Consumer_(void)
{
static HIDDescriptorListNode node(_hidMultiReportDescriptorConsumer, sizeof(_hidMultiReportDescriptorConsumer));
HID().AppendDescriptor(&node);
}
void Consumer_::SendReport(void* data, int length)
{
HID().SendReport(HID_REPORTID_CONSUMERCONTROL, data, length);
}
Consumer_ Consumer;

View file

@ -0,0 +1,43 @@
/*
Copyright (c) 2014-2015 NicoHood
See the readme for credit to other people.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
// Include guard
#pragma once
#include <Arduino.h>
#include "PluggableUSB.h"
#include "HID.h"
#include "HID-Settings.h"
#include "../HID-APIs/ConsumerAPI.h"
class Consumer_ : public ConsumerAPI
{
public:
Consumer_(void);
protected:
virtual inline void SendReport(void* data, int length) override;
};
extern Consumer_ Consumer;