-
Notifications
You must be signed in to change notification settings - Fork 0
/
SetUnits.cpp
45 lines (37 loc) · 1.2 KB
/
SetUnits.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
* SetUnits.cpp
*
* Created on: Feb 5, 2013
* Author: dam7633
*/
#include "SetUnits.h"
#include "SetCircumference.h"
#include "CyclometerController.h"
#include "PulseScanner.h"
static void toggleUnits(StateContext* context) {
((CyclometerController*)context)->getPulseScanner()->toggleUnits();
}
SetUnits::SetUnits(StateParent* parent, StateContext* context) :
State(parent, context) {}
void SetUnits::accept(Event event) {
//make the transition to the proper state when specific events occur
if (event == evModeDepressed) {
parent->doTransition(new SetUnits(parent, context), toggleUnits);
} else if (event == evSetDepressed) {
parent->doTransition(new SetCircumference(parent, context), NULL);
} else if (event == evFullReset) {
parent->doTransition(new Initialize(parent, context), NULL);
}
}
DisplayInfo SetUnits::getData() {
DisplayInfo info;
// Clear the display info.
for (int i = 0; i < NUM_DIGITS; i++) {
info.val[i] = BLANK_DIGIT;
info.dp[i] = false;
}
// Display 1 for kilometers, 2 for miles.
DistanceUnit units = ((CyclometerController*)context)->getPulseScanner()->getUnits();
info.val[0] = (units == KM) ? 1 : 2;
return info;
}