JavaScript support

Where are the pin values?

It's important to use these arrays and update their values so the framework pin states can be consistent.

involt.pin.P[index] array contains the P pins.

involt.pin.S[index] contains the strings.

involt.pin.A[index] contains the received values (updated automatically).

involt.send(pin, value)

Send value to target pin:

involt.pin.P[6] = 255;
involt.send("P6", involt.pin.P[6]);

involt.sendFunction(name)

Send the function name to device. For triggering function from device to app check functions page.

involt.sendFunction("test");

involt.sendToDevice(string)

Send raw string to device. This should be used only with custom arduino sketch.

var string = "anything"+"\n";

involt.sendToDevice(string);

JQuery methods

For better modularity and simplicity of working on existing Involt UI elements use JQuery methods. Framework elements are based on them.

For more examples check the Involt as JQuery plugin.

Changing the UI element parameters

To manipulate the parameters in framework elements use JQuery .data(). These parameters are: pin, pinNumber, pinType, value, min, max, step, fn. While working with HTML inputs use .attr() instead.

Basic pattern

Most basic example of assigning the pin to element, updating its value in array and send it to device. You should use this pattern as much as possible. There is one golden rule: using Involt JQuery methods is more about manipulating pins rather than elements that control them.

$(this).pinDefine("P6").updateValue(100).sendValue();

Currently there are no methods related to receiving data from device. Listening for pin or triggering function is something that reacts to receive event but it's not related to JQuery. The values are updated automatically so use the involt.pin.A[index] if necessary.

Important: remember about JQuery document ready to make sure that everything is loaded.

1. Assigning the pin to element

.pinDefine(pin)

Defines the pin for selected element (pin, pinNumber, pinType). You don't have to use this method each time, just define this once.

$(this).pinDefine("P6");

.pinSwap(newPin)

Similar to pinDefine but checks if there is defined pin value in involt.pin arrays. If not - set it to previous pin value. The previous pin must be defined.

// if the P7 value was undefined, it will be 100.

$(this).pinDefine("P6").updateValue(100).pinSwap("P7");

2. Updating pin value

.updateValue(value, updateElement)

Updates the pin current value before sending it to device (involt.pin array). updateValue keeps them up to date so the framework is consistent and multiple UI elements share same single value. Each pin can have only one value at once.

If value is not defined, the pin current value will change to UI element value stored with JQuery data (make sure that the element has .data("value")). If value is set, the pin current value will be same as passed variable to this method.

Define updateElement as true to update both pin value and element value at once.

Before updating the value you must define the pin with pinDefine.

Use the UI element value to update pin value:

$(this).updateValue();

Assigned pin now will have new value but not the element itself:

$(this).updateValue(255);

Both UI element and pin will have same new value:

$(this).updateValue(255,true);

3. Sending

.sendValue(value)

If the pin is defined and its value is set, it's time to send it to device. Passing the value to this method will send the variable to target pin without updating anything.

When everything is defined, send the value:

$(this).sendValue();

Send the defined with updateValue value of pin.:

$(this).pinDefine("P6").updateValue(100).sendValue();

Send the value from element JQuery data ( .data("value", 100)):

$(this).pinDefine("P6").updateValue().sendValue();

Set pin and element value to same number and send it:

$(this).pinDefine("P6").updateValue(255, true).sendValue();

Send the value to pin without updating anything and outside of pin array:

$(this).pinDefine("P6").sendValue(123);

.sendFn(name)

Send function name to device. If name is not defined it will use fn data (declaring fn should be avoided if you don't want to send function on sendValue) event.

$(this).sendFn("test");

.sendRawString(string)

Send string to device. Similar to involt.sendToDevice(string).

$(this).sendRawString("sendAnything");

.sendAndUpdate(pin, value)

Shorthand for:

$(this).pinDefine(pin).updateValue(value, true).sendValue();