Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add detection of the heartbeat #8

Merged
merged 1 commit into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
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
Binary file modified index.html.gz
Binary file not shown.
20 changes: 20 additions & 0 deletions www/js/tablet.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ var gCodeDisplayable = false
var snd = null
var sndok = true

var lastHeartBeatTime = new Date().getTime();

var versionNumber = 0.65

function beep(vol, freq, duration) {
Expand Down Expand Up @@ -238,6 +240,18 @@ sendMove = function (cmd) {

fn && fn()
}
setInterval(checkOnHeartbeat, 500);
function checkOnHeartbeat() {
if (new Date().getTime() - lastHeartBeatTime > 10000) {
let msgWindow = document.getElementById('messages')
let text = msgWindow.textContent
text = text + '\n' + "No heartbeat from machine in 10 seconds. Please check connection."
msgWindow.textContent = text
msgWindow.scrollTop = msgWindow.scrollHeight
lastHeartBeatTime = new Date().getTime();
}
}

function tabletShowMessage(msg, collecting) {
if (
collecting ||
Expand All @@ -250,6 +264,12 @@ function tabletShowMessage(msg, collecting) {
return
}

//This keeps track of when we saw the last heartbeat from the machine
if(msg.startsWith('[MSG:INFO: Heartbeat')){
lastHeartBeatTime = new Date().getTime();
return
}

let msgWindow = document.getElementById('messages')
let text = msgWindow.textContent
text = text + '\n' + msg
Expand Down