new AccelerationStream(l8, samplingRate)
Time based stream of acceleration data from the L8.
The stream is an object mode stream. It therefore does not return a buffer
if read, but one Acceleration data struct at a time. The data structure is
identical with the one you would get from the L8#getAcceleration
method.
The L8 only provides the Acceleration information if they are polled. This stream takes care of polling the data at a given sampling rate and providing it to you in an easily accessible way.
The stream automatically takes care of starting and stopping the data polling once a listener is connected or disconnected. Therefore you do not need to take care of this nasty business yourself.
The Stream needs an instance of the L8 class to attach to, as well as an optional
samplingRate_
. The sampling rate tells the system which timeframe (in msec) should be
waited between two data polls. If none is given 100 msec
is assumed by default.
In order to utilize the Stream simply wrap it around an L8 instance and attach to the corresponding Stream event handlers:
Name | Type | Description |
---|---|---|
l8 |
L8 |
Instance of the L8 to attach to. |
samplingRate |
int | optional |
Examples
var l8 = //...
var acceleration = new AccelerationStream(l8, 200);
acceleration.on("data", function(data) {
// Do something with each part of the acceleration data here.
});
Alternatively the convenience function L8#createAccelerationStream
can
be used to get an already connected stream directly from an L8 instance
var l8 = //...
var acceleration = l8.createAccelerationStream(200);
acceleration.on("data", function(data) {
// Do something with each part of the acceleration data here.
});
Members
-
privatecooldown_boolean
-
Status flag indicating whether the stream is in cooldown mode, aka. if it is currently waiting for the next sampling interval to occur.
-
privatel8_L8
-
Instance of the L8 to access for acceleration data
-
privaterequested_boolean
-
Status flag indicating whether a request to read a new acceleration data package was issued during the current cooldown mode
-
privatesamplingRate_Number
-
Sampling rate which defines in which interval the data is polled from the L8
Methods
-
private_read()
-
Triggered by the stream API in case the read buffer needs to be filled with information.
-
privateonResponse_(error, data)
-
Callback invoked each time acceleration data has been read from the L8
The information is retrieved directly from the
getAcceleration
method.Name Type Description error
String nullable data
Object -
privatepoll_()
-
Poll the acceleration information from the L8.
After the polling is complete the
AccelerationStream#onResponse_
method will be invoked as callback.