2015-11-05 03:02:09 +00:00
|
|
|
#include "Joystick.h"
|
|
|
|
#include <Arduino.h>
|
|
|
|
|
|
|
|
Joystick::Joystick(bool debug) {
|
|
|
|
_debug = debug;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Joystick::Init() {
|
|
|
|
Serial.begin(115200);
|
|
|
|
delay(100);
|
|
|
|
|
|
|
|
for (uint8_t i=0; i < JOYSTICK_NUM_AXES; i++) {
|
|
|
|
_joyReport.axis[i] = 0;
|
|
|
|
}
|
|
|
|
for (uint8_t i=0; i < JOYSTICK_NUM_BYTES; i++) {
|
|
|
|
_joyReport.button[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_debug) Serial.println("DEBUG: Joystick library initialized.");
|
|
|
|
}
|
|
|
|
|
2015-11-06 15:48:38 +00:00
|
|
|
void Joystick::AddButton(uint8_t pin, ButtonType type) {
|
|
|
|
// stub
|
|
|
|
}
|
|
|
|
|
|
|
|
void Joystick::AddAxis(uint8_t pin) {
|
|
|
|
// stub
|
|
|
|
}
|
|
|
|
|
|
|
|
void Joystick::Update() {
|
|
|
|
// stub
|
|
|
|
}
|
|
|
|
|
2015-11-05 03:02:09 +00:00
|
|
|
void Joystick::SetAxis(uint8_t axis, int16_t value) {
|
|
|
|
if (axis >= JOYSTICK_NUM_AXES) return;
|
|
|
|
_joyReport.axis[axis] = value;
|
|
|
|
if (_debug) Serial.println("DEBUG: Axis change recorded.");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Joystick::PressButton(uint8_t button) {
|
|
|
|
if (button >= JOYSTICK_NUM_BUTTONS) return;
|
|
|
|
uint8_t byte = button / 8;
|
|
|
|
uint8_t bit = button % 8;
|
|
|
|
_joyReport.button[byte] |= 1 << bit;
|
|
|
|
if (_debug) Serial.println("DEBUG: Button press recorded.");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Joystick::ReleaseButton(uint8_t button) {
|
|
|
|
if (button >= JOYSTICK_NUM_BUTTONS) return;
|
|
|
|
uint8_t byte = button / 8;
|
|
|
|
uint8_t bit = button % 8;
|
|
|
|
_joyReport.button[byte] |= 0 << bit;
|
|
|
|
if (_debug) Serial.println("DEBUG: Button release recorded.");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Joystick::ReleaseAllButtons() {
|
|
|
|
for (uint8_t i = 0; i < JOYSTICK_NUM_BYTES; i++) {
|
|
|
|
_joyReport.button[i] = 0;
|
|
|
|
}
|
|
|
|
if (_debug) Serial.println("DEBUG: All-button release recorded.");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Joystick::Write() {
|
|
|
|
Serial.write((uint8_t *)&_joyReport, sizeof(JoyReport));
|
|
|
|
delay(250);
|
|
|
|
}
|