|
The SensorDomo Android app provides hooks for providing the phone's sensor data to a web page downloaded from an arbitrary web site.
We plan to add the ability to configure sending the phone’s sensor data out to an external entity via WebSockets.
In order to write javascript that gets notified of sensor events, programmers should use the following model:
Inside your document ready javascript function, subscribe to one or many of the sensor events available. Currently the available options for <sensorName> are:
1) "SENSOR_ORIENTATION"
2) "SENSOR_TOUCH"
3) “SENSOR_ACCELEROMETER"
4) "SENSOR_LIGHT"
5) "SENSOR_PROXIMITY"
6) "SENSOR_GPS”
From within your Javascript code, call one of the function:
subscribeSensor(<sensorName>, <callbackName>)
Then implement the function named <callbackName> in your Javascript code. The function will be called with a set of parameters that is pre-determined by the android application code and is based on the sensor data values that are available. The parameters required for each sensor type callback are as follows:
"SENSOR_TOUCH" - The callback function name you provide will be called with two parameters in the following order:
1) x location of the touch event in pixels
2) y location of the touch event in pixels
A warning about subscribing to touch events. If you want your web page to respond to html button clicks and text entry, you can’t subscribe to touch events. Once you subscribe for touch events, those touch events are no longer propagated to the web view where your buttons and other html widgets live. You can always subscribe for touch events, then unsubscribe later, as long as you can trigger the unsubscribe call without needing the user to interact with HTML widgets. For example, you could register for accelerometer events, and then register for touch events, and use the touch screen functionality for awhile. You would write some Javascript which would watch the accelerometer data and unsubscribe from the touch events when it sees the phone turned upside down.
"SENSOR_ORIENTATION" - The callback function name you provide will be called with three parameters in the following order:
1) azimuth in degrees
2) pitch in degrees
3) roll in degrees
“SENSOR_ACCELEROMETER” - The callback function name you provide will be called with three parameters in the following order:
1) accelerometer x value
2) accelerometer y value
3) accelerometer z value
“SENSOR_LIGHT” - The callback function name you provide will be called with the following parameter:
1) light value
“SENSOR_PROXIMITY” - The callback function name you provide will be called with the following parameter:
1) proximity value
“SENSOR_GPS” - The callback function name you provide will be called with two parameters in the following order:
1) latitude
2) longitude
If you want to unsubscribe from certain sensor events when you don’t need them anymore, you can save some battery by doing so. The way to unsubscribe is by using the following function call:
unsubscribeSensor(<sensorName>)
Where <sensorName> is one of the sensor names described above.
As mentioned above, all sensor data can be forwarded to a list of remote servers via OSC messages. To achieve this behavior, call the following function from within your Javascript code:
addOscServer(<ip-address>, <port>, <sensorId>, <oscAddress>);
Where the sensorId strings are the same as for subscribing to events for your Javascript code. Also, you should specify an OSC address in this function call so that the android application will know where to address your sensor data on the remote machine. Example:
addOscServer("192.168.1.100", 32323, "SENSOR_TOUCH", "/sensor/touch");
If you want to remove an OSC server from the list of entities notified with your phone’s sensor data, call the following function from within your Javascript code:
removeOscServer(<ip-address>);
You can also remove a single sensor type from the list of sensor data that is being forwarded to an remote server by making the following call in your Javascript code:
removeOscSensor(<ip-address>, <sensorName>);