Skip to content

Commit

Permalink
remove profilemanager.mc & forumsladersettings.mc
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberman54 committed Jun 15, 2024
1 parent 8b8923f commit 1330c8b
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 147 deletions.
55 changes: 47 additions & 8 deletions source/DeviceManager.mc
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ class DeviceManager {
//FLV = [0x24, 0x46, 0x4C, 0x54, 0x2C, 0x34, 0x2A, 0x34, 0x36, 0x0a]b; // $FLT,4*46<lf>

private var
_profileManager as ProfileManager,
_data as DataManager,
_device as Device?,
_service as Service?,
_command as Characteristic?,
_config as Characteristic?,
_scanResult as ScanResult?,
_FL_SERVICE as Uuid?,
_FL_CONFIG as Uuid?,
_FL_COMMAND as Uuid?,
_writeInProgress as Boolean = false,
_configDone as Boolean = false;

//! Constructor
//! @param bleDelegate The BLE delegate which provides the functions for asynchronous BLE callbacks
//! @param profileManager The profileManager class which scans and connects the BLE device
//! @param dataManager The DataManager class which processes the received data stream of the BLE device
public function initialize(bleDelegate as ForumsladerDelegate, profileManager as ProfileManager, dataManager as DataManager) {
public function initialize(bleDelegate as ForumsladerDelegate, dataManager as DataManager) {
_device = null;
_profileManager = profileManager;
_data = dataManager;
bleDelegate.notifyScanResult(self);
bleDelegate.notifyConnection(self);
Expand Down Expand Up @@ -155,12 +155,12 @@ class DeviceManager {
//! identify forumslader and get characteristic of it's GATT service
private function setupProfile() as Boolean {
if (null != _device) {
if (_profileManager.isForumslader(_device)) {
_service = (_device as Device).getService(_profileManager.FL_SERVICE);
if (isForumslader(_device)) {
_service = (_device as Device).getService(_FL_SERVICE);
var service = _service;
if (null != service) {
_command = service.getCharacteristic(_profileManager.FL_COMMAND);
_config = service.getCharacteristic(_profileManager.FL_CONFIG);
_command = service.getCharacteristic(_FL_COMMAND);
_config = service.getCharacteristic(_FL_CONFIG);
}
return true;
}
Expand All @@ -171,6 +171,45 @@ class DeviceManager {
return false;
}

//! Identify the forumslader type and setup it's UUIDs
//! @param Device to be validated as forumslader
//! @return Boolean to indicate if the device was identified as a forumslader
public function isForumslader(device as Device) as Boolean {
var rc = false;
if (device != null) {
// select FL type
var iter = device.getServices();
for (var r = iter.next(); r != null; r = iter.next())
{
r = r as Service;
if (r != null)
{
if (r.getUuid().equals(FL5_SERVICE))
{
_FL_SERVICE = FL5_SERVICE;
_FL_CONFIG = FL5_RXTX_CHARACTERISTIC;
_FL_COMMAND = FL5_RXTX_CHARACTERISTIC;
rc = true;
$.isV6 = false;
//debug("FLv5 detected");
}
else {
if (r.getUuid().equals(FL6_SERVICE))
{
_FL_SERVICE = FL6_SERVICE;
_FL_CONFIG = FL6_RX_CHARACTERISTIC;
_FL_COMMAND = FL6_TX_CHARACTERISTIC;
rc = true;
$.isV6 = true;
//debug("FLv6 detected");
}
}
}
}
}
return rc;
}

//! Write notification to descriptor to start data stream on forumslader device
private function startDatastreamFL() as Void {
//debug("start datastream");
Expand Down
60 changes: 43 additions & 17 deletions source/ForumsladerApp.mc
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,31 @@ to do:
*/

import Toybox.Application;
import Toybox.Application.Storage;
import Toybox.BluetoothLowEnergy;
import Toybox.Lang;
import Toybox.WatchUi;
import Toybox.System;

(:debug) function debug(val as String or Char or Number) as Void {
switch(val) {
case instanceof Lang.Number:
System.println(val as Number);
break;
case instanceof Lang.Char:
System.print(val as Char);
break;
case instanceof Lang.String:
System.println(val as String);
break;
var UserSettings as Array = [10, 3, 6, 7, false, false, false];

// settings adjustable by user in garmin mobile app / garmin express
enum {
DisplayField1,
DisplayField2,
DisplayField3,
DisplayField4,
BattCalcMethod,
FitLogging,
DeviceLock
}
}

//! This data field app uses the BLE data interface of a forumslader.
//! The field will pair with the first Forumslader it encounters and will
//! show up to 4 user selectable values every 1 second in a simpledatafield.
class ForumsladerApp extends Application.AppBase {

private var
_profileManager as ProfileManager?,
_bleDelegate as ForumsladerDelegate?,
_deviceManager as DeviceManager?,
_dataManager as DataManager?;
Expand All @@ -47,12 +46,10 @@ private var
public function onStart(state as Dictionary?) as Void {
//debug("--- started ---");
getUserSettings();
_profileManager = new $.ProfileManager();
_dataManager = new $.DataManager();
_bleDelegate = new $.ForumsladerDelegate();
_deviceManager = new $.DeviceManager(_bleDelegate, _profileManager, _dataManager);
_deviceManager = new $.DeviceManager(_bleDelegate, _dataManager);
BluetoothLowEnergy.setDelegate(_bleDelegate as ForumsladerDelegate);
(_profileManager as ProfileManager).registerProfiles();
(_deviceManager as DeviceManager).startScan();
}

Expand All @@ -61,7 +58,6 @@ private var
public function onStop(state as Dictionary?) as Void {
_deviceManager = null;
_bleDelegate = null;
_profileManager = null;
_dataManager = null;
//debug("--- stopped ---");
}
Expand All @@ -80,4 +76,34 @@ private var
getUserSettings();
WatchUi.requestUpdate();
}

//! read user settings from GCM properties in UserSettings array
function getUserSettings() as Void {
$.UserSettings[$.DisplayField1] = Application.Properties.getValue("UserSetting1") as Number;
$.UserSettings[$.DisplayField2] = Application.Properties.getValue("UserSetting2") as Number;
$.UserSettings[$.DisplayField3] = Application.Properties.getValue("UserSetting3") as Number;
$.UserSettings[$.DisplayField4] = Application.Properties.getValue("UserSetting4") as Number;
$.UserSettings[$.BattCalcMethod] = Application.Properties.getValue("BatteryCalcMethod") as Boolean;
$.UserSettings[$.FitLogging] = Application.Properties.getValue("FitLogging") as Boolean;
$.UserSettings[$.DeviceLock] = Application.Properties.getValue("DeviceLock") as Boolean;
if ($.UserSettings[$.DeviceLock] == false) {
Storage.deleteValue("MyDevice");
}
//debug("User Settings: " + $.UserSettings.toString());
}

(:debug) function debug(val as String or Char or Number) as Void {
switch(val) {
case instanceof Lang.Number:
System.println(val as Number);
break;
case instanceof Lang.Char:
System.print(val as Char);
break;
case instanceof Lang.String:
System.println(val as String);
break;
}
}

}
2 changes: 2 additions & 0 deletions source/ForumsladerDelegate.mc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ForumsladerDelegate extends BluetoothLowEnergy.BleDelegate {
if (_deviceName != null) {
if (_deviceName.equals("FLV6") || _deviceName.equals("FL_BLE")) {
//debug("found FL by Devicename: " + _deviceName);
BluetoothLowEnergy.registerProfile(FL6_profile);
broadcastScanResult(result);
return;
}
Expand All @@ -36,6 +37,7 @@ class ForumsladerDelegate extends BluetoothLowEnergy.BleDelegate {
for (var dict = iter.next() as Dictionary; dict != null; dict = iter.next()) {
if (dict.get(:companyId) == 0x4d48) {
//debug("found FL by Company ID");
BluetoothLowEnergy.registerProfile(FL5_profile);
broadcastScanResult(result);
return;
}
Expand Down
34 changes: 34 additions & 0 deletions source/ForumsladerProfile.mc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import Toybox.BluetoothLowEnergy;
import Toybox.Lang;

//! BLE profiles for Forumslader v5/v6
const
//! Service UUIDs
FL5_SERVICE as Uuid = BluetoothLowEnergy.stringToUuid("0000ffe0-0000-1000-8000-00805f9b34fb"),
FL6_SERVICE as Uuid = BluetoothLowEnergy.stringToUuid("6e40ffe2-b5a3-f393-e0a9-e50e24dcca9e"),

//! Characteristic UUIDs
FL5_RXTX_CHARACTERISTIC as Uuid = BluetoothLowEnergy.stringToUuid("0000ef38-0000-1000-8000-00805f9b34fb"),
FL6_RX_CHARACTERISTIC as Uuid = BluetoothLowEnergy.stringToUuid("6e40ef38-b5a3-f393-e0a9-e50e24dcca9e"),
FL6_TX_CHARACTERISTIC as Uuid = BluetoothLowEnergy.stringToUuid("6e40ef39-b5a3-f393-e0a9-e50e24dcca9e"),

//! profile v5
FL5_profile = {
:uuid => FL5_SERVICE,
:characteristics => [{
:uuid => FL5_RXTX_CHARACTERISTIC,
:descriptors => [BluetoothLowEnergy.cccdUuid()]
}]
},

//! profile v6
FL6_profile = {
:uuid => FL6_SERVICE,
:characteristics => [{
:uuid => FL6_RX_CHARACTERISTIC,
:descriptors => [BluetoothLowEnergy.cccdUuid()]
}, {
:uuid => FL6_TX_CHARACTERISTIC,
:descriptors => [BluetoothLowEnergy.cccdUuid()]
}]
};
31 changes: 0 additions & 31 deletions source/ForumsladerSettings.mc

This file was deleted.

91 changes: 0 additions & 91 deletions source/ProfileManager.mc

This file was deleted.

0 comments on commit 1330c8b

Please sign in to comment.