can't push chnages :(

Fork of FBRDash by Michael Allan

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Gears.cpp Source File

Gears.cpp

00001 #include "Gears.h"
00002 #include "mbed.h"
00003 #include "PinDetect.h"
00004 #include "Comms.h"
00005 
00006 //Detect and process presses of the Gear buttons
00007 
00008 //Initialise members and set up button handlers
00009 Gears::Gears(PinName up, PinName neutral, PinName down, unsigned char* _currentGear, Comms* _remote)
00010 {
00011     currentGear = _currentGear;
00012     remote = _remote;
00013 
00014     btnUp = new PinDetect(up, PullUp);
00015     btnNeutral = new PinDetect(neutral, PullUp);
00016     btnDown = new PinDetect(down, PullUp);
00017 
00018     //Set buttons as pull down to assert
00019     btnUp->setAssertValue(0);
00020     btnDown->setAssertValue(0);
00021     btnNeutral->setAssertValue(0);
00022     
00023     //Attach handlers
00024     btnUp->attach_asserted(this, &Gears::up);
00025     btnDown->attach_asserted(this, &Gears::down);
00026     btnNeutral->attach_asserted(this, &Gears::neutral);
00027     
00028     //Start checking buttons
00029     btnUp->setSampleFrequency();
00030     btnDown->setSampleFrequency();
00031     btnNeutral->setSampleFrequency();
00032 }
00033 
00034 void Gears::up()
00035 {
00036     //Send change up command
00037     remote->send(2);
00038     
00039     //Update state
00040     if(*currentGear < 6)
00041         (*currentGear)++;
00042 }
00043 
00044 void Gears::neutral()
00045 {
00046     //Sent neutral command
00047     remote->send(0);
00048     
00049     //Update state
00050     *currentGear = 0;
00051 }
00052 
00053 void Gears::down()
00054 {
00055     //Send change down command
00056     remote->send(1);
00057     
00058     //Update state
00059     if(*currentGear > 0)
00060     {
00061         (*currentGear)--;
00062     }
00063 }