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:
- 24:7b149f5d4bef
- Parent:
- 23:34da21dfdfd6
- Child:
- 26:ccdf299b26c4
--- a/Controller.cpp Sat Apr 15 15:39:47 2017 +0000 +++ b/Controller.cpp Sun Apr 16 13:45:22 2017 +0000 @@ -1,5 +1,4 @@ #include "Controller.h" - #include "mbed.h" //////////// constructor/destructor //////////// @@ -30,10 +29,8 @@ _timeout(new Timeout()), - _event_state(0), + _event_state(0) - _x0(0), - _y0(0) {} Controller::~Controller() @@ -48,23 +45,19 @@ void Controller::init() { - leds_off(); + ledsOFF(); init_buttons(); - // read centred values of joystick - _x0 = _horiz->read(); - _y0 = _vert->read(); - // clear all flags _event_state = 0; } -void Controller::leds_off() +void Controller::ledsOFF() { leds(0.0); } -void Controller::leds_on() +void Controller::ledsON() { leds(1.0); } @@ -77,7 +70,7 @@ if (val > 1.0f) { val = 1.0f; } - + // leds are active-low, so subtract from 1.0 // 0.0 corresponds to fully-off, 1.0 to fully-on val = 1.0f - val; @@ -126,16 +119,16 @@ } } -float Controller::read_pot() const +float Controller::pot_value() const { return _pot->read(); } -void Controller::tone(float frequency, float duration) +void Controller::sound(float frequency, float duration) { _buzzer->period(1.0f/frequency); _buzzer->write(0.5); // 50% duty cycle - square wave - _timeout->attach(callback(this, &Controller::tone_off), duration ); + _timeout->attach(callback(this, &Controller::sound_off), duration ); } bool Controller::check_event(ControllerEvent const id) @@ -151,7 +144,7 @@ ///////////////////// private methods //////////////////////// -void Controller::tone_off() +void Controller::sound_off() { // called after timeout _buzzer->write(0.0);