Skip to content

Commit 1330c8b

Browse files
committed
remove profilemanager.mc & forumsladersettings.mc
1 parent 8b8923f commit 1330c8b

File tree

6 files changed

+126
-147
lines changed

6 files changed

+126
-147
lines changed

source/DeviceManager.mc

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,23 @@ class DeviceManager {
3333
//FLV = [0x24, 0x46, 0x4C, 0x54, 0x2C, 0x34, 0x2A, 0x34, 0x36, 0x0a]b; // $FLT,4*46<lf>
3434

3535
private var
36-
_profileManager as ProfileManager,
3736
_data as DataManager,
3837
_device as Device?,
3938
_service as Service?,
4039
_command as Characteristic?,
4140
_config as Characteristic?,
4241
_scanResult as ScanResult?,
42+
_FL_SERVICE as Uuid?,
43+
_FL_CONFIG as Uuid?,
44+
_FL_COMMAND as Uuid?,
4345
_writeInProgress as Boolean = false,
4446
_configDone as Boolean = false;
4547

4648
//! Constructor
4749
//! @param bleDelegate The BLE delegate which provides the functions for asynchronous BLE callbacks
48-
//! @param profileManager The profileManager class which scans and connects the BLE device
4950
//! @param dataManager The DataManager class which processes the received data stream of the BLE device
50-
public function initialize(bleDelegate as ForumsladerDelegate, profileManager as ProfileManager, dataManager as DataManager) {
51+
public function initialize(bleDelegate as ForumsladerDelegate, dataManager as DataManager) {
5152
_device = null;
52-
_profileManager = profileManager;
5353
_data = dataManager;
5454
bleDelegate.notifyScanResult(self);
5555
bleDelegate.notifyConnection(self);
@@ -155,12 +155,12 @@ class DeviceManager {
155155
//! identify forumslader and get characteristic of it's GATT service
156156
private function setupProfile() as Boolean {
157157
if (null != _device) {
158-
if (_profileManager.isForumslader(_device)) {
159-
_service = (_device as Device).getService(_profileManager.FL_SERVICE);
158+
if (isForumslader(_device)) {
159+
_service = (_device as Device).getService(_FL_SERVICE);
160160
var service = _service;
161161
if (null != service) {
162-
_command = service.getCharacteristic(_profileManager.FL_COMMAND);
163-
_config = service.getCharacteristic(_profileManager.FL_CONFIG);
162+
_command = service.getCharacteristic(_FL_COMMAND);
163+
_config = service.getCharacteristic(_FL_CONFIG);
164164
}
165165
return true;
166166
}
@@ -171,6 +171,45 @@ class DeviceManager {
171171
return false;
172172
}
173173

174+
//! Identify the forumslader type and setup it's UUIDs
175+
//! @param Device to be validated as forumslader
176+
//! @return Boolean to indicate if the device was identified as a forumslader
177+
public function isForumslader(device as Device) as Boolean {
178+
var rc = false;
179+
if (device != null) {
180+
// select FL type
181+
var iter = device.getServices();
182+
for (var r = iter.next(); r != null; r = iter.next())
183+
{
184+
r = r as Service;
185+
if (r != null)
186+
{
187+
if (r.getUuid().equals(FL5_SERVICE))
188+
{
189+
_FL_SERVICE = FL5_SERVICE;
190+
_FL_CONFIG = FL5_RXTX_CHARACTERISTIC;
191+
_FL_COMMAND = FL5_RXTX_CHARACTERISTIC;
192+
rc = true;
193+
$.isV6 = false;
194+
//debug("FLv5 detected");
195+
}
196+
else {
197+
if (r.getUuid().equals(FL6_SERVICE))
198+
{
199+
_FL_SERVICE = FL6_SERVICE;
200+
_FL_CONFIG = FL6_RX_CHARACTERISTIC;
201+
_FL_COMMAND = FL6_TX_CHARACTERISTIC;
202+
rc = true;
203+
$.isV6 = true;
204+
//debug("FLv6 detected");
205+
}
206+
}
207+
}
208+
}
209+
}
210+
return rc;
211+
}
212+
174213
//! Write notification to descriptor to start data stream on forumslader device
175214
private function startDatastreamFL() as Void {
176215
//debug("start datastream");

source/ForumsladerApp.mc

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,31 @@ to do:
77
*/
88

99
import Toybox.Application;
10+
import Toybox.Application.Storage;
1011
import Toybox.BluetoothLowEnergy;
1112
import Toybox.Lang;
1213
import Toybox.WatchUi;
1314
import Toybox.System;
1415

15-
(:debug) function debug(val as String or Char or Number) as Void {
16-
switch(val) {
17-
case instanceof Lang.Number:
18-
System.println(val as Number);
19-
break;
20-
case instanceof Lang.Char:
21-
System.print(val as Char);
22-
break;
23-
case instanceof Lang.String:
24-
System.println(val as String);
25-
break;
16+
var UserSettings as Array = [10, 3, 6, 7, false, false, false];
17+
18+
// settings adjustable by user in garmin mobile app / garmin express
19+
enum {
20+
DisplayField1,
21+
DisplayField2,
22+
DisplayField3,
23+
DisplayField4,
24+
BattCalcMethod,
25+
FitLogging,
26+
DeviceLock
2627
}
27-
}
2828

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

3434
private var
35-
_profileManager as ProfileManager?,
3635
_bleDelegate as ForumsladerDelegate?,
3736
_deviceManager as DeviceManager?,
3837
_dataManager as DataManager?;
@@ -47,12 +46,10 @@ private var
4746
public function onStart(state as Dictionary?) as Void {
4847
//debug("--- started ---");
4948
getUserSettings();
50-
_profileManager = new $.ProfileManager();
5149
_dataManager = new $.DataManager();
5250
_bleDelegate = new $.ForumsladerDelegate();
53-
_deviceManager = new $.DeviceManager(_bleDelegate, _profileManager, _dataManager);
51+
_deviceManager = new $.DeviceManager(_bleDelegate, _dataManager);
5452
BluetoothLowEnergy.setDelegate(_bleDelegate as ForumsladerDelegate);
55-
(_profileManager as ProfileManager).registerProfiles();
5653
(_deviceManager as DeviceManager).startScan();
5754
}
5855

@@ -61,7 +58,6 @@ private var
6158
public function onStop(state as Dictionary?) as Void {
6259
_deviceManager = null;
6360
_bleDelegate = null;
64-
_profileManager = null;
6561
_dataManager = null;
6662
//debug("--- stopped ---");
6763
}
@@ -80,4 +76,34 @@ private var
8076
getUserSettings();
8177
WatchUi.requestUpdate();
8278
}
79+
80+
//! read user settings from GCM properties in UserSettings array
81+
function getUserSettings() as Void {
82+
$.UserSettings[$.DisplayField1] = Application.Properties.getValue("UserSetting1") as Number;
83+
$.UserSettings[$.DisplayField2] = Application.Properties.getValue("UserSetting2") as Number;
84+
$.UserSettings[$.DisplayField3] = Application.Properties.getValue("UserSetting3") as Number;
85+
$.UserSettings[$.DisplayField4] = Application.Properties.getValue("UserSetting4") as Number;
86+
$.UserSettings[$.BattCalcMethod] = Application.Properties.getValue("BatteryCalcMethod") as Boolean;
87+
$.UserSettings[$.FitLogging] = Application.Properties.getValue("FitLogging") as Boolean;
88+
$.UserSettings[$.DeviceLock] = Application.Properties.getValue("DeviceLock") as Boolean;
89+
if ($.UserSettings[$.DeviceLock] == false) {
90+
Storage.deleteValue("MyDevice");
91+
}
92+
//debug("User Settings: " + $.UserSettings.toString());
93+
}
94+
95+
(:debug) function debug(val as String or Char or Number) as Void {
96+
switch(val) {
97+
case instanceof Lang.Number:
98+
System.println(val as Number);
99+
break;
100+
case instanceof Lang.Char:
101+
System.print(val as Char);
102+
break;
103+
case instanceof Lang.String:
104+
System.println(val as String);
105+
break;
106+
}
107+
}
108+
83109
}

source/ForumsladerDelegate.mc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class ForumsladerDelegate extends BluetoothLowEnergy.BleDelegate {
2727
if (_deviceName != null) {
2828
if (_deviceName.equals("FLV6") || _deviceName.equals("FL_BLE")) {
2929
//debug("found FL by Devicename: " + _deviceName);
30+
BluetoothLowEnergy.registerProfile(FL6_profile);
3031
broadcastScanResult(result);
3132
return;
3233
}
@@ -36,6 +37,7 @@ class ForumsladerDelegate extends BluetoothLowEnergy.BleDelegate {
3637
for (var dict = iter.next() as Dictionary; dict != null; dict = iter.next()) {
3738
if (dict.get(:companyId) == 0x4d48) {
3839
//debug("found FL by Company ID");
40+
BluetoothLowEnergy.registerProfile(FL5_profile);
3941
broadcastScanResult(result);
4042
return;
4143
}

source/ForumsladerProfile.mc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import Toybox.BluetoothLowEnergy;
2+
import Toybox.Lang;
3+
4+
//! BLE profiles for Forumslader v5/v6
5+
const
6+
//! Service UUIDs
7+
FL5_SERVICE as Uuid = BluetoothLowEnergy.stringToUuid("0000ffe0-0000-1000-8000-00805f9b34fb"),
8+
FL6_SERVICE as Uuid = BluetoothLowEnergy.stringToUuid("6e40ffe2-b5a3-f393-e0a9-e50e24dcca9e"),
9+
10+
//! Characteristic UUIDs
11+
FL5_RXTX_CHARACTERISTIC as Uuid = BluetoothLowEnergy.stringToUuid("0000ef38-0000-1000-8000-00805f9b34fb"),
12+
FL6_RX_CHARACTERISTIC as Uuid = BluetoothLowEnergy.stringToUuid("6e40ef38-b5a3-f393-e0a9-e50e24dcca9e"),
13+
FL6_TX_CHARACTERISTIC as Uuid = BluetoothLowEnergy.stringToUuid("6e40ef39-b5a3-f393-e0a9-e50e24dcca9e"),
14+
15+
//! profile v5
16+
FL5_profile = {
17+
:uuid => FL5_SERVICE,
18+
:characteristics => [{
19+
:uuid => FL5_RXTX_CHARACTERISTIC,
20+
:descriptors => [BluetoothLowEnergy.cccdUuid()]
21+
}]
22+
},
23+
24+
//! profile v6
25+
FL6_profile = {
26+
:uuid => FL6_SERVICE,
27+
:characteristics => [{
28+
:uuid => FL6_RX_CHARACTERISTIC,
29+
:descriptors => [BluetoothLowEnergy.cccdUuid()]
30+
}, {
31+
:uuid => FL6_TX_CHARACTERISTIC,
32+
:descriptors => [BluetoothLowEnergy.cccdUuid()]
33+
}]
34+
};

source/ForumsladerSettings.mc

Lines changed: 0 additions & 31 deletions
This file was deleted.

source/ProfileManager.mc

Lines changed: 0 additions & 91 deletions
This file was deleted.

0 commit comments

Comments
 (0)