-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathOpenLapTimer.ino
98 lines (83 loc) · 2.42 KB
/
OpenLapTimer.ino
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
/* Open LapTimer */
#include <ILI_SdSpi.h>
#include <ILI_SdFatConfig.h>
#include <ILI9341_due_gText.h>
#include <ILI9341_due.h>
#include <SdFat.h>
#include <TouchScreen.h>
#include <Adafruit_GPS.h>
#include <ArduinoJson.h>
#include "Chrono.h"
// TFT SPI pin
#define TFT_RST 8
#define TFT_DC 9
#define TFT_CS 10
// Touchscreen pin
#define YP A2 // must be an analog pin, use "An" notation!
#define XM A3 // must be an analog pin, use "An" notation!
#define YM 5 // can be a digital pin
#define XP 6 // can be a digital pin
// Touchscreen X+ / X- resistance (for better pressure precision)
#define TOUCH_XP_XM_OHM 300
// Button to simulate the new lap
#define FINISH_LINE_BUTTON 2
int prevTestButtonState = 0;
// SD-Card
#define SD_CS 7
// GPS
#define gpsSerial Serial1
ILI9341_due* tft = new ILI9341_due(TFT_CS, TFT_DC, TFT_RST);
TouchScreen* touchScreen = new TouchScreen(XP, YP, XM, YM, TOUCH_XP_XM_OHM);
SdFat* sd;
Adafruit_GPS* gps = new Adafruit_GPS(&gpsSerial);
Chrono* chrono;
/*
long loopLenghtTimestamp;
long loopLenghtMax;
long loopCount;
*/
void setup() {
Serial.begin(115200);
Serial.println("START SETUP Open LapTimer!");
pinMode(FINISH_LINE_BUTTON, INPUT);
// SD-Card - initialize it before Chrono
sd = new SdFat();
if(sd->begin(SD_CS, SPI_HALF_SPEED)) {
Serial.println("SD-Card initialized OK");
} else {
sd = NULL;
Serial.println("SD-Card NOT initialized");
}
Serial.println("Chrono setup");
chrono = new Chrono(tft, gps, &gpsSerial);
chrono->setLogSdCard(sd);
chrono->setTouchScreen(touchScreen);
Serial.println("Chrono setup finish");
Serial.println("FINE SETUP LapTimer!");
}
void loop(void) {
/*
loopCount ++;
long loopLenght = millis() - loopLenghtTimestamp;
loopLenghtTimestamp = millis();
if(loopLenght > loopLenghtMax) {
loopLenghtMax = loopLenght;
}
long average = (millis() / loopCount);
Serial.print(loopLenght); Serial.print(" - ");
Serial.print(average); Serial.print(" - "); Serial.println(loopLenghtMax);
*/
// test button state
/*
int currentTestButtonState = LOW; //digitalRead(FINISH_LINE_BUTTON);
//Serial.println(currentTestButtonState);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (currentTestButtonState == HIGH && prevTestButtonState == LOW) {
Serial.print("ButtonTest Pressed");
chrono->simulateNewLap = true;
}
prevTestButtonState = currentTestButtonState;
*/
chrono->loopChrono();
}