Skip to content

Commit e83896e

Browse files
committed
Add Ticker task for BT LED.
1 parent da552c9 commit e83896e

File tree

2 files changed

+51
-21
lines changed

2 files changed

+51
-21
lines changed

Firmware/RTK_Surveyor/RTK_Surveyor.ino

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
Enable various debug outputs sent over BT
3333
3434
when user exits wifi mode, turn BT back on
35-
35+
3636
*/
3737

3838
const int FIRMWARE_VERSION_MAJOR = 1;
@@ -130,9 +130,9 @@ SFE_UBLOX_GPS_ADD myGPS;
130130
//don't prevent operation if firmware is mismatched.
131131
char latestZEDFirmware[] = "FWVER=HPG 1.13";
132132

133-
//Used for config ZED for things not supported in library: getPortSettings, getSerialRate, getNMEASettings, getRTCMSettings
133+
//Used for config ZED for things not supported in library: getPortSettings, getSerialRate, getNMEASettings, getRTCMSettings
134134
//This array holds the payload data bytes. Global so that we can use between config functions.
135-
uint8_t settingPayload[MAX_PAYLOAD_SIZE];
135+
uint8_t settingPayload[MAX_PAYLOAD_SIZE];
136136
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
137137

138138
//Battery fuel gauge and PWM LEDs
@@ -145,6 +145,10 @@ const int freq = 5000;
145145
const int ledRedChannel = 0;
146146
const int ledGreenChannel = 1;
147147
const int resolution = 8;
148+
149+
int battLevel = 0; //SOC measured from fuel gauge, in %. Used in multiple places (display, serial debug, log)
150+
float battVoltage = 0.0;
151+
float battChangeRate = 0.0;
148152
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
149153

150154
//Hardware serial and BT buffers
@@ -188,7 +192,6 @@ uint8_t unitMACAddress[6]; //Use MAC address in BT broadcast and display
188192
char deviceName[20]; //The serial string that is broadcast. Ex: 'Surveyor Base-BC61'
189193
const byte menuTimeout = 15; //Menus will exit/timeout after this number of seconds
190194
bool inTestMode = false; //Used to re-route BT traffic while in test sub menu
191-
int battLevel = 0; //SOC measured from fuel gauge, in %
192195
long systemTime_minutes = 0; //Used to test if logging is less than max minutes
193196

194197
uint32_t lastBluetoothLEDBlink = 0;
@@ -200,6 +203,20 @@ uint32_t lastDisplayUpdate = 0;
200203
uint32_t lastTime = 0;
201204
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
202205

206+
//Low frequency tasks
207+
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
208+
#include <Ticker.h>
209+
210+
SemaphoreHandle_t xI2CSemaphore;
211+
TickType_t i2cSemaphore_maxWait = 5;
212+
213+
Ticker btLEDTask;
214+
float btLEDTaskPace = 0.5; //Seconds
215+
216+
//Ticker battCheckTask;
217+
//float battCheckTaskPace = 2.0; //Seconds
218+
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
219+
203220
void setup()
204221
{
205222
Serial.begin(115200); //UART0 for programming and debugging
@@ -245,25 +262,23 @@ void setup()
245262

246263
if (online.microSD == true && settings.zedOutputLogging == true) startLogTime_minutes = 0; //Mark now as start of logging
247264

265+
if (xI2CSemaphore == NULL)
266+
{
267+
xI2CSemaphore = xSemaphoreCreateMutex();
268+
if (xI2CSemaphore != NULL)
269+
xSemaphoreGive(xI2CSemaphore); //Make the I2C hardware available for use
270+
}
271+
272+
//Start tasks
273+
btLEDTask.attach(btLEDTaskPace, updateBTled); //Rate in seconds, callback
274+
//battCheckTask.attach(battCheckTaskPace, checkBatteryLevels);
275+
248276
//myGPS.enableDebugging(); //Enable debug messages over Serial (default)
249277
}
250278

251279
void loop()
252280
{
253281
myGPS.checkUblox(); //Regularly poll to get latest data and any RTCM
254-
255-
//Update Bluetooth LED status
256-
if (radioState == BT_ON_NOCONNECTION)
257-
{
258-
if (millis() - lastBluetoothLEDBlink > 500)
259-
{
260-
if (digitalRead(bluetoothStatusLED) == LOW)
261-
digitalWrite(bluetoothStatusLED, HIGH);
262-
else
263-
digitalWrite(bluetoothStatusLED, LOW);
264-
lastBluetoothLEDBlink = millis();
265-
}
266-
}
267282

268283
//Check rover switch and configure module accordingly
269284
//When switch is set to '1' = BASE, pin will be shorted to ground
@@ -273,7 +288,8 @@ void loop()
273288
Serial.println(F("Rover Mode"));
274289

275290
baseState = BASE_OFF;
276-
startBluetooth(); //Restart Bluetooth with new name
291+
292+
startBluetooth(); //Restart Bluetooth with 'Rover' name
277293

278294
//If we are survey'd in, but switch is rover then disable survey
279295
if (configureUbloxModuleRover() == false)
@@ -293,8 +309,10 @@ void loop()
293309
Serial.println(F("Base config failed!"));
294310
}
295311

296-
startBluetooth(); //Restart Bluetooth with new name
297-
312+
//Restart Bluetooth with 'Base' name
313+
//We start BT regardless of Ntrip Server in case user wants to transmit survey-in stats over BT
314+
startBluetooth();
315+
298316
baseState = BASE_SURVEYING_IN_NOTSTARTED; //Switch to new state
299317
}
300318

@@ -304,7 +322,7 @@ void loop()
304322
}
305323
else if (baseState == BASE_TRANSMITTING)
306324
{
307-
if(settings.enableNtripServer == true)
325+
if (settings.enableNtripServer == true)
308326
{
309327
updateNtripServer();
310328
}

Firmware/RTK_Surveyor/tasks.ino

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//These are all the low frequency tasks that are called by Ticker
2+
3+
//Control BT status LED according to bluetoothState
4+
void updateBTled()
5+
{
6+
if (radioState == BT_ON_NOCONNECTION)
7+
digitalWrite(bluetoothStatusLED, !digitalRead(bluetoothStatusLED));
8+
else if (radioState == BT_CONNECTED)
9+
digitalWrite(bluetoothStatusLED, HIGH);
10+
else
11+
digitalWrite(bluetoothStatusLED, LOW);
12+
}

0 commit comments

Comments
 (0)