Library for ELEC2645 Gamepad PCB. University of Leeds Version 2 January 2020
Dependents: ELEC2645_Ticker_WAV ELEC2645_Project_username ELEC2645_Project_el18vgt ELEC2645_Project_el17oc11 ... more
Diff: Gamepad.cpp
- Revision:
- 12:1b0b6355da4f
- Parent:
- 11:ff86b2ffce01
- Child:
- 13:ef5fc9f58805
diff -r ff86b2ffce01 -r 1b0b6355da4f Gamepad.cpp --- a/Gamepad.cpp Thu Mar 02 18:34:42 2017 +0000 +++ b/Gamepad.cpp Fri Mar 03 12:35:43 2017 +0000 @@ -50,15 +50,7 @@ _y0 = _vert->read(); // clear all flags - _a_flag = false; - _b_flag = false; - _x_flag = false; - _y_flag = false; - _joy_flag = false; - _l_flag = false; - _r_flag = false; - _back_flag = false; - _start_flag = false; + _event_state = 0; } void Gamepad::leds_off() @@ -123,99 +115,11 @@ _timeout->attach(callback(this, &Gamepad::tone_off), duration ); } -bool Gamepad::a_pressed() -{ - // ISR must have been triggered - if (_a_flag) { - _a_flag = 0; // clear flag - return true; - } else { - return false; - } -} - -bool Gamepad::b_pressed() -{ - // ISR must have been triggered - if (_b_flag) { - _b_flag = false; // clear flag - return true; - } else { - return false; - } -} - -bool Gamepad::x_pressed() -{ - // ISR must have been triggered - if (_x_flag) { - _x_flag = false; // clear flag - return true; - } else { - return false; - } -} - -bool Gamepad::y_pressed() -{ - // ISR must have been triggered - if (_y_flag) { - _y_flag = false; // clear flag - return true; - } else { - return false; - } -} - -bool Gamepad::l_pressed() +bool Gamepad::check_event(GamepadEvent const id) { - // ISR must have been triggered - if (_l_flag) { - _l_flag = false; // clear flag - return true; - } else { - return false; - } -} - -bool Gamepad::r_pressed() -{ - // ISR must have been triggered - if (_r_flag) { - _r_flag = false; // clear flag - return true; - } else { - return false; - } -} - -bool Gamepad::back_pressed() -{ - // ISR must have been triggered - if (_back_flag) { - _back_flag = false; // clear flag - return true; - } else { - return false; - } -} - -bool Gamepad::start_pressed() -{ - // ISR must have been triggered - if (_start_flag) { - _start_flag = false; // clear flag - return true; - } else { - return false; - } -} - -bool Gamepad::joystick_pressed() -{ - // ISR must have been triggered - if (_joy_flag) { - _joy_flag = false; // clear flag + // Check whether event flag is set + if (_event_state[id]) { + _event_state.reset(id); // clear flag return true; } else { return false; @@ -300,41 +204,43 @@ } // button interrupts ISRs +// Each of these simply sets the appropriate event bit in the _event_state +// variable void Gamepad::a_isr() { - _a_flag=true; + _event_state.set(EVENT_A_PRESSED); } void Gamepad::b_isr() { - _b_flag=true; + _event_state.set(EVENT_B_PRESSED); } void Gamepad::x_isr() { - _x_flag=true; + _event_state.set(EVENT_X_PRESSED); } void Gamepad::y_isr() { - _y_flag=true; + _event_state.set(EVENT_Y_PRESSED); } void Gamepad::l_isr() { - _l_flag=true; + _event_state.set(EVENT_L_PRESSED); } void Gamepad::r_isr() { - _r_flag=true; + _event_state.set(EVENT_R_PRESSED); } void Gamepad::back_isr() { - _back_flag=true; + _event_state.set(EVENT_BACK_PRESSED); } void Gamepad::start_isr() { - _start_flag=true; + _event_state.set(EVENT_START_PRESSED); } void Gamepad::joy_isr() { - _joy_flag=true; + _event_state.set(EVENT_JOY_PRESSED); } // get raw joystick coordinate in range -1 to 1