Skip to content

Instantly share code, notes, and snippets.

View jarrodbell's full-sized avatar

Jarrod Bell jarrodbell

View GitHub Profile
@jarrodbell
jarrodbell / submitform.js
Last active December 19, 2015 18:09
Send form data via HTTP POST using CommandFusion iViewer
/**
* Get join data and send HTTP request
*/
function submitForm () {
// Get join values
CF.getJoins(["s1", "s2", "s3", "s4"], function(joins) {
// Create POST data
var postFields = {
z_name: joins["s1"].value, //Join S1 Name
@jarrodbell
jarrodbell / hex.js
Last active December 14, 2015 22:38
JavaScript hex conversion snippets
// Convert 0-255 to hex byte:
String.fromCharCode(id)
// Convert 01-FF to hex byte:
String.fromCharCode(parseInt(id, 16))
// Convert hex byte to 0-ff:
id.charCodeAt(0).toString(16);
// Convert hex byte to 00-FF:
@jarrodbell
jarrodbell / main.js
Created February 27, 2013 03:14
This is a quick example on how to set a button active and inactive based on slider join value reaching extremities.
// This is a quick example on how to set a button active and inactive based on slider join value reaching extremities.
// http://www.commandfusion.com/docs/scripting/startup.html#script_execution_and_lifetime
CF.userMain = function() {
// Setup a watch on the specific analog join you want to use, in our case analog join 10
// http://www.commandfusion.com/docs/scripting/gui.html#cF.JoinChangeEvent
CF.watch(CF.JoinChangeEvent, "a10", function (join, value) {
// This callback is run whenever the analog join 10 changes value
// join = "a10"
@jarrodbell
jarrodbell / main.js
Last active December 14, 2015 06:29
This is a quick example on how to scroll a list to a specific pixel position defined by the value of an analog join within CommandFusion iViewer.
// This is a quick example on how to scroll a list to a specific pixel position
// defined by the value of an analog join.
// http://www.commandfusion.com/docs/scripting/startup.html#script_execution_and_lifetime
CF.userMain = function() {
// Setup a watch on the specific analog join you want to use for the list scroll position
// http://www.commandfusion.com/docs/scripting/gui.html#cF.JoinChangeEvent
CF.watch(CF.JoinChangeEvent, "a10", function (join, value) {
// This callback is run whenever the analog join 10 changes value
@jarrodbell
jarrodbell / gist:3890637
Created October 15, 2012 03:05
CFLink JS API device definition with DIN-MOD4 modules, watching MOD-COM4 data
// Quick example of watching data in a COM4 module
var devices = CFLink.getDevices({
lanbridge: {
id: "02",
type: CFLink.model.LANBridge
},
dinmod4: {
id: "2B",
type: CFLink.model.DINMOD4,
@jarrodbell
jarrodbell / gist:3762140
Created September 21, 2012 15:22
CommandFusion XML Parsing - JavaScript API
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(body, 'text/xml');
// Get the data from XML
var results = xmlDoc.evaluate("//Item", xmlDoc, null, XPathResult.ANY_TYPE, null);
var infoItem = results.iterateNext();
while (infoItem) {
CF.log("Name Attribute: " + infoItem.getAttribute("Name"));
CF.log("Node Value: " + infoItem.childNodes[0].nodeValue);
infoItem = results.iterateNext();
@jarrodbell
jarrodbell / gist:2936917
Created June 15, 2012 15:07 — forked from D-Touch/gist:2936671
Delaying color picker commands
/* Color Picker module for CommandFusion
===============================================================================
AUTHOR: Sergey Klenov, Jarrod Bell, Florent Pillet, CommandFusion
CONTACT: support@commandfusion.com
URL: https://github.com/CommandFusion/
VERSION: v1.0.2
LAST MOD: Thursday, 17 November 2011
=========================================================================
@jarrodbell
jarrodbell / gist:2924984
Created June 13, 2012 16:02
Delaying color picker commands
// Push the modules into the startup process
CF.modules.push({name: "Color Picker", object: ColorPicker});
var myColorPicker;
// Only one CF.userMain function in all scripts is allowed!
// If you have one already in your project, consolidate all their contents into one CF.userMain function
CF.userMain = function () {
myColorPicker = new ColorPicker("colorpicker.png", "s1", 750, function(r, g, b, x, y) {
// This code will be run everytime the pixel color is obtained, along with the pixel data as parameters
CF.send("AppleKNX", "\x06\x20\xF0\x80\x00\x15\x04\x00\x00\x00\xF0\x06\x01\x32\x00\x01\x01\x32\x­03\x01" + String.fromCharCode(r) );
@jarrodbell
jarrodbell / gist:2494847
Created April 26, 2012 00:45
CommandFusion: Using a list as a message log
function addLog (data) {
CF.listAdd("l10", [{"s1": data, "s2": new Date().toTimeString()}]);
// Automatically scroll to the bottom of the log
CF.listInfo("l10", function (list, count) {
CF.listScroll("l10", count, CF.BottomPosition, true);
});
}
@jarrodbell
jarrodbell / gist:2288936
Created April 3, 2012 02:45
Timezone List
[UTC-12] Niue Time
[UTC-12] Samoa Standard Time
[UTC-11] Hawaii-Aleutian Standard Time
[UTC-11] Cook Island Time
[UTC-9:30] Marquesas Islands Time
[UTC-9] Alaska Standard Time
[UTC-9] Gambier Island Time
[UTC-8] Pacific Standard Time
[UTC-7] Mountain Standard Time