pablojimenezmateo / GodotAndroidBluetoothPlugin

Android Studio project for GodotAndroidBluetooth
35 stars 5 forks source link

Godot Android Bluetooth Plugin

This is the Android Studio project that implements all the logic to use Bluetooth LTE from Godot. Checkout the Godot demo to see a working example.

Software versions

This versions have been tested:

Initialize GodotBluetooth

To use the module functions on your scripts, start the module as follows:


var bluetooth

func _ready():
    if Engine.has_singleton("GodotBluetooth344"):
        GodotBluetooth344 = Engine.get_singleton("GodotBluetooth344")

API

Signals

_on_debug_message

GodotBluetooth344.connect("_on_debug_message", self, "_on_debug_message")

This signal sends extra information from the Android Plugin.

Received arguments:

_on_device_found

GodotBluetooth344.connect("_on_device_found", self, "_on_device_found")

This signal is called every time a new device is found.

Received arguments:

_on_bluetooth_status_change

GodotBluetooth344.connect("_on_bluetooth_status_change", self, "_on_bluetooth_status_change")

This signal is called every time the Bluetooth Status is changed (e.g. changes from On to Off)

Received arguments:

_on_location_status_change

GodotBluetooth344.connect("_on_location_status_change", self, "_on_location_status_change")

This signal is called every time the Location Status is changed (e.g. changes from On to Off)

Received arguments:

_on_connection_status_change

GodotBluetooth344.connect("_on_connection_status_change", self, "_on_connection_status_change")

This signal is called every time the Connection Status is changed (e.g. changes from Connected to Disconnected)

Received arguments:

_on_characteristic_found

GodotBluetooth344.connect("_on_characteristic_found", self, "_on_characteristic_found")

This signal is called every time the we discover a characteristic

Received arguments:

_on_characteristic_finding

GodotBluetooth344.connect("_on_characteristic_finding", self, "_on_characteristic_finding")

This signal is called every time we are querying for characteristics. Note that you cannot use any characteristic that has not been discovered before.

Received arguments:

_on_characteristic_read

GodotBluetooth344.connect("_on_characteristic_read", self, "_on_characteristic_read")

This signal is called every time other device writes to this characteristic.

Note: You can use PoolByteArray to transform the bytes to string:

var string = PoolByteArray(data.bytes).get_string_from_utf8()

Received arguments:

reportDuplicates When set true, devices previously found in a scan will be reported with _on_device_found.


Methods

scan

GodotBluetooth344.scan()

Starts a scan. The results will be delivered by the _on_device_found signal.

Arguments:

Returns:


stopScan

GodotBluetooth344.stopScan()

Stops a scan if there is one in progress.

Arguments:

Returns:

hasLocationPermissions

GodotBluetooth344.hasLocationPermissions()

Checks if we have location permissions.

Arguments:

Returns:


locationStatus

GodotBluetooth344.locationStatus()

Arguments:

Returns:


connect

GodotBluetooth344.connect(address)

Connects to a given device. The result will be delivered by the _on_connection_status_change signal.

Arguments:

Returns:

disconnect

GodotBluetooth344.disconnect()

Disconnects from current device. The result will be delivered by the _on_connection_status_change signal.

Arguments:

Returns:

listServicesAndCharacteristics

GodotBluetooth344.listServicesAndCharacteristics()

Lists all services and characteristics from the connected device. The result will be delivered by the _on_characteristic_found signal.

Note: You cna check if we are still reading characreistics using the _on_characteristic_finding signal.

Arguments:

Returns:

subscribeToCharacteristic

GodotBluetooth344.subscribeToCharacteristic(service_uuid, read_uuid)

Subscribes to a characteristic. From now on, any write to that characteristic will be delivered by the signal _on_characteristic_read.

Arguments:

Returns:

unsubscribeFromCharacteristic

GodotBluetooth344.unsubscribeFromCharacteristic(service_uuid, read_uuid)

Unsubscribes from a characteristic.

Arguments:

Returns:

writeBytesToCharacteristic

GodotBluetooth344.writeBytesToCharacteristic(bytes)

Writes bytes to a characteristic.

Arguments:

Returns:

writeStringToCharacteristic

GodotBluetooth344.writeStringToCharacteristic(string)

Writes a UTF-8 string to a characteristic.

Arguments:

Returns:

readFromCharacteristic

GodotBluetooth344.readFromCharacteristic(service_uuid, read_uuid)

Reads bytes from a characteristic. The result will be sent through the signal _on_characteristic_read.

Arguments:

Returns:

License

The MIT License (MIT)

Copyright (c) 2022 Pablo Jiménez Mateo

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.