Skip to content

Classes description

Andrew Laptev edited this page Sep 1, 2022 · 1 revision

This section describes the functional modules of the application and the classes (Activity) that they consist of.

Only methods that contain application-specific logic are considered, i.e. standard methods onCreate(), onResume(), etc., not carrying specific logic in themselves, will not be described.

Classes, methods and functions (or part of the method) of rendering the application interface are not considered in detail, because this is a simple basic interface made for a prototype.

ble_light

This functional module is the main one in the operation of the application and implements the user (User mode) mode of operation of the application.

MainActivity

The main class of the application, it contains entrypoint, access to settings, advanced mode, and it is from it that device scanning is started with subsequent connection

Protected methods:

  • onCreate - calls private methods for initializing, configuring and scanning Bluetooth, as well as access rights for Bluetooth and checking for BLE support.

Private methods:

  • getBluetoothAdapterAndLeScanner - initializes objects of the Bluetooth Adapter and Bluetooth Le Scanner classes
  • scanBleDevices - starts scanning Bluetooth devices with a certain scan_period time, passes a list of device addresses to the LightManageActivity class
  • meanRSSI - calculates the average value of the RSSI signal strength from the input array of values
  • loadSettings - loads the settings (scan_period) from root_preferences.xml

Inner classes:

  • Kalman - the class implementing the Kalman filter has one public method filter(int init_rssi, ArrayList<Integer> rssi_list), which directly performs filtering

BluetoothLeService

A class containing all the necessary methods for creating and managing Bluetooth connections.

Public methods:

  • initialize - initializes an object of the BluetoothAdapter class
  • connect - connects a Bluetooth device to GATT at the specified MAC address
  • multiconnect - connects to several GATT Bluetooth devices at once using the specified list of MAC addresses
  • disconnect - disconnects from one or several Bluetooth devices at once
  • сlose - closes the connection/GATT connections of Bluetooth devices
  • readCharacteristic - reads the value of a certain GATT characteristic of one Bluetooth device or several at once
  • writeCharacteristic - writes a value to a specific GATT characteristic of one Bluetooth device or several at once
  • setCharacteristicNotification - sets or disables notification for a specific GATT characteristic of one Bluetooth device or several at once
  • getSupportedGattServices - returns a list of available GATT Bluetooth device services

Private methods:

  • loadSettings - loads the settings (reconnection_attempts) from root_preferences.xml

Inner classes:

  • BluetoothGattExt - class that is an extension of the BluetoothGatt class. Connects the Bluetooth device and the BluetoothGatt object more closely, because the standard BluetoothGatt can connect to multiple devices, which does not provide data exchange with multiple devices at once.

LightManageActivity

A class responsible for authentication and control of light modes on a connected Bluetooth device (services Authentication and Light manage). Authentication is only needed to access the values entry in the Level of light characteristic for controlling light modes, i.e. you can connect to the GATT of the BLightESP32 device and see its services and characteristics, but without authentication (access_token) through the Authorization data characteristic, it will be impossible to control the light mode.

Protected methods:

  • onCreate - performs initial calculations of the step of changing the light mode based on the selected settings, initializes the visual interface for selecting the mode, initializes the connection to Bluetooth devices BLightESP32

Private methods:

  • initServiceConnection - connects to Bluetooth devices, also defines a callback method for reconnecting if it is not possible to connect the first time
  • authDataSending - passes authentication data (access_token) to the Authorization data characteristic for future access to recording light mode values in the Level of light characteristic
  • loadSettings - loads the settings (access_token, effect_color_temp_min_key, effect_color_temp_max_key) from root_preferences.xml

SettingsActivity

A class that implements an interface for user interaction with application settings via root_preferences.xml, allows you to reset the settings to the default values. Basically, this class contains visual functionality, so it will not be described in detail.

dev_mode

This module implements the advanced mode (Developer mode) of using the application.

MainActivityDev

The main class for interacting with Bluetooth devices implements a graphical interface for representing all available devices within Bluetooth range.

Protected methods:

  • onCreate - Calls private methods for initializing, configuring and scanning Bluetooh, defines callback functions for the Filter ON/OFF and Multiple connect buttons calls private methods for initializing, configuring and scanning Bluetooh, defines callback functions for the Filter ON/OFF and Multiple connect buttons

Private methods:

  • getBTDeviceType - determines the type of the selected Bluetooth device before connecting directly
  • getBluetoothAdapterAndLeScanner - initializes objects of the BluetoothAdapter and BluetoothLeScanner classes
  • scanLeDevice - the SCAN button starts scanning devices until the STOP button is pressed

Inner classes:

  • BluetoothDeviceExt - a class that is an extension of the BluetoothDevice class. Allows you to more closely link a Bluetooth device and its RSSI

ConnectionActivityDev

This class implements a mechanism for connecting to a Bluetooth device, similar to the LightManageActivity class, only for one device. Builds a graphical interface for direct interaction with the services and characteristics of the GATT device through text dialog boxes

MultiConnectionActivityDev

This class implements a mechanism for connecting to a Bluetooth device, similar to the LightManageActivity class, to several BLightESP32 devices at once. Builds a single graphical interface for direct interaction with GATT services and characteristics of all devices at once through text dialog boxes

gatt_attr

This module contains classes for storing collections (dictionaries) UUID GATT matches of services, characteristics, descriptors and their names.

AllGattServices

Contains a dictionary of service names and their corresponding UUIDs

AllGattCharacteristics

Contains a dictionary of feature names and their corresponding UUIDs

AllGattDescriptors

Contains a dictionary of descriptor names and their corresponding UUIDs

light_picker

This module contains the implementation of a graphical interface for selecting the light mode in the user mode (User mode) of the application. Implementation by modification of the library Pikolo