4 errors

Dependencies:   KS0108_PCF8574 mbed

Committer:
GuiTwo
Date:
Tue Sep 11 10:21:10 2012 +0000
Revision:
3:ec80bb6ff5da
Parent:
0:936f1c020120
4 errors on vector .cc

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GuiTwo 0:936f1c020120 1 #include "mbed.h"
GuiTwo 0:936f1c020120 2 #include "include/menbedNavigator.h"
GuiTwo 0:936f1c020120 3 #include "include/menbedButtonHandlerTimespec.h"
GuiTwo 0:936f1c020120 4 #include "include/menbedButtonHandler.h"
GuiTwo 0:936f1c020120 5
GuiTwo 0:936f1c020120 6 MenbedButtonHandler::MenbedButtonHandler (PinName selectPin, PinName downPin,
GuiTwo 0:936f1c020120 7 PinName upPin, PinName cancelPin, MenbedButtonHandlerTimespec *timespec,
GuiTwo 0:936f1c020120 8 MenbedNavigator *navigator) :
GuiTwo 0:936f1c020120 9 //select(select), down(down), up(up), cancel(cancel),
GuiTwo 0:936f1c020120 10 timespec(timespec), navigator(navigator)
GuiTwo 0:936f1c020120 11 {
GuiTwo 0:936f1c020120 12 select = new DigitalIn(selectPin);
GuiTwo 0:936f1c020120 13 down = new DigitalIn(downPin);
GuiTwo 0:936f1c020120 14 up = new DigitalIn(upPin);
GuiTwo 0:936f1c020120 15 cancel = new DigitalIn(cancelPin);
GuiTwo 0:936f1c020120 16
GuiTwo 0:936f1c020120 17 numButtons = 4;
GuiTwo 0:936f1c020120 18
GuiTwo 0:936f1c020120 19 select->mode (PullDown);
GuiTwo 0:936f1c020120 20 down->mode (PullDown);
GuiTwo 0:936f1c020120 21 up->mode (PullDown);
GuiTwo 0:936f1c020120 22 cancel->mode (PullDown);
GuiTwo 0:936f1c020120 23
GuiTwo 0:936f1c020120 24 init();
GuiTwo 0:936f1c020120 25 }
GuiTwo 0:936f1c020120 26
GuiTwo 0:936f1c020120 27
GuiTwo 0:936f1c020120 28 MenbedButtonHandler::MenbedButtonHandler (PinName selectPin, PinName downPin,
GuiTwo 0:936f1c020120 29 PinName upPin, MenbedButtonHandlerTimespec *timespec,
GuiTwo 0:936f1c020120 30 MenbedNavigator *navigator) :
GuiTwo 0:936f1c020120 31 timespec(timespec), navigator(navigator)
GuiTwo 0:936f1c020120 32 {
GuiTwo 0:936f1c020120 33 select = new DigitalIn(selectPin);
GuiTwo 0:936f1c020120 34 down = new DigitalIn(downPin);
GuiTwo 0:936f1c020120 35 up = new DigitalIn(upPin);
GuiTwo 0:936f1c020120 36
GuiTwo 0:936f1c020120 37 numButtons = 3;
GuiTwo 0:936f1c020120 38
GuiTwo 0:936f1c020120 39 select->mode (PullDown);
GuiTwo 0:936f1c020120 40 down->mode (PullDown);
GuiTwo 0:936f1c020120 41 up->mode (PullDown);
GuiTwo 0:936f1c020120 42
GuiTwo 0:936f1c020120 43 init();
GuiTwo 0:936f1c020120 44 }
GuiTwo 0:936f1c020120 45
GuiTwo 0:936f1c020120 46
GuiTwo 0:936f1c020120 47 MenbedButtonHandler::MenbedButtonHandler (PinName selectPin, PinName downPin,
GuiTwo 0:936f1c020120 48 MenbedButtonHandlerTimespec *timespec,
GuiTwo 0:936f1c020120 49 MenbedNavigator *navigator) :
GuiTwo 0:936f1c020120 50 timespec(timespec), navigator(navigator)
GuiTwo 0:936f1c020120 51 {
GuiTwo 0:936f1c020120 52 select = new DigitalIn(selectPin);
GuiTwo 0:936f1c020120 53 down = new DigitalIn(downPin);
GuiTwo 0:936f1c020120 54
GuiTwo 0:936f1c020120 55 numButtons = 2;
GuiTwo 0:936f1c020120 56
GuiTwo 0:936f1c020120 57 select->mode (PullDown);
GuiTwo 0:936f1c020120 58 down->mode (PullDown);
GuiTwo 0:936f1c020120 59
GuiTwo 0:936f1c020120 60 init();
GuiTwo 0:936f1c020120 61 }
GuiTwo 0:936f1c020120 62
GuiTwo 0:936f1c020120 63
GuiTwo 0:936f1c020120 64 void MenbedButtonHandler::init()
GuiTwo 0:936f1c020120 65 {
GuiTwo 0:936f1c020120 66 for (int i=0; i<4; i++)
GuiTwo 0:936f1c020120 67 {
GuiTwo 0:936f1c020120 68 buttonDebounced[i] = false;
GuiTwo 0:936f1c020120 69 buttonAlreadyDepressed[i] = false;
GuiTwo 0:936f1c020120 70 }
GuiTwo 0:936f1c020120 71
GuiTwo 0:936f1c020120 72 currentTime_us = 0;
GuiTwo 0:936f1c020120 73 ticker.attach_us (this, &MenbedButtonHandler::tick,
GuiTwo 0:936f1c020120 74 timespec->scanPeriod_us);
GuiTwo 0:936f1c020120 75 }
GuiTwo 0:936f1c020120 76
GuiTwo 0:936f1c020120 77
GuiTwo 0:936f1c020120 78 void MenbedButtonHandler::tick (void)
GuiTwo 0:936f1c020120 79 {
GuiTwo 0:936f1c020120 80 // Accumulated amount of time that buttons have been continuously depressed
GuiTwo 0:936f1c020120 81 uint32_t buttonDepressedTime_us;
GuiTwo 0:936f1c020120 82 bool buttonCurrentlyDepressed;
GuiTwo 0:936f1c020120 83
GuiTwo 0:936f1c020120 84 MenbedButtonEvent buttonEvent;
GuiTwo 0:936f1c020120 85 buttonEvent.numButtons = numButtons;
GuiTwo 0:936f1c020120 86
GuiTwo 0:936f1c020120 87 currentTime_us += timespec->scanPeriod_us;
GuiTwo 0:936f1c020120 88
GuiTwo 0:936f1c020120 89 // Cycle through each of the buttons
GuiTwo 0:936f1c020120 90 for (int i=MenbedButtonEvent::ButtonSelect;
GuiTwo 0:936f1c020120 91 (i<=MenbedButtonEvent::ButtonCancel) && (i<numButtons);
GuiTwo 0:936f1c020120 92 i++)
GuiTwo 0:936f1c020120 93 {
GuiTwo 0:936f1c020120 94 buttonEvent.name = (MenbedButtonEvent::ButtonName)i;
GuiTwo 0:936f1c020120 95 buttonCurrentlyDepressed =
GuiTwo 0:936f1c020120 96 isButtonDepressed((MenbedButtonEvent::ButtonName)i);
GuiTwo 0:936f1c020120 97
GuiTwo 0:936f1c020120 98 // The amount of time the current button has been depressed is
GuiTwo 0:936f1c020120 99 // the current time minus the time which the button was first
GuiTwo 0:936f1c020120 100 // depressed.
GuiTwo 0:936f1c020120 101 buttonDepressedTime_us = currentTime_us - buttonPushedTime_us[i];
GuiTwo 0:936f1c020120 102
GuiTwo 0:936f1c020120 103 if (buttonCurrentlyDepressed && buttonAlreadyDepressed[i])
GuiTwo 0:936f1c020120 104 {
GuiTwo 0:936f1c020120 105 if ((buttonDepressedTime_us >= timespec->typematicX10Delay_us) &&
GuiTwo 0:936f1c020120 106 (currentTime_us - buttonLastTypematicTime_us[i] >=
GuiTwo 0:936f1c020120 107 timespec->typematicX10Period_us ))
GuiTwo 0:936f1c020120 108 {
GuiTwo 0:936f1c020120 109 buttonLastTypematicTime_us[i] = currentTime_us;
GuiTwo 0:936f1c020120 110 buttonEvent.action = MenbedButtonEvent::BUTTON_ACTION_PUSHED;
GuiTwo 0:936f1c020120 111 navigator->handleButtonEvent (buttonEvent);
GuiTwo 0:936f1c020120 112 }
GuiTwo 0:936f1c020120 113 else if ((buttonDepressedTime_us >=
GuiTwo 0:936f1c020120 114 timespec->typematicPeriod_us)
GuiTwo 0:936f1c020120 115 && (currentTime_us - buttonLastTypematicTime_us[i] >=
GuiTwo 0:936f1c020120 116 timespec->typematicPeriod_us))
GuiTwo 0:936f1c020120 117 {
GuiTwo 0:936f1c020120 118 buttonLastTypematicTime_us[i] = currentTime_us;
GuiTwo 0:936f1c020120 119 buttonEvent.action = MenbedButtonEvent::BUTTON_ACTION_PUSHED;
GuiTwo 0:936f1c020120 120 navigator->handleButtonEvent (buttonEvent);
GuiTwo 0:936f1c020120 121 }
GuiTwo 0:936f1c020120 122 else if ((buttonDepressedTime_us >= timespec->debounceDelay_us)
GuiTwo 0:936f1c020120 123 && (!buttonDebounced[i]))
GuiTwo 0:936f1c020120 124 {
GuiTwo 0:936f1c020120 125 buttonLastTypematicTime_us[i] = currentTime_us;
GuiTwo 0:936f1c020120 126 buttonDebounced[i] = true;
GuiTwo 0:936f1c020120 127 buttonEvent.action = MenbedButtonEvent::BUTTON_ACTION_PUSHED;
GuiTwo 0:936f1c020120 128 navigator->handleButtonEvent (buttonEvent);
GuiTwo 0:936f1c020120 129 }
GuiTwo 0:936f1c020120 130
GuiTwo 0:936f1c020120 131 if (buttonDebounced[i] &&
GuiTwo 0:936f1c020120 132 (buttonDepressedTime_us >=
GuiTwo 0:936f1c020120 133 timespec->longReleaseDelay_us))
GuiTwo 0:936f1c020120 134 {
GuiTwo 0:936f1c020120 135 buttonEvent.action = MenbedButtonEvent::BUTTON_ACTION_HELD_LONG;
GuiTwo 0:936f1c020120 136 navigator->handleButtonEvent (buttonEvent);
GuiTwo 0:936f1c020120 137 }
GuiTwo 0:936f1c020120 138
GuiTwo 0:936f1c020120 139 buttonAlreadyDepressed[i] = true;
GuiTwo 0:936f1c020120 140 }
GuiTwo 0:936f1c020120 141 // Otherwise, if the button was just depressed, we indicate that it
GuiTwo 0:936f1c020120 142 // has not yet debounced and record the time so that we know when it
GuiTwo 0:936f1c020120 143 // was first pressed.
GuiTwo 0:936f1c020120 144 else if (buttonCurrentlyDepressed && !buttonAlreadyDepressed[i])
GuiTwo 0:936f1c020120 145 {
GuiTwo 0:936f1c020120 146 buttonDebounced[i] = false;
GuiTwo 0:936f1c020120 147 buttonPushedTime_us[i] = currentTime_us;
GuiTwo 0:936f1c020120 148
GuiTwo 0:936f1c020120 149 buttonAlreadyDepressed[i] = true;
GuiTwo 0:936f1c020120 150 }
GuiTwo 0:936f1c020120 151 // Otherwise, if the button is not depressed but it was previously
GuiTwo 0:936f1c020120 152 // depressed and the amount of time it was depressed exceeds the
GuiTwo 0:936f1c020120 153 // debounce time, then we say the button has been released.
GuiTwo 0:936f1c020120 154 else if (!buttonCurrentlyDepressed && buttonAlreadyDepressed[i])
GuiTwo 0:936f1c020120 155 {
GuiTwo 0:936f1c020120 156 if (buttonDebounced[i])
GuiTwo 0:936f1c020120 157 {
GuiTwo 0:936f1c020120 158 if (buttonDepressedTime_us >=
GuiTwo 0:936f1c020120 159 timespec->longReleaseDelay_us)
GuiTwo 0:936f1c020120 160 {
GuiTwo 0:936f1c020120 161 buttonEvent.action = MenbedButtonEvent::BUTTON_ACTION_RELEASED_LONG;
GuiTwo 0:936f1c020120 162 navigator->handleButtonEvent (buttonEvent);
GuiTwo 0:936f1c020120 163 }
GuiTwo 0:936f1c020120 164 else
GuiTwo 0:936f1c020120 165 {
GuiTwo 0:936f1c020120 166 buttonEvent.action = MenbedButtonEvent::BUTTON_ACTION_RELEASED_SHORT;
GuiTwo 0:936f1c020120 167 navigator->handleButtonEvent (buttonEvent);
GuiTwo 0:936f1c020120 168 }
GuiTwo 0:936f1c020120 169 }
GuiTwo 0:936f1c020120 170
GuiTwo 0:936f1c020120 171 buttonAlreadyDepressed[i] = false;
GuiTwo 0:936f1c020120 172 }
GuiTwo 0:936f1c020120 173 }
GuiTwo 0:936f1c020120 174 }
GuiTwo 0:936f1c020120 175
GuiTwo 0:936f1c020120 176
GuiTwo 0:936f1c020120 177 bool MenbedButtonHandler::isButtonDepressed (MenbedButtonEvent::ButtonName name)
GuiTwo 0:936f1c020120 178 {
GuiTwo 0:936f1c020120 179 switch (name)
GuiTwo 0:936f1c020120 180 {
GuiTwo 0:936f1c020120 181 case MenbedButtonEvent::ButtonSelect:
GuiTwo 0:936f1c020120 182 return *select;
GuiTwo 0:936f1c020120 183 case MenbedButtonEvent::ButtonDown:
GuiTwo 0:936f1c020120 184 if (numButtons >= 2)
GuiTwo 0:936f1c020120 185 return *down;
GuiTwo 0:936f1c020120 186 else
GuiTwo 0:936f1c020120 187 return false;
GuiTwo 0:936f1c020120 188 case MenbedButtonEvent::ButtonUp:
GuiTwo 0:936f1c020120 189 if (numButtons >= 3)
GuiTwo 0:936f1c020120 190 return *up;
GuiTwo 0:936f1c020120 191 else
GuiTwo 0:936f1c020120 192 return false;
GuiTwo 0:936f1c020120 193 case MenbedButtonEvent::ButtonCancel:
GuiTwo 0:936f1c020120 194 if (numButtons == 4)
GuiTwo 0:936f1c020120 195 return *cancel;
GuiTwo 0:936f1c020120 196 else
GuiTwo 0:936f1c020120 197 return false;
GuiTwo 0:936f1c020120 198 }
GuiTwo 0:936f1c020120 199
GuiTwo 0:936f1c020120 200 return false;
GuiTwo 0:936f1c020120 201 }