Skip to content

Instantly share code, notes, and snippets.

@jywarren
Last active April 13, 2016 21:14
Show Gist options
  • Save jywarren/4945996 to your computer and use it in GitHub Desktop.
Save jywarren/4945996 to your computer and use it in GitHub Desktop.
A SpectralWorkbench macro to periodically submit spectral data on a timer
setup: function() {
// code to run on startup
$W.timer = {}
$W.timer.title = prompt('Please provide a title for the spectra you will be capturing. They will also be numbered sequentially.')
$W.timer.number = 0
$W.timer.interval = 60*60 // seconds until next capture: 60 * 60 is one hour
// run this every hour:
$W.timer.capture = function() {
$W.timer.number += 1
if ($W.calibration_id) {
// submit the data:
$.ajax({
url: "/spectrums",
type: "POST",
data: {
spectrum: {
title: $W.timer.title+" #"+$W.timer.number,
notes: "Part of a series of spectrum captures using the API.",
calibration_id: $W.calibration_id
},
dataurl: $W.excerptCanvas(0,0,$W.width,1,$W.ctx).canvas.toDataURL(),
tags: "periodic,macro",
}
})
}
}
$W.timer.capture()
setInterval($W.timer.capture,$W.timer.interval * 1000)
},
draw: function() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment