Skip to content

Instantly share code, notes, and snippets.

@nLight
Last active November 21, 2015 13:38
Show Gist options
  • Save nLight/522c104a2be1241564d1 to your computer and use it in GitHub Desktop.
Save nLight/522c104a2be1241564d1 to your computer and use it in GitHub Desktop.
GoPro Timer Proof of Concept
<html>
<head>
<title>GoPro Timer</title>
</head>
<body>
<script>
var countDownTimer = null;
function countDown (time) {
stopTimer();
var timer = document.getElementById("timer");
timer.innerText = time--;
countDownTimer = window.setInterval(function () {
if (time > 0) {
timer.innerText = time--;
}
else {
stopTimer();
}
}, 1000);
}
function stopTimer () {
clearInterval(countDownTimer);
document.getElementById("timer").innerText = "";
}
function start () {
var startReq = new XMLHttpRequest()
, stopReq = new XMLHttpRequest()
, waitTime = parseInt( document.getElementById("waitTime").value, 10)
, recordTime = parseInt( document.getElementById("recordTime").value, 10)
, stopRecording = function () {
stopTimer();
document.getElementById("cameraStatus").innerText = "Stopped...";
stopReq.open("GET", "http://10.5.5.9/gp/gpControl/command/shutter?p=0");
stopReq.send();
}
, startRecording = function () {
startReq.open("GET", "http://10.5.5.9/gp/gpControl/command/shutter?p=1");
startReq.addEventListener("load", function () {
document.getElementById("cameraStatus").innerText = "Recording...";
countDownTimer = countDown(recordTime);
window.setTimeout(stopRecording, recordTime * 1000);
});
startReq.send();
};
window.setTimeout(startRecording, waitTime * 1000);
countDown(waitTime);
}
</script>
<label for="waitTime">Wait time in sec: <input id="waitTime" value="5"></label>
<label for="recordTime">Record time in sec: <input id="recordTime" value="5"></label>
<button onclick="start();">Start!</button>
<div id="cameraStatus"></div>
<div id="timer"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment