diff --git a/src/HID-Project.h b/src/HID-Project.h index ffce021..b3a5562 100644 --- a/src/HID-Project.h +++ b/src/HID-Project.h @@ -113,6 +113,7 @@ THE SOFTWARE. // Include all HID libraries (.a linkage required to work) properly #include "AbsoluteMouse.h" +#include "ImprovedMouse.h" #include "Consumer.h" #include "Gamepad.h" #include "System.h" diff --git a/src/ImprovedMouse.cpp b/src/ImprovedMouse.cpp index 234ca60..483feb1 100644 --- a/src/ImprovedMouse.cpp +++ b/src/ImprovedMouse.cpp @@ -19,63 +19,61 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "Mouse.h" +#include "ImprovedMouse.h" #if defined(_USING_HID) static const uint8_t _hidReportDescriptor[] PROGMEM = { - - // Mouse - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 54 - 0x09, 0x02, // USAGE (Mouse) - 0xa1, 0x01, // COLLECTION (Application) - 0x09, 0x01, // USAGE (Pointer) - 0xa1, 0x00, // COLLECTION (Physical) - 0x85, 0x01, // REPORT_ID (1) - 0x05, 0x09, // USAGE_PAGE (Button) - 0x19, 0x01, // USAGE_MINIMUM (Button 1) - 0x29, 0x03, // USAGE_MAXIMUM (Button 3) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x25, 0x01, // LOGICAL_MAXIMUM (1) - 0x95, 0x03, // REPORT_COUNT (3) - 0x75, 0x01, // REPORT_SIZE (1) - 0x81, 0x02, // INPUT (Data,Var,Abs) - 0x95, 0x01, // REPORT_COUNT (1) - 0x75, 0x05, // REPORT_SIZE (5) - 0x81, 0x03, // INPUT (Cnst,Var,Abs) - 0x05, 0x01, // USAGE_PAGE (Generic Desktop) - 0x09, 0x30, // USAGE (X) - 0x09, 0x31, // USAGE (Y) - 0x09, 0x38, // USAGE (Wheel) - 0x15, 0x81, // LOGICAL_MINIMUM (-127) - 0x25, 0x7f, // LOGICAL_MAXIMUM (127) - 0x75, 0x08, // REPORT_SIZE (8) - 0x95, 0x03, // REPORT_COUNT (3) - 0x81, 0x06, // INPUT (Data,Var,Rel) - 0xc0, // END_COLLECTION - 0xc0, // END_COLLECTION + /* Mouse relative */ + 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) 54 */ + 0x09, 0x02, /* USAGE (Mouse) */ + 0xa1, 0x01, /* COLLECTION (Application) */ + 0x85, HID_REPORTID_MOUSE, /* REPORT_ID */ + + /* 8 Buttons */ + 0x05, 0x09, /* USAGE_PAGE (Button) */ + 0x19, 0x01, /* USAGE_MINIMUM (Button 1) */ + 0x29, 0x08, /* USAGE_MAXIMUM (Button 8) */ + 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ + 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ + 0x95, 0x08, /* REPORT_COUNT (8) */ + 0x75, 0x01, /* REPORT_SIZE (1) */ + 0x81, 0x02, /* INPUT (Data,Var,Abs) */ + + /* X, Y, Wheel */ + 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ + 0x09, 0x30, /* USAGE (X) */ + 0x09, 0x31, /* USAGE (Y) */ + 0x09, 0x38, /* USAGE (Wheel) */ + 0x15, 0x81, /* LOGICAL_MINIMUM (-127) */ + 0x25, 0x7f, /* LOGICAL_MAXIMUM (127) */ + 0x75, 0x08, /* REPORT_SIZE (8) */ + 0x95, 0x03, /* REPORT_COUNT (3) */ + 0x81, 0x06, /* INPUT (Data,Var,Rel) */ + + /* End */ + 0xc0 /* END_COLLECTION */ }; //================================================================================ //================================================================================ // Mouse -Mouse_::Mouse_(void) : _buttons(0) +Mouse_::Mouse_(void) : _buttons(0), +HIDDevice((uint8_t*)_hidReportDescriptor, sizeof(_hidReportDescriptor), HID_REPORTID_MOUSE) { - const static HID_Descriptor cb = { - .length = sizeof(_hidReportDescriptor), - .descriptor = _hidReportDescriptor, - }; - static HIDDescriptorListNode node(&cb); - HID.AppendDescriptor(&node); + // HID Descriptor is appended via the inherited HIDDevice class } void Mouse_::begin(void) { + end(); } void Mouse_::end(void) { + _buttons = 0; + move(0, 0, 0); } void Mouse_::click(uint8_t b) @@ -88,12 +86,12 @@ void Mouse_::click(uint8_t b) void Mouse_::move(signed char x, signed char y, signed char wheel) { - uint8_t m[4]; - m[0] = _buttons; - m[1] = x; - m[2] = y; - m[3] = wheel; - HID.SendReport(1,m,4); + HID_MouseReport_Data_t report; + report.buttons = _buttons; + report.xAxis = x; + report.yAxis = y; + report.wheel = wheel; + SendReport(&report, sizeof(report)); } void Mouse_::buttons(uint8_t b) diff --git a/src/ImprovedMouse.h b/src/ImprovedMouse.h index 3ab57a5..0265208 100644 --- a/src/ImprovedMouse.h +++ b/src/ImprovedMouse.h @@ -1,26 +1,27 @@ /* - Mouse.h +Copyright (c) 2014-2015 NicoHood +See the readme for credit to other people. - Copyright (c) 2015, Arduino LLC - Original code (pre-library): Copyright (c) 2011, Peter Barrett +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: - 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. +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. - 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 +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. */ -#ifndef MOUSE_h -#define MOUSE_h +#pragma once #include "HID.h" @@ -34,12 +35,31 @@ //================================================================================ // Mouse -#define MOUSE_LEFT 1 -#define MOUSE_RIGHT 2 -#define MOUSE_MIDDLE 4 -#define MOUSE_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE) +#include "HID-Project.h" -class Mouse_ +#define MOUSE_LEFT (1 << 0) +#define MOUSE_RIGHT (1 << 1) +#define MOUSE_MIDDLE (1 << 2) +#define MOUSE_PREV (1 << 3) +#define MOUSE_NEXT (1 << 4) +// actually this mouse report has 8 buttons (for smaller descriptor) +// but the last 3 wont do anything from what I tested +#define MOUSE_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE | MOUSE_PREV | MOUSE_NEXT) + +typedef union{ + // mouse report: 8 buttons, position, wheel + uint8_t whole8[]; + uint16_t whole16[]; + uint32_t whole32[]; + struct{ + uint8_t buttons; + int8_t xAxis; + int8_t yAxis; + int8_t wheel; + }; +} HID_MouseReport_Data_t; + +class Mouse_ : private HIDDevice { private: uint8_t _buttons; @@ -55,7 +75,5 @@ public: bool isPressed(uint8_t b = MOUSE_LEFT); // check LEFT by default }; extern Mouse_ Mouse; -extern HID_ HID; #endif -#endif \ No newline at end of file