Code for Doug, Elizabeth, and Maruchi's team project: a Mario Kart controller.
Dependencies: PinDetect USBDevice mbed
Diff: KeyManager.h
- Revision:
- 0:0c8c5c9f7586
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/KeyManager.h Mon Sep 29 06:55:14 2014 +0000 @@ -0,0 +1,91 @@ +/** + * Class KeyManager + * + * This class tracks the state of the four input + * buttons and returns state information and + * mappings. + * + */ + +#ifndef KEYMANAGER +#define KEYMANAGER + +#include <string> +#include <ctype.h> + +class KeyManager { +private: + // key definitions + bool keyA; + bool keyB; + bool keyC; + bool keyZ; + +public: + + // constructor + KeyManager() { + keyA = false; + keyB = false; + keyC = false; + keyZ = false; + } + + // DEBUG: return the status of which keys are pressed + char* getStatusString() { + std::string status = "the following keys are pressed:"; + if (keyA) { + status += " A"; + } + if (keyB) { + status += " B"; + } + if (keyC) { + status += " C"; + } + if (keyZ) { + status += " Z"; + } + status += "\n"; + return (char*)status.c_str(); + } + + // map the current code to its character + char getCharacter() { + if (keyA) { + return 'a'; + } + if (keyB) { + return 'b'; + } + if (keyC) { + return 'c'; + } + if (keyZ) { + return 'z'; + } + return '?'; + } + + // check whether any of the character keys or the space + // key are pressed + bool keysPressed() { + if (keyA || keyB || keyC || keyZ) { + return true; + } + return false; + } + + // Interrupt callback functions + void keyAOn() { keyA = true; } + void keyAOff() { keyA = false; } + void keyBOn() { keyB = true; } + void keyBOff() { keyB = false; } + void keyCOn() { keyC = true; } + void keyCOff() { keyC = false; } + void keyZOn() { keyZ = true; } + void keyZOff() { keyZ = false; } + +}; + +#endif \ No newline at end of file