Class: TinkaCore

TinkaCore(id, characteristics)

Class representing a Tinkacore. Currently Supports: - Connection - ID: 0 - Output: [0|1] string containing name of sensor attached - Button - ID: 1 - Output: [0|1] - Knob - ID: 2 - Output: float ranging from -10 to 10 - Slider - ID: 3 - Output: float ranging from 0 to 10 - Joystick - ID: 4 - Output: horizontal float, vertical float ranging from -10 to 10 - Distance - ID: 23 - Output: float ranging from 0 to 20 - Color - ID: 27 - Output: red int, green int, blue int ranging from 0 to 255

Constructor

new TinkaCore(id, characteristics)

Creates an instance of the Tinkacore class
Parameters:
Name Type Description
id number
characteristics Object
Source:

Methods

(static) createMessage(direction, intensityInt, intensityDecimal) → {Array.<number>}

In process function - forms and sends a message to a Tinkacore that controls the motor. It can also be used to request the type of TinkaTop indicated in the device's response.
Parameters:
Name Type Description
direction number
intensityInt number
intensityDecimal number
Source:
Returns:
Type
Array.<number>

addEventListener(eventType, func, …args) → {boolean}

Function allowing the user to define custom event listeners to be called when a TinkaCore instance triggers an event. Events are called in the order with which they were added. eventType must be one of the following: - '*' - any message sent by a TinkaCore - 'sensor change' - When a tinkatop is removed or added - 'reading' - when any sensor triggers a sensor reading - 'button', 'knob', 'slider', 'joystick', 'distance', 'color'
Parameters:
Name Type Attributes Description
eventType string
func function
args * <repeatable>
Source:
Returns:
Type
boolean

connect() → {boolean}

Uses the Chrome Bluetooth API to connect the browser to a TinkaCore and begin subsribing to messages sent by the core. In Progress - Sends an initial message to the TinkaCore to determine its top.
Source:
Returns:
Type
boolean

connect_sensor(sensor_id) → {TinkaTop}

Determines a sensor based on the sensor id, the appropriate TinkaTop and instantiates a new TinkaTop instance. Unsupported TinkaTops (e.g. LED Grid) are set to an instance of the of the generic TinkaTop class.
Parameters:
Name Type Description
sensor_id number
Source:
Returns:
Type
TinkaTop

disconnect() → {boolean}

Called when a Tinkacore is turned off or the Bluetooth connection is otherwise lost. At the moment, this function is not meant to be called by the user since it does not stop subscription to sensor messages.
Source:
Returns:
Type
boolean

disconnect_sensor() → {boolean}

Called when a TinkaTop is taken off of a TinkaCore.
Source:
Returns:
Type
boolean

getLastReading(sensor_name) → {number|Array.<number>|false}

User called function to request the most recent value picked up by a sensor. - Return type depends on the sensor requested. - False if that sensor has not been used yet.
Parameters:
Name Type Description
sensor_name string
Source:
Returns:
Type
number | Array.<number> | false

getSensorName() → {string}

Getter for the name of the sensor.
Source:
Returns:
Type
string

parse_packet(event) → {boolean}

TinkaCores send byte strings of different lengths to indicate an important event like a sensor reading or connection. - (See the protocols folder for more info.) This is the main parser function that unpacks the byte string, interprets its length and meaning, and calls the appropriate functions. User defined event listeners are called here after messages are successfully parsed.
Parameters:
Name Type Description
event Object
Source:
Returns:
- true if interpretable, false otherwise
Type
boolean

reconnect(characteristics) → {boolean}

Called when a disconnected sensor is reconnected. At the moment, it simply calls the connect function.
Parameters:
Name Type Description
characteristics Object
Source:
Returns:
Type
boolean

removeEventListener(eventType, func) → {boolean}

Removes a callback function from the events list preventing further calls.
Parameters:
Name Type Description
eventType string
func function
Source:
Returns:
Type
boolean