-
Notifications
You must be signed in to change notification settings - Fork 0
/
Joystick.h
executable file
·87 lines (65 loc) · 2.17 KB
/
Joystick.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
Joystick.h
Copyright (c) 2015, Matthew Heironimus
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.
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
*/
#ifndef JOYSTICK_h
#define JOYSTICK_h
#include "HID.h"
#if ARDUINO < 10606
#error The Joystick library requires Arduino IDE 1.6.6 or greater. Please update your IDE.
#endif
#if !defined(USBCON)
#error The Joystick library can only be used with a USB MCU (e.g. Arduino Leonardo, Arduino Micro, etc.).
#endif
#if !defined(_USING_HID)
#warning "Using legacy HID core (non pluggable)"
#else
//================================================================================
//================================================================================
// Joystick (Gamepad)
class Joystick_
{
private:
bool autoSendState;
int8_t xAxis;
int8_t yAxis;
int8_t zAxis;
int16_t xAxisRotation;
int16_t yAxisRotation;
int16_t zAxisRotation;
uint32_t buttons;
uint8_t throttle;
uint8_t rudder;
int16_t hatSwitch[2];
public:
Joystick_();
void begin(bool initAutoSendState = true);
void end();
void setXAxis(int8_t value);
void setYAxis(int8_t value);
void setZAxis(int8_t value);
void setXAxisRotation(int16_t value);
void setYAxisRotation(int16_t value);
void setZAxisRotation(int16_t value);
void setButton(uint8_t button, uint8_t value);
void pressButton(uint8_t button);
void releaseButton(uint8_t button);
void setThrottle(uint8_t value);
void setRudder(uint8_t value);
void setHatSwitch(int8_t hatSwitch, int16_t value);
void sendState();
};
extern Joystick_ Joystick;
#endif
#endif