Skip to content

o-bagge/open_earable_flutter

 
 

Repository files navigation

OpenEarable Flutter

This Dart package provides functionality for interacting with OpenEarable devices. It enables you to communicate with OpenEarable devices, control LED colors, control audio, and access raw sensor data.


Get OpenEarable device now!

Permissions

For your app to be able to use Flutter reactive BLE in this package, you need to grant the following permissions:

Android

You need to add the following permissions to your AndroidManifest.xml file:

<uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" android:maxSdkVersion="30" />

If you use BLUETOOTH_SCAN to determine location, modify your AndroidManfiest.xml file to include the following entry:

 <uses-permission android:name="android.permission.BLUETOOTH_SCAN" 
                     tools:remove="android:usesPermissionFlags"
                     tools:targetApi="s" />

If you use location services in your app, remove android:maxSdkVersion="30" from the location permission tags

Android ProGuard rules

In case you are using ProGuard add the following snippet to your proguard-rules.pro file:

-keep class com.signify.hue.** { *; }

This will prevent issues like #131.

iOS

For iOS it is required you add the following entries to the Info.plist file of your app. It is not allowed to access Core BLuetooth without this. See our example app on how to implement this. For more indepth details: Blog post on iOS bluetooth permissions

iOS13 and higher

  • NSBluetoothAlwaysUsageDescription

iOS12 and lower

  • NSBluetoothPeripheralUsageDescription

Getting Started

To get started with the OpenEarable Flutter package, follow these steps:

  1. Installation: Add the package to your pubspec.yaml file:

    dependencies:
      open_earable_flutter: ^1.0.0
  2. Import the package:

    import 'package:open_earable_flutter/open_earable_flutter.dart';
  3. Initialize OpenEarable

    final openEarable = OpenEarable();
  4. Connect to Earable Device

    openEarable.bleManager.startScan();
    
    // Listen for discovered devices
    openEarable.bleManager.scanStream.listen((device) {
      // Handle discovered device
    });
    
    // Connect to a device
    openEarable.bleManager.connectToDevice(device);
    

Usage

  • Read device information:
     final deviceIdentifier = await openEarable.readDeviceIdentifier();
     final deviceGeneration = await openEarable.readDeviceGeneration();
  • Sensors:
    • Configuration of Sensors:
      var config  = OpenEarableSensorConfig(sensorId: 0, samplingRate: 30, latency: 0);
      openEarable.sensorManager.writeSensorConfig(config);
      Please refer to open-earable for a documentation on all possible sensor configurations
    • Subscribing to sensor data with sensor id 0
      openEarable.sensorManager.subscribeToSensorData(0).listen((data) {
        // Handle sensor data
        });
      Sensor data is returned as a dictionary:
        {
        	"sensorId": 0,
        	"timestamp": 163538,
        	"sensorName": "ACC_GYRO_MAG",
        	"ACC": {
        		"units": {"X": "g", "Y": "g", "Z": "g"},
        		"X": 5.255882263183594,
        		"Y": -2.622856855392456,
        		"Z": 8.134146690368652
        	},
        	"GYRO": {
        		"units": {"X": "dps", "Y": "dps", "Z": "dps"},
        		"X": 0.007621999830007553,
        		"Y": -0.030487999320030212,
        		"Z": -0.015243999660015106
        	},
        	"MAG": {
        		"units": {"X": "uT", "Y": "uT", "Z": "uT"},
        		"X": -566.1000366210938,
        		"Y": -95.70000457763672,
        		"Z": -117.30000305175781
        	}
        }
    • Battery Level percentage:
      Stream batteryLevelStream = openEarable.sensorManager.getBatteryLevelStream();
    • Button States:
      • 0: Idle
      • 1: Pressed
      • 2: Held
      Stream buttonStateStream = openEarable.sensorManager.getButtonStateStream();
  • Control built-in LED: This does not work at the moment
    openEarable.rgbLed.writeLedColor(r: 0, g: 255, b: 0);
  • Control audio player:
    • Play WAV files Has not been tested yet dart openEarable.audioPlayer.setWavState(state, name: "audio.wav"); - state: WavAudioPlayerState - name: filename of audio file stored on earable
      • Play Frequency:
          openEarable.audioPlayer.setFrequencyState(
        state, frequency, waveForm);
        • state: WavAudioPlayerState
        • frequency: double
        • waveForm: int
      • Play Jingle:
         openEarable.audioPlayer.setJingleState(state, name: "success.wav")
        • state: WavAudioPlayerState
      • name: filename of jingle stored on earable
    • Put audio player into idle state: dart openEarable.audioPlayer.setIdle()

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dart 41.6%
  • C++ 27.2%
  • CMake 21.9%
  • Ruby 3.3%
  • HTML 2.2%
  • Swift 2.0%
  • Other 1.8%