fork/GramFirmware
git clone https://git.julia.blue/fork/GramFirmware
38b67d3
v0.1.2
1/************************************************************************ 2MIT License 3 4Copyright (c) 2021 gdsports625@gmail.com 5 6Permission is hereby granted, free of charge, to any person obtaining a copy 7of this software and associated documentation files (the "Software"), to deal 8in the Software without restriction, including without limitation the rights 9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10copies of the Software, and to permit persons to whom the Software is 11furnished to do so, subject to the following conditions: 12 13The above copyright notice and this permission notice shall be included in all 14copies or substantial portions of the Software. 15 16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22SOFTWARE. 23*************************************************************************/ 24#ifndef _TUCOMPOSITE_TUGAMEPAD_HPP 25#define _TUCOMPOSITE_TUGAMEPAD_HPP 26 27#include <Adafruit_TinyUSB.h> 28#include <Arduino.h> 29#include <TUCompositeHID.hpp> 30 31typedef struct TU_ATTR_PACKED { 32uint16_t x ;// X value of left analog stick 33uint16_t y ;// Y value of left analog stick 34uint16_t z ;// Value of analog left trigger 35uint16_t rz ;// Value of analog right trigger 36uint16_t rx ;// X value of right analog stick 37uint16_t ry ;// Y value of right analog stick 38uint8_t hat ;// Position value of the DPad/hat switch 39uint16_t buttons ;// Buttons mask for currently pressed buttons 40}gamepad_report_t ; 41 42class TUGamepad { 43public : 44TUGamepad (); 45 46static void registerDescriptor (); 47 48void begin (); 49bool ready (); 50void resetInputs (); 51bool sendState (); 52 53void press (uint8_t button ); 54void release (uint8_t button ); 55void setButton (uint8_t button ,bool pressed ); 56void releaseAll (); 57 58void buttons (uint16_t buttons ); 59void leftXAxis (uint8_t value ); 60void leftYAxis (uint8_t value ); 61void rightXAxis (uint8_t value ); 62void rightYAxis (uint8_t value ); 63void triggerLAnalog (uint8_t value ); 64void triggerRAnalog (uint8_t value ); 65void hatSwitch (hid_gamepad_hat_t direction ); 66void hatSwitch (bool left ,bool right ,bool down ,bool up ); 67 68protected : 69static const uint8_t _report_id = 1 ; 70static uint8_t _descriptor []; 71 72gamepad_report_t _report ; 73 74private : 75static hid_gamepad_hat_t getHatPosition (bool left ,bool right ,bool down ,bool up ); 76}; 77 78#endif