Initial implementation of the new API. Update() isn't functional yet.
This commit is contained in:
parent
cd0fe5829e
commit
c2771502e3
37
Joystick.cpp
37
Joystick.cpp
|
@ -3,11 +3,8 @@
|
||||||
|
|
||||||
Joystick::Joystick(bool debug) {
|
Joystick::Joystick(bool debug) {
|
||||||
_debug = debug;
|
_debug = debug;
|
||||||
}
|
_num_buttons = 0;
|
||||||
|
_num_axes = 0;
|
||||||
void Joystick::Init() {
|
|
||||||
Serial.begin(115200);
|
|
||||||
delay(100);
|
|
||||||
|
|
||||||
for (uint8_t i=0; i < JOYSTICK_NUM_AXES; i++) {
|
for (uint8_t i=0; i < JOYSTICK_NUM_AXES; i++) {
|
||||||
_joyReport.axis[i] = 0;
|
_joyReport.axis[i] = 0;
|
||||||
|
@ -15,20 +12,44 @@ void Joystick::Init() {
|
||||||
for (uint8_t i=0; i < JOYSTICK_NUM_BYTES; i++) {
|
for (uint8_t i=0; i < JOYSTICK_NUM_BYTES; i++) {
|
||||||
_joyReport.button[i] = 0;
|
_joyReport.button[i] = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Joystick::Init() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
delay(100);
|
||||||
|
|
||||||
if (_debug) Serial.println("DEBUG: Joystick library initialized.");
|
if (_debug) Serial.println("DEBUG: Joystick library initialized.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Joystick::AddButton(uint8_t pin, ButtonType type) {
|
void Joystick::AddButton(uint8_t pin, ButtonType type) {
|
||||||
// stub
|
_buttons[_num_buttons].pin = pin;
|
||||||
|
_buttons[_num_buttons].type = type;
|
||||||
|
_buttons[_num_buttons].last_state = digitalRead(pin);
|
||||||
|
_num_buttons++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Joystick::AddAxis(uint8_t pin) {
|
void Joystick::AddAxis(uint8_t pin) {
|
||||||
// stub
|
_axes[_num_axes] = pin;
|
||||||
|
_num_axes++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Joystick::Update() {
|
void Joystick::Update() {
|
||||||
// stub
|
JoyReport oldReport = _joyReport;
|
||||||
|
|
||||||
|
for (int i = 0; i < _num_buttons; i++) {
|
||||||
|
uint8_t value = digitalRead(_buttons[i].pin);
|
||||||
|
// TODO: handle button according to ButtonType
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < _num_axes; i++) {
|
||||||
|
uint16_t value = analogRead(_axes[i]);
|
||||||
|
// TODO: convert raw analog value to something sensible for
|
||||||
|
// HID Analog data.
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_joyReport != oldReport) {
|
||||||
|
Serial.write(_joyReport);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Joystick::SetAxis(uint8_t axis, int16_t value) {
|
void Joystick::SetAxis(uint8_t axis, int16_t value) {
|
||||||
|
|
|
@ -44,9 +44,15 @@ class Joystick {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct {
|
struct {
|
||||||
|
uint8_t pin;
|
||||||
|
ButtonType type;
|
||||||
|
uint8_t last_state;
|
||||||
} _buttons[JOYSTICK_NUM_BUTTONS];
|
} _buttons[JOYSTICK_NUM_BUTTONS];
|
||||||
uint8_t _num_buttons;
|
uint8_t _num_buttons;
|
||||||
|
|
||||||
|
uint8_t _axes[JOYSTICK_NUM_AXES];
|
||||||
|
uint8_t _num_axes;
|
||||||
|
|
||||||
JoyReport _joyReport;
|
JoyReport _joyReport;
|
||||||
bool _debug;
|
bool _debug;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user