Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of el17ajf by
Input/Input.cpp
- Committer:
- el17ajf
- Date:
- 2019-03-17
- Revision:
- 12:beb0d7632531
- Parent:
- 10:5762d7fae033
- Child:
- 13:59e17cab320a
File content as of revision 12:beb0d7632531:
#include "Input.h"
#include "mbed.h" // TODO DELETE
const int NUMBER_OF_BUTTONS = 4;
Input::State Input::states[NUMBER_OF_BUTTONS];
Gamepad * Input::gamepad;
void Input::init() {
gamepad = new Gamepad();
gamepad->init();
//printf("%d\n", NUMBER_OF_BUTTONS);
/*
for (int i = 0; i < 4; i++) {
Input::states[i] = RELEASED;
}
*/
}
void Input::deinit() {
delete gamepad;
}
void Input::update() {
// update existing states
for (int i = 0; i < NUMBER_OF_BUTTONS; i++) {
if (Input::states[i] == RELEASED_FRAME) {
Input::states[i] = RELEASED;
}
if (Input::states[i] == HIT_FRAME) {
Input::states[i] = HELD;
}
}
// check inputs
if (gamepad->check_event(Gamepad::Y_PRESSED)) {
// states[RIGHT] = HIT_FRAME;
printf("RIGHT\n");
}
}
bool Input::buttonHit(Button button) {
return Input::states[button] == HIT_FRAME;
}
bool Input::buttonHeld(Button button) {
return Input::states[button] == HIT_FRAME
|| Input::states[button] == HELD;
}
