Skip to content

Instantly share code, notes, and snippets.

View jarrodbell's full-sized avatar

Jarrod Bell jarrodbell

View GitHub Profile
@jarrodbell
jarrodbell / gist:2288665
Created April 3, 2012 01:42
CommandFusion: JavaScript list population example
function populateList (listJoin, elements) {
CF.log("Populating list");
// Clear the list
CF.listRemove(listJoin);
// Create an array to fill with list contents
var newContents = [];
// Avoid using Array.forEach() method as it uses callbacks to access the data, which means code after the forEach loop will be executed before the loop finishes.
for (var i=0; i<elements.length; i++) {
newContents.push({s1: element.textlabel, s2: element.filename});
}
@jarrodbell
jarrodbell / gist:2144878
Created March 21, 2012 05:45
Basic Command Queuing for CommandFusion
/* Basic Command Queuing for CommandFusion
USAGE:
- First step: Replace the "SYSTEM NAME GOES HERE" text towards the end of the script with your actual system name as defined in the System Manager of your GUI project
- Next: Save this script into a .js file and add it to your GUI project via Project Properties > Script Manager.
- Ensure you are using iViewer4 (NOT CF iViewer, legacy product without JavaScript support)
- within button properties, add a JavaScript call such as:
CommandQueue.startCommand("StartDataGoesHere");
@jarrodbell
jarrodbell / gist:1977165
Created March 5, 2012 07:10
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.
@jarrodbell
jarrodbell / gist:1948409
Created March 1, 2012 08:48
Manage Object Visibility
var manageItems = ["l1","l2","l3","l4"];
function showItem(joinToShow) {
var hideItems = [];
for (var i = 0; i < manageItems.length; i++) {
if (manageItems[i] != joinToShow) {
hideItems.push({join: manageItems[i], opacity: 0});
}
}
hideItems.push({join: joinToShow, opacity: 1});
CF.setProperties(hideItems);
@jarrodbell
jarrodbell / gist:1789532
Created February 10, 2012 12:57
Toggle power state with feedback
/*
NOTE: Change "System Name" and "Feedback Name" to the correct info for your project first.
NOTE: Change "d1" to the digital join number of your power button.
NOTE: on your power button, set the javascript to: togglePower();
*/
var powerState = 0;
var powerStateRegex = /\x21\x01\x00\x00\x01(\x00|\x01)\x0D/;
@jarrodbell
jarrodbell / gist:1214016
Created September 13, 2011 14:58
URL Encode and Decode in JavaScript
/**
* rfc3986 compatable encode of a string
*
* @param {String} string
*/
self.urlEncode = function (string) {
function hex(code) {
var hex = code.toString(16).toUpperCase();
if (hex.length < 2) {
hex = 0 + hex;
@jarrodbell
jarrodbell / gist:1034969
Created June 20, 2011 01:03
PUT request using CF.request
var baseURL = "www.someurl.com";
var theURL = "/some/url?param=test";
var headerString = "\
PUT "+theURL+" HTTP/1.1\r\n\
Host: "+baseURL+"\r\n\
Accept-Encoding: gzip, deflate\r\n\
Content-Type: text/xml\r\n\
Content-Length: ";