-
Notifications
You must be signed in to change notification settings - Fork 0
/
recording.cpp
113 lines (97 loc) · 3.12 KB
/
recording.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "uni_display.h"
#include "uni_keypad.h"
#include "uni_sd.h"
#include "recording.h"
#include "uni_config.h"
extern UniDisplay display;
extern UniKeypad keypad;
extern UniSd sd;
extern UniConfig config;
int _racer_number = 0;
TimeResult recentResult[RECENT_RESULT_COUNT];
int recentRacer[RECENT_RESULT_COUNT];
// Add a new digit to the current racer number
void store_racer_number() {
Serial.println("Storing Racer number");
char last_key_pressed = keypad.lastKeyPressed();
_racer_number = (_racer_number * 10) + keypad.intFromChar(last_key_pressed);
Serial.print("Racer #: ");
Serial.println(_racer_number);
display.showNumber(_racer_number);
}
// Methods
void clear_racer_number() {
_racer_number = 0;
display.clear();
log("Clear Racer Number");
}
int racer_number() {
return _racer_number;
}
// Is the racer number already maximum-digits long?
// if so, another digit will be "too long"
bool maximum_digits_racer_number() {
if (config.get_bib_number_length() == 3) {
return racer_number() > 99;
} else {
return racer_number() > 999;
}
}
// **((((((((( NEW FILE )))))))))))))))))
bool print_racer_data_to_sd(int racer_number, TimeResult data, bool fault) {
#define FILENAME_LENGTH 35
char filename[FILENAME_LENGTH];
char full_string[FILENAME_LENGTH];
char data_string[FILENAME_LENGTH];
snprintf(data_string, FILENAME_LENGTH, "%02d,%02d,%03d", (data.hour * 60) + data.minute, data.second, data.millisecond);
Serial.println("data_string");
Serial.println(data_string);
Serial.println("racer_number");
Serial.println(racer_number);
if (fault) {
snprintf(full_string, FILENAME_LENGTH, "%d,,%s,1", racer_number, data_string);
} else {
snprintf(full_string, FILENAME_LENGTH, "%d,,%s,0", racer_number, data_string);
}
log(full_string);
// Store result for review on the system as desired
for (int i = RECENT_RESULT_COUNT; i > 0; i--) {
// copy result 8 to result 9,
// copy result 7 to result 8, etc.
memcpy(&recentResult[i], &recentResult[i - 1], sizeof(TimeResult));
recentRacer[i] = recentRacer[i - 1];
}
// store result in slot 0
memcpy(&recentResult[0], &data, sizeof(TimeResult));
recentRacer[0] = racer_number;
strncpy(filename, config.filename(), FILENAME_LENGTH);
if (sd.writeFile(filename, full_string)) {
return true;
} else {
// Error writing to SD
Serial.println("Error writing to SD");
display.sd();
return false;
}
}
void print_data_to_log(TimeResult data, bool fault) {
#define FILENAME_LENGTH 35
char data_string[FILENAME_LENGTH];
snprintf(data_string, FILENAME_LENGTH, "sensor: %2d,%02d,%02d,%03d,%d", data.hour, data.minute, data.second, data.millisecond, fault);
log(data_string);
}
void clear_previous_entry() {
#define MAX_FILENAME 35
#define MAX_MESSAGE 20
char filename[MAX_FILENAME];
char message[MAX_MESSAGE];
strncpy(filename, config.filename(), MAX_FILENAME);
snprintf(message, MAX_MESSAGE, "CLEAR_PREVIOUS");
Serial.println("Clear previous entry");
sd.writeFile(filename, message);
log("Clear Previous entry");
}
#define LOG_FILE "log.txt"
void log(char *message) {
sd.writeFile(LOG_FILE, message);
}