Add Surface Dial support
This commit is contained in:
parent
af9fff10e9
commit
2169d34f2c
6 changed files with 291 additions and 0 deletions
66
src/HID-APIs/SurfaceDialAPI.h
Normal file
66
src/HID-APIs/SurfaceDialAPI.h
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
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"
|
||||
|
||||
typedef union{
|
||||
// SurfaceDial report: 1 button, 15-bit rotation, position
|
||||
uint8_t whole8[0];
|
||||
uint16_t whole16[0];
|
||||
uint32_t whole32[0];
|
||||
struct{
|
||||
uint16_t button: 1;
|
||||
uint16_t rotation: 15;
|
||||
//int8_t xAxis;
|
||||
//int8_t yAxis;
|
||||
|
||||
};
|
||||
} HID_SurfaceDialReport_Data_t;
|
||||
|
||||
class SurfaceDialAPI
|
||||
{
|
||||
public:
|
||||
inline SurfaceDialAPI(void);
|
||||
inline void begin(void);
|
||||
inline void end(void);
|
||||
inline void click(void);
|
||||
inline void rotate(int16_t rotation);
|
||||
inline void press(void);
|
||||
inline void release(void);
|
||||
inline void releaseAll(void);
|
||||
inline bool isPressed();
|
||||
|
||||
// Sending is public in the base class for advanced users.
|
||||
virtual void SendReport(void* data, int length) = 0;
|
||||
|
||||
protected:
|
||||
bool _button;
|
||||
inline void button(bool b);
|
||||
};
|
||||
|
||||
// Implementation is inline
|
||||
#include "SurfaceDialAPI.hpp"
|
||||
90
src/HID-APIs/SurfaceDialAPI.hpp
Normal file
90
src/HID-APIs/SurfaceDialAPI.hpp
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
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
|
||||
|
||||
SurfaceDialAPI::SurfaceDialAPI(void) : _button(false)
|
||||
{
|
||||
// Empty
|
||||
}
|
||||
|
||||
void SurfaceDialAPI::begin(void)
|
||||
{
|
||||
end();
|
||||
}
|
||||
|
||||
void SurfaceDialAPI::end(void)
|
||||
{
|
||||
_button = false;
|
||||
rotate(0);
|
||||
}
|
||||
|
||||
void SurfaceDialAPI::click(void)
|
||||
{
|
||||
_button = true;
|
||||
rotate(0);
|
||||
_button = false;
|
||||
rotate(0);
|
||||
}
|
||||
|
||||
void SurfaceDialAPI::rotate(int16_t rotation)
|
||||
{
|
||||
HID_SurfaceDialReport_Data_t report;
|
||||
report.button = _button;
|
||||
report.rotation = rotation;
|
||||
//report.xAxis = x;
|
||||
//report.yAxis = y;
|
||||
|
||||
SendReport(&report, sizeof(report));
|
||||
}
|
||||
|
||||
void SurfaceDialAPI::button(bool b)
|
||||
{
|
||||
if (b != _button)
|
||||
{
|
||||
_button = b;
|
||||
rotate(0);
|
||||
}
|
||||
}
|
||||
|
||||
void SurfaceDialAPI::press(void)
|
||||
{
|
||||
button(true);
|
||||
}
|
||||
|
||||
void SurfaceDialAPI::release(void)
|
||||
{
|
||||
button(false);
|
||||
}
|
||||
|
||||
void SurfaceDialAPI::releaseAll(void)
|
||||
{
|
||||
_button = false;
|
||||
rotate(0);
|
||||
}
|
||||
|
||||
bool SurfaceDialAPI::isPressed()
|
||||
{
|
||||
return _button;
|
||||
}
|
||||
|
|
@ -51,6 +51,7 @@ THE SOFTWARE.
|
|||
#include "MultiReport/ImprovedKeyboard.h"
|
||||
#include "SingleReport/SingleNKROKeyboard.h"
|
||||
#include "MultiReport/NKROKeyboard.h"
|
||||
#include "MultiReport/SurfaceDial.h"
|
||||
|
||||
// Include Teensy HID afterwards to overwrite key definitions if used
|
||||
// TODO include Teensy API if non english keyboard layout was used
|
||||
|
|
|
|||
|
|
@ -108,3 +108,7 @@ THE SOFTWARE.
|
|||
#ifndef HID_REPORTID_TEENSY_KEYBOARD
|
||||
#define HID_REPORTID_TEENSY_KEYBOARD 9
|
||||
#endif
|
||||
|
||||
#ifndef HID_REPORTID_SURFACEDIAL
|
||||
#define HID_REPORTID_SURFACEDIAL 10
|
||||
#endif
|
||||
87
src/MultiReport/SurfaceDial.cpp
Normal file
87
src/MultiReport/SurfaceDial.cpp
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
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 "SurfaceDial.h"
|
||||
|
||||
static const uint8_t _hidMultiReportDescriptorSurfaceDial[] PROGMEM = {
|
||||
// Integrated Radial Controller TLC
|
||||
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
||||
0x09, 0x0e, // USAGE (System Multi-Axis Controller)
|
||||
0xa1, 0x01, // COLLECTION (Application)
|
||||
0x85, HID_REPORTID_SURFACEDIAL, // REPORT_ID (Radial Controller)
|
||||
0x05, 0x0d, // USAGE_PAGE (Digitizers)
|
||||
0x09, 0x21, // USAGE (Puck)
|
||||
0xa1, 0x00, // COLLECTION (Physical)
|
||||
0x05, 0x09, // USAGE_PAGE (Buttons)
|
||||
0x09, 0x01, // USAGE (Button 1)
|
||||
0x95, 0x01, // REPORT_COUNT (1)
|
||||
0x75, 0x01, // REPORT_SIZE (1)
|
||||
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
||||
0x25, 0x01, // LOGICAL_MAXIMUM (1)
|
||||
0x81, 0x02, // INPUT (Data,Var,Abs)
|
||||
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
||||
0x09, 0x37, // USAGE (Dial)
|
||||
0x95, 0x01, // REPORT_COUNT (1)
|
||||
0x75, 0x0f, // REPORT_SIZE (15)
|
||||
0x55, 0x0f, // UNIT_EXPONENT (-1)
|
||||
0x65, 0x14, // UNIT (Degrees, English Rotation)
|
||||
0x36, 0xf0, 0xf1, // PHYSICAL_MINIMUM (-3600)
|
||||
0x46, 0x10, 0x0e, // PHYSICAL_MAXIMUM (3600)
|
||||
0x16, 0xf0, 0xf1, // LOGICAL_MINIMUM (-3600)
|
||||
0x26, 0x10, 0x0e, // LOGICAL_MAXIMUM (3600)
|
||||
0x81, 0x06, // INPUT (Data,Var,Rel)
|
||||
// 0x09, 0x30, // USAGE (X)
|
||||
// 0x75, 0x10, // REPORT_SIZE (16)
|
||||
// 0x55, 0x0d, // UNIT_EXPONENT (-3)
|
||||
// 0x65, 0x13, // UNIT (Inch,EngLinear)
|
||||
// 0x35, 0x00, // PHYSICAL_MINIMUM (0)
|
||||
// 0x46, 0xc0, 0x5d, // PHYSICAL_MAXIMUM (24000)
|
||||
// 0x15, 0x00, // LOGICAL_MINIMUM (0)
|
||||
// 0x26, 0xff, 0x7f, // LOGICAL_MAXIMUM (32767)
|
||||
// 0x81, 0x02, // INPUT (Data,Var,Abs)
|
||||
// 0x09, 0x31, // USAGE (Y)
|
||||
// 0x46, 0xb0, 0x36, // PHYSICAL_MAXIMUM (14000)
|
||||
// 0x81, 0x02, // INPUT (Data,Var,Abs)
|
||||
// 0x05, 0x0d, // USAGE_PAGE (Digitizers)
|
||||
// 0x09, 0x48, // USAGE (Width)
|
||||
// 0x36, 0xb8, 0x0b, // PHYSICAL_MINIMUM (3000)
|
||||
// 0x46, 0xb8, 0x0b, // PHYSICAL_MAXIMUM (3000)
|
||||
// 0x16, 0xb8, 0x0b, // LOGICAL_MINIMUM (3000)
|
||||
// 0x26, 0xb8, 0x0b, // LOGICAL_MAXIMUM (3000)
|
||||
// 0x81, 0x03 // INPUT (Cnst,Var,Abs)
|
||||
0xc0, // END_COLLECTION
|
||||
0xc0 // END_COLLECTION
|
||||
};
|
||||
|
||||
SurfaceDial_::SurfaceDial_(void)
|
||||
{
|
||||
static HIDSubDescriptor node(_hidMultiReportDescriptorSurfaceDial, sizeof(_hidMultiReportDescriptorSurfaceDial));
|
||||
HID().AppendDescriptor(&node);
|
||||
}
|
||||
|
||||
void SurfaceDial_::SendReport(void *data, int length)
|
||||
{
|
||||
HID().SendReport(HID_REPORTID_SURFACEDIAL, data, length);
|
||||
}
|
||||
|
||||
SurfaceDial_ SurfaceDial;
|
||||
43
src/MultiReport/SurfaceDial.h
Normal file
43
src/MultiReport/SurfaceDial.h
Normal 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/SurfaceDialAPI.h"
|
||||
|
||||
|
||||
class SurfaceDial_ : public SurfaceDialAPI
|
||||
{
|
||||
public:
|
||||
SurfaceDial_(void);
|
||||
|
||||
protected:
|
||||
virtual inline void SendReport(void* data, int length) override;
|
||||
};
|
||||
extern SurfaceDial_ SurfaceDial;
|
||||
|
||||
Loading…
Reference in a new issue