Code for Doug, Elizabeth, and Maruchi's team project: a Mario Kart controller.

Dependencies:   PinDetect USBDevice mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers KeyManager.h Source File

KeyManager.h

00001 /**
00002  * Class KeyManager
00003  *
00004  * This class tracks the state of the four input
00005  * buttons and returns state information and
00006  * mappings.
00007  *
00008  */
00009 
00010 #ifndef KEYMANAGER
00011 #define KEYMANAGER
00012 
00013 #include <string>
00014 #include <ctype.h>
00015 
00016 class KeyManager {
00017 private:
00018     // key definitions
00019     bool keyA;
00020     bool keyB;
00021     bool keyC;
00022     bool keyZ;
00023         
00024 public:
00025     
00026     // constructor
00027     KeyManager() {
00028         keyA = false;
00029         keyB = false;
00030         keyC = false;
00031         keyZ = false;
00032     }
00033     
00034     // DEBUG: return the status of which keys are pressed
00035     char* getStatusString() {
00036         std::string status = "the following keys are pressed:";
00037         if (keyA) {
00038            status += " A";
00039         }
00040         if (keyB) {
00041            status += " B";
00042         }
00043         if (keyC) {
00044            status += " C";
00045         }
00046         if (keyZ) {
00047            status += " Z";
00048         }
00049         status += "\n";
00050         return (char*)status.c_str(); 
00051     }
00052     
00053     // map the current code to its character
00054     char getCharacter() {
00055         if (keyA) {
00056             return 'a';
00057         }
00058         if (keyB) {
00059             return 'b';
00060         }
00061         if (keyC) {
00062             return 'c';
00063         }
00064         if (keyZ) {
00065             return 'z';
00066         }
00067         return '?';
00068     }
00069     
00070     // check whether any of the character keys or the space
00071     // key are pressed
00072     bool keysPressed() {
00073         if (keyA || keyB || keyC || keyZ) {
00074             return true;   
00075         }
00076         return false;
00077     }
00078     
00079     // Interrupt callback functions
00080     void keyAOn() { keyA = true; }
00081     void keyAOff() { keyA = false; }
00082     void keyBOn() { keyB = true; }
00083     void keyBOff() { keyB = false; }
00084     void keyCOn() { keyC = true; }
00085     void keyCOff() { keyC = false; }
00086     void keyZOn() { keyZ = true; }
00087     void keyZOff() { keyZ = false; }
00088 
00089 };
00090 
00091 #endif