Tinkerforge-NodeJS/Tinkerforge/BrickletAccelerometer.js
2016-03-09 21:35:32 +01:00

227 lines
11 KiB
JavaScript

/* ***********************************************************
* This file was automatically generated on 2016-02-10. *
* *
* JavaScript Bindings Version 2.0.8 *
* *
* If you have a bugfix for this file and want to commit it, *
* please fix the bug in the generator. You can find a link *
* to the generators git repository on tinkerforge.com *
*************************************************************/
var Device = require('./Device');
BrickletAccelerometer.DEVICE_IDENTIFIER = 250;
BrickletAccelerometer.DEVICE_DISPLAY_NAME = 'Accelerometer Bricklet';
BrickletAccelerometer.CALLBACK_ACCELERATION = 14;
BrickletAccelerometer.CALLBACK_ACCELERATION_REACHED = 15;
BrickletAccelerometer.FUNCTION_GET_ACCELERATION = 1;
BrickletAccelerometer.FUNCTION_SET_ACCELERATION_CALLBACK_PERIOD = 2;
BrickletAccelerometer.FUNCTION_GET_ACCELERATION_CALLBACK_PERIOD = 3;
BrickletAccelerometer.FUNCTION_SET_ACCELERATION_CALLBACK_THRESHOLD = 4;
BrickletAccelerometer.FUNCTION_GET_ACCELERATION_CALLBACK_THRESHOLD = 5;
BrickletAccelerometer.FUNCTION_SET_DEBOUNCE_PERIOD = 6;
BrickletAccelerometer.FUNCTION_GET_DEBOUNCE_PERIOD = 7;
BrickletAccelerometer.FUNCTION_GET_TEMPERATURE = 8;
BrickletAccelerometer.FUNCTION_SET_CONFIGURATION = 9;
BrickletAccelerometer.FUNCTION_GET_CONFIGURATION = 10;
BrickletAccelerometer.FUNCTION_LED_ON = 11;
BrickletAccelerometer.FUNCTION_LED_OFF = 12;
BrickletAccelerometer.FUNCTION_IS_LED_ON = 13;
BrickletAccelerometer.FUNCTION_GET_IDENTITY = 255;
BrickletAccelerometer.THRESHOLD_OPTION_OFF = 'x';
BrickletAccelerometer.THRESHOLD_OPTION_OUTSIDE = 'o';
BrickletAccelerometer.THRESHOLD_OPTION_INSIDE = 'i';
BrickletAccelerometer.THRESHOLD_OPTION_SMALLER = '<';
BrickletAccelerometer.THRESHOLD_OPTION_GREATER = '>';
BrickletAccelerometer.DATA_RATE_OFF = 0;
BrickletAccelerometer.DATA_RATE_3HZ = 1;
BrickletAccelerometer.DATA_RATE_6HZ = 2;
BrickletAccelerometer.DATA_RATE_12HZ = 3;
BrickletAccelerometer.DATA_RATE_25HZ = 4;
BrickletAccelerometer.DATA_RATE_50HZ = 5;
BrickletAccelerometer.DATA_RATE_100HZ = 6;
BrickletAccelerometer.DATA_RATE_400HZ = 7;
BrickletAccelerometer.DATA_RATE_800HZ = 8;
BrickletAccelerometer.DATA_RATE_1600HZ = 9;
BrickletAccelerometer.FULL_SCALE_2G = 0;
BrickletAccelerometer.FULL_SCALE_4G = 1;
BrickletAccelerometer.FULL_SCALE_6G = 2;
BrickletAccelerometer.FULL_SCALE_8G = 3;
BrickletAccelerometer.FULL_SCALE_16G = 4;
BrickletAccelerometer.FILTER_BANDWIDTH_800HZ = 0;
BrickletAccelerometer.FILTER_BANDWIDTH_400HZ = 1;
BrickletAccelerometer.FILTER_BANDWIDTH_200HZ = 2;
BrickletAccelerometer.FILTER_BANDWIDTH_50HZ = 3;
function BrickletAccelerometer(uid, ipcon) {
//Measures acceleration in three axis
/*
Creates an object with the unique device ID *uid* and adds it to
the IP Connection *ipcon*.
*/
Device.call(this, this, uid, ipcon);
BrickletAccelerometer.prototype = Object.create(Device);
this.responseExpected = {};
this.callbackFormats = {};
this.APIVersion = [2, 0, 1];
this.responseExpected[BrickletAccelerometer.FUNCTION_GET_ACCELERATION] = Device.RESPONSE_EXPECTED_ALWAYS_TRUE;
this.responseExpected[BrickletAccelerometer.FUNCTION_SET_ACCELERATION_CALLBACK_PERIOD] = Device.RESPONSE_EXPECTED_TRUE;
this.responseExpected[BrickletAccelerometer.FUNCTION_GET_ACCELERATION_CALLBACK_PERIOD] = Device.RESPONSE_EXPECTED_ALWAYS_TRUE;
this.responseExpected[BrickletAccelerometer.FUNCTION_SET_ACCELERATION_CALLBACK_THRESHOLD] = Device.RESPONSE_EXPECTED_TRUE;
this.responseExpected[BrickletAccelerometer.FUNCTION_GET_ACCELERATION_CALLBACK_THRESHOLD] = Device.RESPONSE_EXPECTED_ALWAYS_TRUE;
this.responseExpected[BrickletAccelerometer.FUNCTION_SET_DEBOUNCE_PERIOD] = Device.RESPONSE_EXPECTED_TRUE;
this.responseExpected[BrickletAccelerometer.FUNCTION_GET_DEBOUNCE_PERIOD] = Device.RESPONSE_EXPECTED_ALWAYS_TRUE;
this.responseExpected[BrickletAccelerometer.FUNCTION_GET_TEMPERATURE] = Device.RESPONSE_EXPECTED_ALWAYS_TRUE;
this.responseExpected[BrickletAccelerometer.FUNCTION_SET_CONFIGURATION] = Device.RESPONSE_EXPECTED_FALSE;
this.responseExpected[BrickletAccelerometer.FUNCTION_GET_CONFIGURATION] = Device.RESPONSE_EXPECTED_ALWAYS_TRUE;
this.responseExpected[BrickletAccelerometer.FUNCTION_LED_ON] = Device.RESPONSE_EXPECTED_FALSE;
this.responseExpected[BrickletAccelerometer.FUNCTION_LED_OFF] = Device.RESPONSE_EXPECTED_FALSE;
this.responseExpected[BrickletAccelerometer.FUNCTION_IS_LED_ON] = Device.RESPONSE_EXPECTED_ALWAYS_TRUE;
this.responseExpected[BrickletAccelerometer.CALLBACK_ACCELERATION] = Device.RESPONSE_EXPECTED_ALWAYS_FALSE;
this.responseExpected[BrickletAccelerometer.CALLBACK_ACCELERATION_REACHED] = Device.RESPONSE_EXPECTED_ALWAYS_FALSE;
this.responseExpected[BrickletAccelerometer.FUNCTION_GET_IDENTITY] = Device.RESPONSE_EXPECTED_ALWAYS_TRUE;
this.callbackFormats[BrickletAccelerometer.CALLBACK_ACCELERATION] = 'h h h';
this.callbackFormats[BrickletAccelerometer.CALLBACK_ACCELERATION_REACHED] = 'h h h';
this.getAcceleration = function(returnCallback, errorCallback) {
/*
Returns the acceleration in x, y and z direction. The values
are given in g/1000 (1g = 9.80665m/s²), not to be confused with grams.
If you want to get the acceleration periodically, it is recommended
to use the callback :func:`Acceleration` and set the period with
:func:`SetAccelerationCallbackPeriod`.
*/
this.ipcon.sendRequest(this, BrickletAccelerometer.FUNCTION_GET_ACCELERATION, [], '', 'h h h', returnCallback, errorCallback);
};
this.setAccelerationCallbackPeriod = function(period, returnCallback, errorCallback) {
/*
Sets the period in ms with which the :func:`Acceleration` callback is triggered
periodically. A value of 0 turns the callback off.
:func:`Acceleration` is only triggered if the acceleration has changed since the
last triggering.
The default value is 0.
*/
this.ipcon.sendRequest(this, BrickletAccelerometer.FUNCTION_SET_ACCELERATION_CALLBACK_PERIOD, [period], 'I', '', returnCallback, errorCallback);
};
this.getAccelerationCallbackPeriod = function(returnCallback, errorCallback) {
/*
Returns the period as set by :func:`SetAccelerationCallbackPeriod`.
*/
this.ipcon.sendRequest(this, BrickletAccelerometer.FUNCTION_GET_ACCELERATION_CALLBACK_PERIOD, [], '', 'I', returnCallback, errorCallback);
};
this.setAccelerationCallbackThreshold = function(option, minX, maxX, minY, maxY, minZ, maxZ, returnCallback, errorCallback) {
/*
Sets the thresholds for the :func:`AccelerationReached` callback.
The following options are possible:
.. csv-table::
:header: "Option", "Description"
:widths: 10, 100
"'x'", "Callback is turned off"
"'o'", "Callback is triggered when the acceleration is *outside* the min and max values"
"'i'", "Callback is triggered when the acceleration is *inside* the min and max values"
"'<'", "Callback is triggered when the acceleration is smaller than the min value (max is ignored)"
"'>'", "Callback is triggered when the acceleration is greater than the min value (max is ignored)"
The default value is ('x', 0, 0, 0, 0, 0, 0).
*/
this.ipcon.sendRequest(this, BrickletAccelerometer.FUNCTION_SET_ACCELERATION_CALLBACK_THRESHOLD, [option, minX, maxX, minY, maxY, minZ, maxZ], 'c h h h h h h', '', returnCallback, errorCallback);
};
this.getAccelerationCallbackThreshold = function(returnCallback, errorCallback) {
/*
Returns the threshold as set by :func:`SetAccelerationCallbackThreshold`.
*/
this.ipcon.sendRequest(this, BrickletAccelerometer.FUNCTION_GET_ACCELERATION_CALLBACK_THRESHOLD, [], '', 'c h h h h h h', returnCallback, errorCallback);
};
this.setDebouncePeriod = function(debounce, returnCallback, errorCallback) {
/*
Sets the period in ms with which the threshold callback
* :func:`AccelerationReached`
is triggered, if the threshold
* :func:`SetAccelerationCallbackThreshold`
keeps being reached.
The default value is 100.
*/
this.ipcon.sendRequest(this, BrickletAccelerometer.FUNCTION_SET_DEBOUNCE_PERIOD, [debounce], 'I', '', returnCallback, errorCallback);
};
this.getDebouncePeriod = function(returnCallback, errorCallback) {
/*
Returns the debounce period as set by :func:`SetDebouncePeriod`.
*/
this.ipcon.sendRequest(this, BrickletAccelerometer.FUNCTION_GET_DEBOUNCE_PERIOD, [], '', 'I', returnCallback, errorCallback);
};
this.getTemperature = function(returnCallback, errorCallback) {
/*
Returns the temperature of the accelerometer in °C.
*/
this.ipcon.sendRequest(this, BrickletAccelerometer.FUNCTION_GET_TEMPERATURE, [], '', 'h', returnCallback, errorCallback);
};
this.setConfiguration = function(dataRate, fullScale, filterBandwidth, returnCallback, errorCallback) {
/*
Configures the data rate, full scale range and filter bandwidth.
Possible values are:
* Data rate of 0Hz to 1600Hz.
* Full scale range of -2G to +2G up to -16G to +16G.
* Filter bandwidth between 50Hz and 800Hz.
Decreasing data rate or full scale range will also decrease the noise on
the data.
The default values are 100Hz data rate, -4G to +4G range and 200Hz
filter bandwidth.
*/
this.ipcon.sendRequest(this, BrickletAccelerometer.FUNCTION_SET_CONFIGURATION, [dataRate, fullScale, filterBandwidth], 'B B B', '', returnCallback, errorCallback);
};
this.getConfiguration = function(returnCallback, errorCallback) {
/*
Returns the configuration as set by :func:`SetConfiguration`.
*/
this.ipcon.sendRequest(this, BrickletAccelerometer.FUNCTION_GET_CONFIGURATION, [], '', 'B B B', returnCallback, errorCallback);
};
this.ledOn = function(returnCallback, errorCallback) {
/*
Enables the LED on the Bricklet.
*/
this.ipcon.sendRequest(this, BrickletAccelerometer.FUNCTION_LED_ON, [], '', '', returnCallback, errorCallback);
};
this.ledOff = function(returnCallback, errorCallback) {
/*
Disables the LED on the Bricklet.
*/
this.ipcon.sendRequest(this, BrickletAccelerometer.FUNCTION_LED_OFF, [], '', '', returnCallback, errorCallback);
};
this.isLEDOn = function(returnCallback, errorCallback) {
/*
Returns *true* if the LED is enabled, *false* otherwise.
*/
this.ipcon.sendRequest(this, BrickletAccelerometer.FUNCTION_IS_LED_ON, [], '', '?', returnCallback, errorCallback);
};
this.getIdentity = function(returnCallback, errorCallback) {
/*
Returns the UID, the UID where the Bricklet is connected to,
the position, the hardware and firmware version as well as the
device identifier.
The position can be 'a', 'b', 'c' or 'd'.
The device identifier numbers can be found :ref:`here <device_identifier>`.
|device_identifier_constant|
*/
this.ipcon.sendRequest(this, BrickletAccelerometer.FUNCTION_GET_IDENTITY, [], '', 's8 s8 c B3 B3 H', returnCallback, errorCallback);
};
}
module.exports = BrickletAccelerometer;