Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions content/wardrive.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,11 +553,10 @@ async function sendPing(manual = false) {

// Set status to idle after map update
if (state.connection) {
// If in auto mode, start countdown. Otherwise, set to idle
// If in auto mode, schedule next ping. Otherwise, set to idle
if (state.running) {
// Restart the countdown for next auto ping
const intervalMs = getSelectedIntervalMs();
startAutoCountdown(intervalMs);
// Schedule the next auto ping with countdown
scheduleNextAutoPing();
} else {
setStatus("Idle", "text-slate-300");
}
Expand Down Expand Up @@ -596,7 +595,7 @@ function stopAutoPing(stopGps = false) {
}

if (state.autoTimerId) {
clearInterval(state.autoTimerId);
clearTimeout(state.autoTimerId);
state.autoTimerId = null;
}
stopAutoCountdown();
Expand All @@ -610,6 +609,22 @@ function stopAutoPing(stopGps = false) {
updateAutoButton();
releaseWakeLock();
}
function scheduleNextAutoPing() {
if (!state.running) return;

const intervalMs = getSelectedIntervalMs();

// Start countdown immediately
startAutoCountdown(intervalMs);

// Schedule the next ping
state.autoTimerId = setTimeout(() => {
if (state.running) {
sendPing(false).catch(console.error);
}
}, intervalMs);
}

function startAutoPing() {
if (!state.connection) {
alert("Connect to a MeshCore device first.");
Expand All @@ -626,7 +641,7 @@ function startAutoPing() {

// Clean up any existing auto-ping timer (but keep GPS watch running)
if (state.autoTimerId) {
clearInterval(state.autoTimerId);
clearTimeout(state.autoTimerId);
state.autoTimerId = null;
}
stopAutoCountdown();
Expand All @@ -640,14 +655,8 @@ function startAutoPing() {
// Acquire wake lock for auto mode
acquireWakeLock().catch(console.error);

// First ping immediately, then at selected interval
// Send first ping immediately
sendPing(false).catch(console.error);
const intervalMs = getSelectedIntervalMs();
state.autoTimerId = setInterval(() => {
sendPing(false).catch(console.error);
}, intervalMs);

// Countdown will be started after the first ping completes
}

// ---- BLE connect / disconnect ----
Expand Down