IM-TWIN / BLE-Android-Plugin

2 stars 2 forks source link

BLE Android Plugin for Godot Engine

This repository contains an Android plugin that gives the possibility to use BLE in Godot applications. The module to build and use is the one contained in the directory bleframework/.

Setup

General information about Android Studio Version and setup

The BLE Android Plugin consists of an **Android Archive Library (AAR) that is built with Android Studio using the project in this repository. Android Studio projects have many options that must be considered to make the project build successfully. In particular the following variables must be carefully considered:

Installing Android Studio

This project has been created and tested with Android Studio version 4.2.1 and it is recommended to use this version to avoid problems. Go to the download archive and look for version 4.2.1 and download your platform-specific version. The first time you launch Android Studio you have to configure the SDK Platforms and SDK Tools using the SDK manager. To do that choose "configure" option in lower right of the wellcome screen. In the SDK Platform section select version 33, 11, 10 and apply changes. In the SDK Tools section select Android SDK Build tools, NDK, Android SDK command line tools, CMAke, Android SKD Platform Tools (some of these may already be installed) and apply changes.

Building the plugin in Android Studio

After downloading this repository, open the relative folder with Android Studio, and then build the module bleframework. Once the operation is done, you will find the Android archive library (aar archive file) in bleframework/build/outputs/aar/.

Android Environment in Godot

In order to build an Android application, you need to set up the Godot environment as explained here.

Loading the plugin

Move the plugin configuration file (bleframework/bleframework.gdap) and the local binary (bleframework/build/outputs/aar/bleframework-debug.aar) that you generated to the Godot project's res://android/plugins directory (if they do not exist, create them). The Godot editor will automatically parse the .gdap file and show our plugin "BLE Plugin" in the Android export presets window under the Plugins section. Once you enable it, you can use it in your code as explained in the next section.

How to use the plugin

The plugin makes available the main functionalities for an Android device (central) to connect and communicate with a peripheral. The main functionalities are:

To use the plugin in Godot, in your script you have to retrieve the correspondent singleton, as shown below.

if Engine.has_singleton("BLEPlugin"):
    var ble = Engine.get_singleton("BLEPlugin") 
    ble.initialize()

The variable ble is the object that contains all the methods of the Java class, through which you can access the BLE operations.

Since the Android BLE library uses many callbacks in Java, in those cases they carry meaningful information a signal is emitted so that it can also be seen in Godot. To receive these signals and thus perform some actions, the signal has to be connected to a function in the Godot script as shown below.

ble.connect("device_found", self, "_on_dev_found")

In this way, when the signal "device_found" is emitted, the function "_on_dev_found" is instantly executed.

Authors

License

This software is released under MIT license - see the LICENSE file for details.

Funding

This software is part of two projects that have received funding from the European Union’s Horizon 2020 research and innovation programme under grant agreement No 952095 and No 945887

 

from Intrinsic Motivations to Transitional Wearable INtelligent companions for autism spectrum disorder

www.im-twin.eu

 

   PlusMe: Transitional Wearable Companions for the therapy of children with Autism Spectrum   Disorders

   www.plusme-h2020.eu