Skip to content

Instantly share code, notes, and snippets.

@jarrodbell
Created March 5, 2012 07:10
Show Gist options
  • Select an option

  • Save jarrodbell/1977165 to your computer and use it in GitHub Desktop.

Select an option

Save jarrodbell/1977165 to your computer and use it in GitHub Desktop.
Analog Watching for image changes
//Image Array
var Images = new Array();
Images[0] = "image00.png";
Images[1] = "image01.png";
Images[2] = "image03.png";
Images[3] = "image02.png";
function ImageChange(join, value) {
var nJoin = join.substr(1); // strip the "a" from the join string to just get the join number.
CF.setJoin("s" + nJoin, Images[value]); // set the serial value with an image.
}
// Common function that receives the join changes we watch
function onAnalogJoinChange(join, value) {
var nJoin = join.substr(1);
var nValue = parseInt(value);
CF.log("Set Unwatch");
CF.unwatch(CF.JoinChangeEvent, IMAGE_parameters);
IMAGE_parameters = [];
if(nValue == 0)
{
CF.log("Set00 Watch");
IMAGE_parameters = [];
}
if(nValue == 1)
{
CF.log("Set01 Watch");
IMAGE_parameters = ["a101", "a102", "a103", "a104", "a105", "a106"];
}
if(nValue == 2)
{
CF.log("Set02 Watch");
IMAGE_parameters = ["a201", "a202", "a203", "a204", "a205", "a206"];
}
CF.log("Set Watch");
CF.watch(CF.JoinChangeEvent, IMAGE_parameters, ImageChange);
CF.log("Hardware Change End");
}
var IMAGE_parameters = ["a8"];
// Only use one userMain function in your project. So if you have multiple scripts that need to do setup on startup,
// group all startup code into the one userMain function in any script.
CF.userMain = function () {
CF.log("Main");
// Watch the source type selection
CF.watch(CF.JoinChangeEvent, IMAGE_parameters, onAnalogJoinChange);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment