Skip to content

Commit 518d19e

Browse files
committed
Introduce SimRa & Bluetooth as options
1 parent 55823fd commit 518d19e

File tree

4 files changed

+60
-42
lines changed

4 files changed

+60
-42
lines changed

OpenBikeSensorFirmware/OpenBikeSensorFirmware.ino

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ SSD1306DisplayDevice* displayTest;
4444

4545
HCSR04SensorManager* sensorManager;
4646

47-
#ifdef BLUETOOTH_ACTIVATED
4847
BluetoothManager* bluetoothManager;
49-
#endif
5048

5149
String esp_chipid;
5250

@@ -169,20 +167,16 @@ void setup() {
169167
//##############################################################
170168

171169
// Counter, how often the SD card will be read before writing an error on the display
172-
int8_t sdCount = 25;
170+
int8_t sdCount = 5;
173171

174172
displayTest->showTextOnGrid(2, 2, "SD...");
175-
boolean requiresSdCardMount = true;
176-
#ifdef RADMESSER_S_COMPATIBILITY_MODE
177-
requiresSdCardMount = false;
178-
#endif
179173
while (!SD.begin())
180174
{
181175
if(sdCount > 0) {
182176
sdCount--;
183177
} else {
184178
displayTest->showTextOnGrid(2, 2, "SD... error");
185-
if (!requiresSdCardMount) {
179+
if (config.simRaMode || digitalRead(PushButton) == HIGH) {
186180
break;
187181
}
188182
}
@@ -201,12 +195,7 @@ void setup() {
201195
//##############################################################
202196

203197
buttonState = digitalRead(PushButton);
204-
205-
bool requiresDisplayConnection = true;
206-
#ifdef RADMESSER_S_COMPATIBILITY_MODE
207-
requiresDisplayConnection = false;
208-
#endif
209-
if (buttonState == HIGH || (requiresDisplayConnection && displayError != 0))
198+
if (buttonState == HIGH || (!config.simRaMode && displayError != 0))
210199
{
211200
displayTest->showTextOnGrid(2, 2, "Start Server");
212201
esp_bt_mem_release(ESP_BT_MODE_BTDM); // no bluetooth at all here.
@@ -253,12 +242,15 @@ void setup() {
253242

254243
displayTest->showTextOnGrid(2, 3, "CSV file...");
255244

256-
writer = new CSVFileWriter;
257-
writer->setFileName();
258-
writer->writeHeader();
259-
Serial.println("File initialised");
260-
261-
displayTest->showTextOnGrid(2, 3, "CSV file... ok");
245+
if (SD.begin()) {
246+
writer = new CSVFileWriter;
247+
writer->setFileName();
248+
writer->writeHeader();
249+
displayTest->showTextOnGrid(2, 3, "CSV file... ok");
250+
Serial.println("File initialised");
251+
} else {
252+
displayTest->showTextOnGrid(2, 3, "CSV file... skip");
253+
}
262254

263255
//##############################################################
264256
// GPS
@@ -267,10 +259,8 @@ void setup() {
267259
displayTest->showTextOnGrid(2, 4, "Wait for GPS");
268260
Serial.println("Waiting for GPS fix...");
269261
bool validGPSData = false;
270-
bool requiresGpsConnection = true;
271-
#ifdef RADMESSER_S_COMPATIBILITY_MODE
272-
requiresGpsConnection = false;
273-
#endif
262+
readGPSData();
263+
delay(300);
274264
while (!validGPSData)
275265
{
276266
Serial.println("readGPSData()");
@@ -314,7 +304,9 @@ void setup() {
314304
displayTest->showTextOnGrid(2, 5, satellitesString);
315305

316306
buttonState = digitalRead(PushButton);
317-
if (buttonState == HIGH)
307+
if (buttonState == HIGH
308+
|| (config.simRaMode && gps.passedChecksum() == 0) // no module && simRaMode
309+
)
318310
{
319311
Serial.println("Skipped get GPS...");
320312
displayTest->showTextOnGrid(2, 5, "...skipped");
@@ -331,10 +323,12 @@ void setup() {
331323
//##############################################################
332324
// Bluetooth
333325
//##############################################################
334-
#ifdef BLUETOOTH_ACTIVATED
335-
bluetoothManager->init();
336-
bluetoothManager->activateBluetooth();
337-
#endif
326+
if (config.bluetooth) {
327+
bluetoothManager->init();
328+
bluetoothManager->activateBluetooth();
329+
} else {
330+
esp_bt_mem_release(ESP_BT_MODE_BTDM); // no bluetooth at all here.
331+
}
338332

339333
delay(1000); // Added for user experience
340334

@@ -388,21 +382,21 @@ void loop() {
388382
lastMeasurements
389383
);
390384

391-
#ifdef BLUETOOTH_ACTIVATED
392-
auto leftValues = std::list<uint16_t>();
393-
auto rightValues = std::list<uint16_t>();
385+
if (config.bluetooth) {
386+
auto leftValues = std::list<uint16_t>();
387+
auto rightValues = std::list<uint16_t>();
394388

395-
if (sensorManager->m_sensors[1].rawDistance < MAX_SENSOR_VALUE) {
396-
leftValues.push_back(sensorManager->m_sensors[1].rawDistance);
397-
}
398-
if (sensorManager->m_sensors[0].rawDistance < MAX_SENSOR_VALUE) {
399-
rightValues.push_back(sensorManager->m_sensors[0].rawDistance);
400-
}
401-
if (measurements == 0 || !leftValues.empty() || !rightValues.empty()) {
402-
bluetoothManager->newSensorValues(leftValues, rightValues);
389+
if (sensorManager->m_sensors[1].rawDistance < MAX_SENSOR_VALUE) {
390+
leftValues.push_back(sensorManager->m_sensors[1].rawDistance);
391+
}
392+
if (sensorManager->m_sensors[0].rawDistance < MAX_SENSOR_VALUE) {
393+
rightValues.push_back(sensorManager->m_sensors[0].rawDistance);
394+
}
395+
if (measurements == 0 || !leftValues.empty() || !rightValues.empty()) {
396+
bluetoothManager->newSensorValues(leftValues, rightValues);
397+
}
398+
bluetoothManager->processButtonState(digitalRead(PushButton));
403399
}
404-
bluetoothManager->processButtonState(digitalRead(PushButton));
405-
#endif
406400

407401
// #######################################################
408402
// Storage

OpenBikeSensorFirmware/config.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ void jsonDocumentToConfig(DynamicJsonDocument &doc, Config &config)
6363
config.privacyConfig = doc["privacyConfig"] | AbsolutePrivacy;
6464

6565
config.numPrivacyAreas = doc["numPrivacyAreas"] | 0;
66+
config.bluetooth = doc["bluetooth"] | false;
67+
config.simRaMode = doc["simRaMode"] | false;
6668
#ifdef DEVELOP
6769
config.devConfig = doc["devConfig"] | 0;
6870
#endif
@@ -130,6 +132,9 @@ DynamicJsonDocument configToJsonDocument(const Config &config) {
130132
doc["GPSConfig"] = config.GPSConfig;
131133
doc["confirmationTimeWindow"] = config.confirmationTimeWindow;
132134
doc["privacyConfig"] = config.privacyConfig;
135+
doc["bluetooth"] = config.bluetooth;
136+
doc["simRaMode"] = config.simRaMode;
137+
133138
#ifdef DEVELOP
134139
doc["devConfig"] = config.devConfig;
135140
#endif
@@ -264,6 +269,12 @@ void printConfig(Config &config) {
264269
Serial.print(F("SSID = "));
265270
Serial.println(String(config.ssid));
266271

272+
Serial.print(F("bluetooth = "));
273+
Serial.println(String(config.bluetooth));
274+
275+
Serial.print(F("simRaMode = "));
276+
Serial.println(String(config.simRaMode));
277+
267278
#ifdef DEVELOP
268279
if(config.devConfig & PrintWifiPassword) {
269280
Serial.print(F("password = "));

OpenBikeSensorFirmware/config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ struct Config {
6969
char hostname[64];
7070
char obsUserID[64];
7171
int displayConfig;
72+
boolean bluetooth;
73+
boolean simRaMode;
7274
#ifdef DEVELOP
7375
int devConfig;
7476
#endif

OpenBikeSensorFirmware/configServer.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,10 @@ String configIndex =
288288
"<input name='hostname' placeholder='hostname' value='{hostname}'>"
289289
"<hr>"
290290
"<input name='obsUserID' placeholder='API ID' value='{userId}' >"
291+
"<h3>Operation</h3>"
292+
"Enable Bluetooth <input type='checkbox' name='bluetooth' {bluetooth}>"
293+
"<hr>"
294+
"SimRa Mode <input type='checkbox' name='simRaMode' {simRaMode}>"
291295
"<input type=submit class=btn value=Save>"
292296
+ footer;
293297

@@ -374,6 +378,8 @@ void configAction() {
374378
String displayFlip = server.arg("displayFlip") == "on" ? "on" : "off";
375379
String displayNumConfirmed = server.arg("displayNumConfirmed") == "on" ? "on" : "off";
376380
String displayDistanceDetail = server.arg("displayDistanceDetail") == "on" ? "on" : "off";
381+
String bluetooth = server.arg("bluetooth") == "on" ? "on" : "off";
382+
String simRaMode = server.arg("simRaMode") == "on" ? "on" : "off";
377383

378384
String validGPS = server.arg("validGPS");
379385

@@ -438,6 +444,9 @@ void configAction() {
438444
else
439445
config.displayConfig &= ~DisplayDistanceDetail;
440446

447+
config.bluetooth = (bluetooth == "on");
448+
config.simRaMode = (simRaMode == "on");
449+
441450
if (validGPS == "validLocation")
442451
config.GPSConfig = ValidLocation;
443452

@@ -864,6 +873,8 @@ void startServer() {
864873
html.replace("{displayFlip}", displayFlip ? "checked" : "");
865874
html.replace("{displayNumConfirmed}", displayNumConfirmed ? "checked" : "");
866875
html.replace("{displayDistanceDetail}", displayDistanceDetail ? "checked" : "");
876+
html.replace("{bluetooth}", config.bluetooth ? "checked" : "");
877+
html.replace("{simRaMode}", config.simRaMode ? "checked" : "");
867878

868879
bool validLocation = config.GPSConfig & ValidLocation;
869880
bool validTime = config.GPSConfig & ValidTime;

0 commit comments

Comments
 (0)