Wiki
Clone wikirobobo-programming / native / sensing-library
Using sensing library
The sensing library is used to get infomation form the smartphone sensors in an easy mode. This library is composed by 4 modules:
Acceleration module
This module can be used for getting information about the state of the acceleration sensor of the smartphone. The interface of the module is the following one:
public interface IAccelerationModule extends IModule { void suscribe(IAccelerationListener listener); void unsuscribe(IAccelerationListener listener); void setDetectionThreshold(int threshold); }
setDetectionThreshold()
sets the amount of change required to trigger a detection.
suscribe()
and unsuscribe()
are used to manage the listeners of the acceleration module. A class that wants to receive notifications of the acceleration sensor must implement the interface IAccelerationListener.class
.
public interface IAccelerationListener { void onAccelerationChange(); void onAcceleration(double xaccel, double yaccel, double zaccel); }
onAccelerationChange()
is called when a notable change is detected on the acceleration. The threshold of the detection is configured via the setDetectionThreshold()
method.
onAcceleration()
is called on a regular basis and returns the acceleration in the three axis of space.
Obtaining the instance of the module
IAccelerationModule accelModule = roboboManager.getModuleInstance(IAccelerationModule.class);
Current implementation
AndroidAccelerationModule:
robobo.module.17=com.mytechia.robobo.framework.sensing.accel.android.AndroidAccelerationModule
Orientation module
This module can be used for getting information about the state of the orientation sensor of the smartphone. This virtual sensor uses a mix of the acceleration, gyroscope and magnetometer sensor to obtain the absolute position of the device, therefore, if the smartphone lacks any of this hardware sensors, this module will not work.
Warning: may not work in all devices
public interface IOrientationModule extends IModule { void suscribe(IOrientationListener listener); void unsuscribe(IOrientationListener listener); }
suscribe()
and unsuscribe()
are used to manage the listeners of the orientation module. A class that wants to receive notifications of the orientation sensor must implement the interface IOrientationListener.class
.
public interface IOrientationListener { /** * Called when the orientation changes * @param yaw Orientation at yaw axis * @param pitch Orientation at pitch axis * @param roll Orientation at roll axis */ void onOrientationChanged(float yaw, float pitch, float roll); }
onOrientationChanged()
is called when the orientation of the device changes and returns the orientation on the three axis of space.
Obtaining the instance of the module
IOrientationModule orientationModule = roboboManager.getModuleInstance(IOrientationModule.class);
Current implementation
AndroidOrientationModule:
robobo.module.16=com.mytechia.robobo.framework.sensing.orientation.android.AndroidOrientationModule
Brightness module
This module is used to access easily to the information of the brightness sensor of the smartphone.
Warning: may not work in all devices
public interface IBrightnessModule extends IModule { float readBrightnessValue(); void suscribe(IBrightnessListener listener); void setHasChangedAmount(int amount); void unsuscribe(IBrightnessListener listener); }
readBrightnessValue()
returns the actual brightness measured in lux.
setHasChangedAmount()
sets the threshold to determine when a change is detected.
suscribe()
and unsuscribe()
are used to manage the listeners of the brightness module. A class that wants to receive notifications of the brightness sensor must implement the interface IBrightnessListener.class
.
public interface IBrightnessListener { void onBrightness(float value); void onBrightnessChanged(); }
onBrightness()
is called on a regular basis and returns the detected brightness. onBrightnessChanged()
is called when a notable change in brightness is detected.
Obtaining the instance of the module
IBrightnessModule brightnessModule = roboboManager.getModuleInstance(IBrightnessModule.class);
Current implementation
AndroidBrightnessModule:
robobo.module.15=com.mytechia.robobo.framework.sensing.brightness.android.AndroidBrightnessModule
Battery module
This module allows the programmer to access the battery level of the device.
public interface IBatteryModule extends IModule { float getBatteryLevel(); void setRefreshInterval(int millis); void suscribe(IBatteryListener listener); void unsuscribe(IBatteryListener listener); }
getBatteryLevel()
is used to get he actual level of the smartphone battery.
setRefreshInterval()
sets the interval of time of the battery notifications.
suscribe()
and unsuscribe()
are used to manage the listeners of the battery module. A class that wants to receive notifications of the battery sensor must implement the interface IBatteryListener.class
.
public interface IBatteryListener { void onNewBatteryStatus(int battlevel); }
onNewBatteryStatus()
is called when a new battery status is available.
Obtaining the instance of the module
IBatteryModule batModule = roboboManager.getModuleInstance(IBatteryModule.class);
Current implementation
AndroidBatteryModule:
robobo.module.14=com.mytechia.robobo.framework.sensing.battery.android.AndroidBatteryModule
The javadoc documentation of this module can be found here
Updated