Skip to content

Commit 4ee29f4

Browse files
committed
Use rtcMillis everywhere
1 parent 67a95a3 commit 4ee29f4

File tree

5 files changed

+28
-18
lines changed

5 files changed

+28
-18
lines changed

Firmware/OpenLog_Artemis/OpenLog_Artemis.ino

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,18 @@
110110
the SPI lines low, preventing communication with the IMU: https://github.com/sparkfun/OpenLog_Artemis/issues/104
111111
112112
v2.2:
113-
Use Apollo3 v2.2.0 with changes by paulvha to fix Issue 117 (Thank you Paul!)
113+
Use Apollo3 v2.1.0 with changes by paulvha to fix Issue 117 (Thank you Paul!)
114114
https://github.com/sparkfun/OpenLog_Artemis/issues/117#issuecomment-1034973065
115+
https://github.com/sparkfun/Arduino_Apollo3/issues/279#issuecomment-710060977
115116
Also includes Paul's SPI.end fix
116117
https://github.com/sparkfun/Arduino_Apollo3/issues/442
118+
In libraries/SPI/src/SPI.cpp change end() to:
119+
void arduino::MbedSPI::end() {
120+
if (dev) {
121+
delete dev;
122+
dev = NULL;
123+
}
124+
}
117125
Use SdFat v2.1.2
118126
Compensate for missing / not-populated IMU
119127
Add support for yyyy/mm/dd and ISO 8601 date style (Issue 118)
@@ -486,7 +494,7 @@ void setup() {
486494

487495
//If we are sleeping between readings then we cannot rely on millis() as it is powered down
488496
//Use RTC instead
489-
measurementStartTime = bestMillis();
497+
measurementStartTime = rtcMillis();
490498

491499
digitalWrite(PIN_STAT_LED, LOW); // Turn the STAT LED off now that everything is configured
492500

@@ -553,12 +561,12 @@ void loop() {
553561

554562
//If we are sleeping between readings then we cannot rely on millis() as it is powered down
555563
//Use RTC instead
556-
lastSeriaLogSyncTime = bestMillis(); //Reset the last sync time to now
564+
lastSeriaLogSyncTime = rtcMillis(); //Reset the last sync time to now
557565
newSerialData = true;
558566
}
559567
else if (newSerialData == true)
560568
{
561-
if ((bestMillis() - lastSeriaLogSyncTime) > MAX_IDLE_TIME_MSEC) //If we haven't received any characters recently then sync log file
569+
if ((rtcMillis() - lastSeriaLogSyncTime) > MAX_IDLE_TIME_MSEC) //If we haven't received any characters recently then sync log file
562570
{
563571
if (incomingBufferSpot > 0)
564572
{
@@ -574,7 +582,7 @@ void loop() {
574582
}
575583

576584
newSerialData = false;
577-
lastSeriaLogSyncTime = bestMillis(); //Reset the last sync time to now
585+
lastSeriaLogSyncTime = rtcMillis(); //Reset the last sync time to now
578586
printDebug("Total chars received: " + (String)charsReceived + "\r\n");
579587
}
580588
}
@@ -666,9 +674,9 @@ void loop() {
666674
}
667675

668676
//Force sync every 500ms
669-
if (bestMillis() - lastDataLogSyncTime > 500)
677+
if (rtcMillis() - lastDataLogSyncTime > 500)
670678
{
671-
lastDataLogSyncTime = bestMillis();
679+
lastDataLogSyncTime = rtcMillis();
672680
sensorDataFile.sync();
673681
if (settings.frequentFileAccessTimestamps == true)
674682
updateDataFileAccess(&sensorDataFile); // Update the file access time & date
@@ -725,7 +733,7 @@ void loop() {
725733
{
726734
// Check if we have been awake long enough (millis is reset to zero when waking from sleep)
727735
// goToSleep will automatically compensate for how long we have been awake
728-
if ((bestMillis() - lastAwakeTimeMillis) < settings.minimumAwakeTimeMillis)
736+
if ((rtcMillis() - lastAwakeTimeMillis) < settings.minimumAwakeTimeMillis)
729737
return; // Too early to sleep - leave sleepAfterRead set true
730738
}
731739

Firmware/OpenLog_Artemis/Sensors.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ void getData()
188188

189189
//If we are sleeping between readings then we cannot rely on millis() as it is powered down
190190
//Use RTC instead
191-
currentMillis = bestMillis();
191+
currentMillis = rtcMillis();
192192
float actualRate;
193193
if ((currentMillis - measurementStartTime) < 1) // Avoid divide by zero
194194
actualRate = 0.0;

Firmware/OpenLog_Artemis/lowerPower.ino

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -562,11 +562,13 @@ void waitForQwiicBusPowerDelay() // Wait while the qwiic devices power up
562562
//Depending on what hardware is configured, the Qwiic bus may have only been turned on a few ms ago
563563
//Give sensors, specifically those with a low I2C address, time to turn on
564564
// If we're not using the SD card, everything will have happened much quicker than usual.
565-
uint64_t qwiicPowerHasBeenOnFor = bestMillis() - qwiicPowerOnTime;
566-
if (qwiicPowerHasBeenOnFor < qwiicPowerOnDelayMillis)
565+
uint64_t qwiicPowerHasBeenOnFor = rtcMillis() - qwiicPowerOnTime;
566+
printDebug("waitForQwiicBusPowerDelay: qwiicPowerHasBeenOnFor " + (String)((unsigned long)qwiicPowerHasBeenOnFor) + "ms\r\n");
567+
if (qwiicPowerHasBeenOnFor < (uint64_t)qwiicPowerOnDelayMillis)
567568
{
568-
unsigned long delayFor = qwiicPowerOnDelayMillis - qwiicPowerHasBeenOnFor;
569-
for (unsigned long i = 0; i < delayFor; i++)
569+
uint64_t delayFor = (uint64_t)qwiicPowerOnDelayMillis - qwiicPowerHasBeenOnFor;
570+
printDebug("waitForQwiicBusPowerDelay: delaying for " + (String)((unsigned long)delayFor) + "\r\n");
571+
for (uint64_t i = 0; i < delayFor; i++)
570572
{
571573
checkBattery();
572574
delay(1);
@@ -584,7 +586,7 @@ void qwiicPowerOn()
584586
digitalWrite(PIN_QWIIC_POWER, HIGH);
585587
#endif
586588

587-
qwiicPowerOnTime = bestMillis(); //Record this time so we wait enough time before detecting certain sensors
589+
qwiicPowerOnTime = rtcMillis(); //Record this time so we wait enough time before detecting certain sensors
588590
}
589591
void qwiicPowerOff()
590592
{

Firmware/OpenLog_Artemis/menuMain.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ void menuMain()
176176
totalCharactersPrinted = 0;
177177
//If we are sleeping between readings then we cannot rely on millis() as it is powered down
178178
//Use RTC instead
179-
measurementStartTime = bestMillis();
179+
measurementStartTime = rtcMillis();
180180

181181
//Edge case: after 10Hz reading, user sets the log rate above 2s mark. We never go to sleep because
182182
//takeReading is not true. And since we don't wake up, takeReading never gets set to true.

Firmware/OpenLog_Artemis/support.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ uint8_t getByteChoice(int numberOfSeconds, bool updateDZSERIAL)
9090
if (settings.useTxRxPinsForTerminal == true)
9191
while (Serial1.available() > 0) Serial1.read(); //Clear buffer
9292

93-
long startTime = millis();
93+
unsigned long startTime = millis();
9494
byte incoming;
9595
while (1)
9696
{
@@ -160,7 +160,7 @@ int64_t getNumber(int numberOfSeconds)
160160
//Get input from user
161161
char cleansed[20]; //Good for very large numbers: 123,456,789,012,345,678\0
162162

163-
long startTime = millis();
163+
unsigned long startTime = millis();
164164
int spot = 0;
165165
while (spot < 20 - 1) //Leave room for terminating \0
166166
{
@@ -265,7 +265,7 @@ double getDouble(int numberOfSeconds)
265265
//Get input from user
266266
char cleansed[20]; //Good for very large numbers: 123,456,789,012,345,678\0
267267

268-
long startTime = millis();
268+
unsigned long startTime = millis();
269269
int spot = 0;
270270
bool dpSeen = false;
271271
while (spot < 20 - 1) //Leave room for terminating \0

0 commit comments

Comments
 (0)