Library for Udoo Blu board
-
Include the library as local library project or add the dependency in your build.gradle.
repositories { maven { url "http://dl.bintray.com/harlem88/maven" } }
...
dependencies { compile 'org.udoo:udooblulib:0.1' }
-
Add in your
AndroidManifest.xml
UdooBluService class<service android:name="org.udoo.udooblulib.service.UdooBluService" android:exported="false" />
-
In your
onCreate
method in Application class, bind theUdooBluManager
.@Override public void onCreate() { super.onCreate(); mUdooBluManager = new UdooBluManager(this); } public UdooBluManager getBluManager(){ return mUdooBluManager; }
-
Connect ble device:
mUdooBluManager.connect(address1, new IBleDeviceListener() { @Override public void onDeviceConnected() { udooBluManager.discoveryServices(address1); } @Override public void onServicesDiscoveryCompleted() { lunchGloveFragment(address1, address2); } @Override public void onDeviceDisconnect() { } });
-
Enable notifications
udooBluManager.enableSensor(address1, UDOOBLESensor.ACCELEROMETER, true); udooBluManager.setNotificationPeriod(address1, UDOOBLESensor.ACCELEROMETER);
-
Listen notifications
udooBluManager.enableNotification(address1, true, UDOOBLESensor.ACCELEROMETER, new OnCharacteristicsListener() { @Override public void onCharacteristicsRead(String uuidStr, byte[] value, int status) { } @Override public void onCharacteristicChanged(String uuidStr, byte[] rawValue) { Point3D point3D = UDOOBLESensor.ACCELEROMETER.convert(rawValue); if (point3D != null) subscriber.onNext(point3D.toFloatArray()); } });
-
Digital write
mUdooBluManager.digitalWrite(address1, IOPIN_VALUE.HIGH, IOPIN.D6);