Hardware Interface - NodeJs Reference

This API is intended for users who want to create their own hardware interfaces. Hardware interfaces are adapters that let you interact with different kinds of objects, like Arduino Uno or Lego WeDo, or even a virtual timer. To create a new hardware interface create a folder under hardwareInterfaces and create the file index.js. You should take a look at /hardwareInterfaces/emptyExample/index.js to get started. The API can be accessed by requiring the hardwareInterfaces library:
var server = require('../../libraries/hardwareInterfaces');

enableDeveloperUI(developer)

Enables the developer mode for all HybridObjects and enables the developer web interface.

Example:
server.enableDeveloperUI(true);

addNode(objectName, nodeName, type)

Adds a new IO point to the specified HybridObject.

Example:
server.addNode("lego1", "light1", "node");

renameNode(objectName,oldNodeName, newNodeName)

Renames a node in the specified HybridObject.

Example:
server.renameNode("lego1", "light1", "motor1");

activate(objectName)

Activates a specified HybridObject when it is done being configured with new nodes.

Example:
server.activate("lego1");

deactivate(objectName)

Deactivates a HybridObject so its data is no longer processed by the server until it is activated again.

Example:
server.deactivate("lego1");

write(objectName, nodeName, value, mode, unit, unitMin, unitMax)

This function writes the values passed from the hardware interface to the HybridObjects server.

Mode specifies the datatype of value, you can define it to be whatever you want. For example ‘f’ could mean value is a floating point variable.

Mode, unit, unitMin, and unitMax are currently optional, and will respectively take on default values of ‘f’, false, 0, and 1.

Example:
server.write("lego1", "light1", Math.random(), "f");

addReadListener(objectName, nodeName, callBack)

This function attaches a callback to a HybridObject’s node to listen for new values it receives and process them accordingly.

For example, the arduino hardwareInterface listens for values and writes them to the serial port.

Example:
server.addReadListener("lego1", "light1", function (data) {
console.log(data.value);
});

removeReadListeners(objectName)

Removes the callbacks attached to a HybridObject by addReadListener.

Example:
server.removeReadListeners("lego1");

addEventListener(option, callBack)

Listens for specific events from the server. Option can be either “reset” or “shutdown.”

Example:
server.addEventListener('shutdown', function() {
console.log('shutting down');
});

map(x, in_min, in_max, out_min, out_max)

Remaps the value of x from the range of [in_min, in_max] to the range of [out_min, out_max]

Example:
var scaledValue = server.map(data.value, 0, 1, -100, 100);

advertiseConnection(object, node, logic)

Broadcasts the HybridObject and node names to the Reality Editor for the Instant Connection feature.

Example:
server.advertiseConnection("lego1","light1");

getDebug()

Checks if debug mode is turned on. Returns true if debug mode is on, false otherwise.

Example:
if (server.getDebug()) console.log("developer");