This module shows how a dashboard can remotely display data from a sensor in real time.
The sensor chosen in this example is the accelerometer of an Android device but the same could be done with other sensors.
The module has a dashboard with just two widgets: a graph and a switch.
The switch is bound to the @active exterior function:
(function (context act)
(if (= act null)
active
(if act (register_acc) (unregister_acc))
)
)
When the switch is activated, the register_acc function is called to register a listener for the accelerator data. This is done through the sensor function of the android Library:
(function ()
(if (not active)
(do
(sensor
"register"
"accelerometer"
(function (d)
(set accelerometer/x d/2)
(set accelerometer/y d/3)
(set accelerometer/z d/4)
(### "Update the graph widget")
(module-notify "@get-value")
)
)
(set active true)
(### "Update the switch widget")
(module-notify "@active")
)
)
)
After that, the accelerometer data
is saved in the accelerator variable
("x" => -0.061676025390625 "y" => 5.7689208984375 "z" => 8.949508666992188)
and displayed in the graph widget.
When the user deactivates the switch, the unregister_acc funcion is called to remove the listener of the accelerator data.
(function ()
(if active
(do
(sensor "unregister" "accelerometer")
(set active false)
(module-notify "@active")
)
)
)
This is how the dashboard looks like when accelerator data is being captured:
Note that the dashboard can display the accelerometer data in real time even when we are connected remotelly.