kekw

Dependencies:   mbed C12832_lcd MMA7660

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers controller.h Source File

controller.h

00001 #include "mbed.h"
00002 #include "MMA7660.h"
00003 #include "C12832_lcd.h"
00004 #include "USBMouse.h"
00005 
00006 C12832_LCD lcd;
00007 USBMouse mouseOne;
00008 MMA7660 MMAOne(p28, p27);
00009 
00010 DigitalIn   click(p14);
00011 DigitalIn   left(p13);
00012 DigitalIn   right(p16);
00013 DigitalIn   up(p15);
00014 DigitalIn   down(p12);
00015 
00016 AnalogIn   potX(p19);
00017 AnalogIn   potY(p20);
00018 
00019 class controller{
00020 public:
00021     virtual int calculateX(int x){ return x; }
00022     virtual int calculateY(int y){ return y; }
00023     virtual void leftClick(){
00024         if(click == 1){
00025             mouseOne.buttons(1,0,0);    
00026             wait(0.2);
00027         }
00028     }
00029     virtual void moveCursor() {lcd.printf("Test\n\r");}
00030 protected:
00031     int x,y;
00032 };
00033 class accelController: public controller{
00034 public:
00035     accelController(){
00036         x = 0;
00037         y = 0;
00038     }
00039     int calculateX(){ return (this->x + MMAOne.x() * 32.0)/2.0; }
00040     int calculateY(){ return (this->y - MMAOne.y() * 16.0)/2.0; }
00041     void moveCursor(){
00042         x = calculateX();
00043         y = calculateY();
00044         wait(.1); //time delay
00045         mouseOne.move((-x)*2, (-y)*2);
00046         leftClick();
00047     }
00048 };
00049 class joystickController: public controller{
00050 public:
00051     joystickController(){
00052         x = 0;
00053         y = 0;
00054     }
00055     void calculateX(){
00056         if(left == 1){ this->x = (this->x - (25)) / 3; }        // move mouse left
00057         else if(right == 1){ this->x = (25) / 2; }        // move mouse right
00058         else{ this->x = 0; }                              // keeps mouse stationary
00059     }
00060     void calculateY(){
00061         
00062         if(up == 1){ this->y = (this->y - (25)) / 3; }          // move mouse down
00063         else if(down == 1){ this->y = (25) / 2; }         // move mouse up
00064         else{ this->y = 0; }                              // keeps mouse stationary
00065     }
00066     void moveCursor(){
00067         calculateX();
00068         calculateY();
00069         mouseOne.buttons(0,0,0);    
00070         mouseOne.move(x, y);
00071         leftClick();
00072         wait(0.001);
00073     }   
00074 };
00075 class potController: public controller{
00076     int16_t a_inx;
00077     int16_t a_iny;
00078 public:
00079     potController(){
00080         x = 0;
00081         y = 0;
00082     }
00083     void calculateX(){
00084        a_inx = (int16_t)(potY.read() * 100.0);
00085        if(a_inx > 52){x = (x - (50 - a_inx)) / 3;}
00086         else if(a_inx < 47){x = (a_inx - 50) / 2;}
00087         else{x = 0;}
00088     }
00089     void calculateY(){
00090        a_iny = (int16_t)(potX.read() * 100.0);
00091        if(a_iny > 52 && a_iny != 99){ y = (y - (50 - a_iny)) / 3; }
00092         else if(a_iny < 47){ y = (a_iny - 50) / 2; }
00093         else{ y = 0; }
00094     }
00095     void moveCursor(){
00096         
00097         calculateX();
00098         calculateY();
00099         leftClick();
00100         mouseOne.move(x, y);
00101         wait(0.001);
00102     }
00103        
00104 };