-
Notifications
You must be signed in to change notification settings - Fork 0
/
DisplayDistance.cpp
58 lines (46 loc) · 1.47 KB
/
DisplayDistance.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
53
54
55
56
57
58
/*
* DisplayDistance.cpp
*
* Created on: Feb 5, 2013
* Author: dam7633
*/
#include "DisplayDistance.h"
#include "SetCircumference.h"
#include "DisplayTime.h"
#include "NormalOperation.h"
#include "PulseScanner.h"
#include "CyclometerController.h"
#include <math.h>
DisplayDistance::DisplayDistance(StateParent* parent, StateContext* context) :
State(parent, context) {}
void DisplayDistance::accept(Event event) {
if (event == evSetDepressed) {
StateParent* context_parent = ((State*)parent)->getParent();
context_parent->doTransition(new SetCircumference(context_parent, context), NULL);
} else if (event == evModeDepressed) {
parent->doTransition(new DisplayTime(parent, context), NULL);
}
}
DisplayInfo DisplayDistance::getData() {
DisplayInfo info;
// Clear the display.
for (int i = 0; i < NUM_DIGITS; i++) {
info.val[i] = BLANK_DIGIT;
info.dp[i] = false;
}
// Always display the decimal point.
info.dp[1] = true;
// The get the distance number.
double distance = ((CyclometerController*)context)->getPulseScanner()->distance();
// Round the distance to the nearest tenth.
distance = round(distance * 10.0f) / 10.0f;
info.val[0] = lround(distance * 10.0f) % 10; // Tenths
info.val[1] = (int)distance % 10; // Ones
if (distance >= 10) {
info.val[2] = (int)(distance / 10) % 10; // Tens
if (distance >= 100) {
info.val[3] = (int)(distance / 100) % 10; // Hundreds
}
}
return info;
}