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
Diff: Input/Input.cpp
- Revision:
- 22:0a474f074553
- Parent:
- 16:3f84f2d7b910
- Child:
- 25:bf47fe41883a
--- a/Input/Input.cpp Wed Apr 03 20:33:27 2019 +0000
+++ b/Input/Input.cpp Thu Apr 04 07:08:39 2019 +0000
@@ -1,14 +1,60 @@
#include "Input.h"
#include "Gamepad.h"
#include "mbed.h" // TODO DELETE
-
+namespace Input {
+
+ enum State {NOT_HIT, HIT};
+ Gamepad * gamepad;
+ const int NUMBER_OF_BUTTONS = 5;
+ State states[5]; // NUM_OF_BS
+
+ void updateButtonState(Button button, Gamepad::GamepadEvent event);
+
+ void init() {
+ gamepad = new Gamepad();
+ gamepad->init();
+
+ for (int i = 0; i < NUMBER_OF_BUTTONS; i++) {
+ states[i] = NOT_HIT;
+ }
+ }
+
+ void deinit() {
+ delete gamepad;
+ }
+
+ void update() {
+ // reset states
+ for (int i = 0; i < NUMBER_OF_BUTTONS; i++) {
+ states[i] = NOT_HIT;
+ }
+
+ // update state to reflect events
+ updateButtonState(LEFT, Gamepad::A_PRESSED);
+ updateButtonState(RIGHT, Gamepad::Y_PRESSED);
+ updateButtonState(UP, Gamepad::X_PRESSED);
+ updateButtonState(DOWN, Gamepad::B_PRESSED);
+ updateButtonState(START, Gamepad::START_PRESSED);
+ }
+
+ bool buttonHit(Button button) {
+ return states[button] == HIT;
+ }
+
+ void updateButtonState(Button button, Gamepad::GamepadEvent event) {
+ if (gamepad->check_event(event)) {
+ states[button] = HIT;
+ }
+ }
+};
+/*
namespace Input {
enum State {RELEASED, RELEASED_FRAME, HIT_FRAME, HELD};
Gamepad * gamepad;
- const int NUMBER_OF_BUTTONS = 4;
- State states[4]; // NUM_OF_BS
- int frame_hit[4] = {-99}; // NUM_OF_BS
+ const int NUMBER_OF_BUTTONS = 5;
+ State states[5]; // NUM_OF_BS
+ int frame_hit[5] = {-99}; // NUM_OF_BS
int frame = 0;
const int bounce_frames = 0;
void updateButtonState(Button button, Gamepad::GamepadEvent event);
@@ -45,6 +91,7 @@
updateButtonState(RIGHT, Gamepad::Y_PRESSED);
updateButtonState(UP, Gamepad::X_PRESSED);
updateButtonState(DOWN, Gamepad::B_PRESSED);
+ updateButtonState(START, Gamepad::START_PRESSED);
}
bool buttonHit(Button button) {
@@ -75,3 +122,4 @@
}
}
}
+*/
\ No newline at end of file
