11package eu .fbk .mpba .sensorsflows .plugins .inputs .empatica ;
22
33import android .content .Context ;
4+ import android .os .Handler ;
45import android .util .Log ;
56import android .widget .Toast ;
67
@@ -18,6 +19,7 @@ public class EmpaticaNode implements NodePlugin<Long, double[]> {
1819 final String LOG_TAG = "ALE EMP DEV" ;
1920
2021 private boolean lastCheckTODO = true ;
22+ private float batteryLevel = -1 ;
2123
2224 final EmpaticaBeam beam ;
2325 final EmpaticaSensor .Accelerometer mAcc ;
@@ -58,11 +60,6 @@ public EmpaticaNode(String key, final Context context, String address, Runnable
5860 @ Override
5961 public void didReceiveAcceleration (int x , int y , int z , double timestamp ) {
6062 mAcc .sensorValue (proTime (timestamp ), new double []{x , y , z });
61- if (lastCheckTODO ) {
62- lastCheckTODO = false ;
63- if (connectedStreaming != null )
64- new Thread (connectedStreaming ).start ();
65- }
6663 }
6764
6865 @ Override
@@ -72,6 +69,12 @@ public void didReceiveBVP(float bvp, double timestamp) {
7269
7370 @ Override
7471 public void didReceiveBatteryLevel (float battery , double timestamp ) {
72+ batteryLevel = battery ;
73+ if (lastCheckTODO ) {
74+ lastCheckTODO = false ;
75+ if (connectedStreaming != null )
76+ new Handler (context .getMainLooper ()).post (connectedStreaming );
77+ }
7578 mBat .sensorValue (proTime (timestamp ), new double []{battery });
7679 Log .v (LOG_TAG , EmpaticaNode .this .getName () + " didReceiveBatteryLevel: " + battery );
7780 }
@@ -183,4 +186,8 @@ protected void finalize() throws Throwable {
183186 public void close () {
184187 beam .destroy ();
185188 }
189+
190+ public float getBatteryLevel () {
191+ return batteryLevel ;
192+ }
186193}
0 commit comments