This Class allows the joystick, buttons and petiometers to be implemented easily and coherently in other classes
Fork of Gamepad by
Diff: Controller.cpp
- Revision:
- 26:ccdf299b26c4
- Parent:
- 24:7b149f5d4bef
- Child:
- 27:d51c87ced56e
--- a/Controller.cpp Sun Apr 16 19:38:43 2017 +0000 +++ b/Controller.cpp Sun Apr 16 21:18:08 2017 +0000 @@ -29,8 +29,9 @@ _timeout(new Timeout()), - _event_state(0) - + _event_state(0), + _x0(0) + {} Controller::~Controller() @@ -50,6 +51,8 @@ // clear all flags _event_state = 0; + // read joystick + _x0 = _horiz->read(); } void Controller::ledsOFF() @@ -215,6 +218,21 @@ _event_state.set(JOY_PRESSED); } + + +// get raw joystick coordinate for x in range -1 to 1 +// North (0,1) +// South (0,-1) + +float Controller::get_joy() +{ + // read() returns value in range 0.0 to 1.0 so is scaled and centre value + // substracted to get values in the range -1.0 to 1.0 + float x = 2.0f*( _horiz->read() - _x0 ); + return x; +} + + int Controller::check_for_buttons() { if (check_event(A_PRESSED)) { return 1; }