-
Notifications
You must be signed in to change notification settings - Fork 0
/
SetCircumference.cpp
52 lines (44 loc) · 1.5 KB
/
SetCircumference.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
46
47
48
49
50
51
52
/*
* SetCircumference.cpp
*
* Created on: Feb 5, 2013
* Author: dam7633
*/
#include "SetCircumference.h"
#include "SetCircumferenceIdle.h"
#include "NormalOperation.h"
#include "CyclometerController.h"
static void finishInitialization(StateContext* context) {
((CyclometerController*)context)->setFullResetDone(true);
}
SetCircumference::SetCircumference(StateParent* parent, StateContext* context) :
State(parent, context) {
childState = new SetCircumferenceIdle(this, context);
}
void SetCircumference::accept(Event event) {
if (event == evSetDepressed) {
((CyclometerController*)context)->getPulseScanner()->setCircumference();
if (((CyclometerController*)context)->getIsFullResetDone()) {
parent->doTransition(new NormalOperation(parent, context, kDisplayDistanceState), NULL);
} else {
parent->doTransition(new NormalOperation(parent, context, NULL), finishInitialization);
}
} else if (event == evFullReset) {
parent->doTransition(new Initialize(parent, context), NULL);
} else {
childState->accept(event);
}
}
DisplayInfo SetCircumference::getData() {
DisplayInfo info;
// Clear the display info.
for (int i = 0; i < NUM_DIGITS; i++) {
info.dp[i] = false;
}
// Display 1 for kilometers, 2 for miles.
int circumference = ((CyclometerController*)context)->getPulseScanner()->getCircumference();
info.val[0] = circumference % 10;
info.val[1] = (circumference % 100) / 10;
info.val[2] = circumference / 100;
return info;
}