Skip to content

Commit 7c47077

Browse files
committed
v1.1.0
1 parent 904e926 commit 7c47077

8 files changed

+64
-59
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bin/

.vscode/launch.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
// Verwendet IntelliSense zum Ermitteln möglicher Attribute.
3+
// Zeigen Sie auf vorhandene Attribute, um die zugehörigen Beschreibungen anzuzeigen.
4+
// Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
8+
{
9+
"type": "monkeyc",
10+
"request": "launch",
11+
"name": "Run App",
12+
"stopAtLaunch": false,
13+
"device": "${command:GetTargetDevice}"
14+
},
15+
{
16+
"type": "monkeyc",
17+
"request": "launch",
18+
"name": "Run Tests",
19+
"runTests": true,
20+
"device": "${command:GetTargetDevice}"
21+
}
22+
]
23+
}

manifest.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<!-- PROD -->
99
<!-- iq:application id="f37ce83f-ad98-4708-9741-fa4fa15c0d69" type="datafield" name="@Strings.AppName" entry="ForumsladerApp" launcherIcon="@Drawables.LauncherIcon" minApiLevel="3.1.0" version="1.0.7" -->
1010
<!-- TEST -->
11-
<iq:application id="f37ce83f-ad98-4708-9741-fa4fa15c0d60" type="datafield" name="@Strings.AppName" entry="ForumsladerApp" launcherIcon="@Drawables.LauncherIcon" minApiLevel="3.1.0" version="1.0.7">
11+
<iq:application id="f37ce83f-ad98-4708-9741-fa4fa15c0d69" type="datafield" name="@Strings.AppName" entry="ForumsladerApp" launcherIcon="@Drawables.LauncherIcon" minApiLevel="3.1.0" version="1.1.0">
1212
<!--
1313
Use the following from the Visual Studio Code comand palette to edit
1414
the build targets:

source/DataManager.mc

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ class DataManager {
316316
Application.Properties.setValue("Item3", 6);
317317
Application.Properties.setValue("Item4", 9);
318318
Application.Properties.setValue("BatteryCalcMethod", true);
319-
_view.getUserSettings();
319+
getUserSettings();
320320
}
321321
catch(exception) {
322322
return false;

source/DeviceManager.mc

+11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import Toybox.BluetoothLowEnergy;
22
import Toybox.Lang;
33

4+
var isV6 as Boolean = false;
5+
46
class DeviceManager {
57

68
// threshold rssi for detecting forumslader devices
@@ -113,6 +115,15 @@ class DeviceManager {
113115
private function setupForumslader() as Void {
114116
var device = _device;
115117

118+
// set forumslader v5 / v6 type
119+
if (_profileManager.FL_SERVICE == _profileManager.FL6_SERVICE ) {
120+
isV6 = true;
121+
debug("setup V6");
122+
} else {
123+
isV6 = false;
124+
debug("setup V5");
125+
}
126+
116127
// get characteristics of GATT service
117128
if (null != device) {
118129
_service = device.getService(_profileManager.FL_SERVICE);

source/ForumsladerApp.mc

+5-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ForumsladerApp extends Application.AppBase {
2828
private var _bleDelegate as ForumsladerDelegate?;
2929
private var _deviceManager as DeviceManager?;
3030
private var _dataManager as DataManager?;
31-
31+
3232
//! Constructor
3333
public function initialize() {
3434
AppBase.initialize();
@@ -41,6 +41,7 @@ class ForumsladerApp extends Application.AppBase {
4141
_profileManager = new $.ProfileManager();
4242
_dataManager = new $.DataManager();
4343
_bleDelegate = new $.ForumsladerDelegate(_profileManager as ProfileManager);
44+
// initialize Bluetooth Delegate
4445
_deviceManager = new $.DeviceManager(_bleDelegate as ForumsladerDelegate, _profileManager as ProfileManager, _dataManager as DataManager);
4546
BluetoothLowEnergy.setDelegate(_bleDelegate as ForumsladerDelegate);
4647
(_profileManager as ProfileManager).registerProfiles();
@@ -68,7 +69,8 @@ class ForumsladerApp extends Application.AppBase {
6869
}
6970

7071
//! Handle change of settings by user in GCM while App is running
71-
function onSettingsChanged() {
72-
ForumsladerView.onSettingsChanged();
72+
public function onSettingsChanged() {
73+
getUserSettings();
74+
WatchUi.requestUpdate();
7375
}
7476
}

source/ForumsladerSettings.mc

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Toybox.Application;
2+
import Toybox.Lang;
3+
4+
var userSettings as Array = [10, 3, 6, 7, false];
5+
6+
function getUserSettings() as Void {
7+
userSettings[0] = Application.Properties.getValue("Item1") as Number;
8+
userSettings[1] = Application.Properties.getValue("Item2") as Number;
9+
userSettings[2] = Application.Properties.getValue("Item3") as Number;
10+
userSettings[3] = Application.Properties.getValue("Item4") as Number;
11+
userSettings[4] = Application.Properties.getValue("BatteryCalcMethod") as Boolean;
12+
debug("GCM settings: " + userSettings.toString());
13+
}

source/ForumsladerView.mc

+9-54
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ class ForumsladerView extends WatchUi.SimpleDataField {
1111

1212
private var
1313
_data as DataManager,
14-
_showList as Array<Number> = [10, 3, 6, 7] as Array<Number>, // max 4 fields to show
15-
_coloumbCalc as Boolean = true,
1614
_speed as Float = 0.0, // calculated field from dynamo pulses, poles and wheelsize
1715
_battVoltage as Float = 0.0, // calculated field from cell voltages
1816
_connecting as String,
@@ -23,20 +21,20 @@ class ForumsladerView extends WatchUi.SimpleDataField {
2321
//! @param dataManager The DataManager
2422
public function initialize(dataManager as DataManager) {
2523
SimpleDataField.initialize();
24+
getUserSettings();
2625
label = "Forumslader";
2726
_data = dataManager;
2827
_connecting = WatchUi.loadResource($.Rez.Strings.connecting) as String;
2928
_initializing = WatchUi.loadResource($.Rez.Strings.initializing) as String;
3029
_loadingdata = WatchUi.loadResource($.Rez.Strings.loadingdata) as String;
3130
_displayString = _initializing;
32-
getUserSettings();
3331
}
3432

3533
//! process the $FLx data, calculate and show values every one second
3634
//! @param info The updated Activity.Info object
3735
//! @return String value to display in the simpledatafield
3836
public function compute(info as Info) as Numeric or Duration or String or Null {
39-
37+
4038
_data.tick++; // increase data age seconds counter
4139

4240
if (!isConnected){
@@ -48,12 +46,13 @@ class ForumsladerView extends WatchUi.SimpleDataField {
4846
if (_data.tick <= _data.MAX_AGE_SEC) {
4947

5048
_displayString = "";
49+
var freq = isV6 ? _data.FLdata[FL_frequency] / 10 : _data.FLdata[FL_frequency];
5150

52-
for (var i=0; i < _showList.size(); i++)
51+
for (var i=0; i < userSettings.size() - 1; i++)
5352
{
5453
_displayString += (_displayString.length() > 0) ? " " : "";
5554

56-
switch (_showList[i])
55+
switch (userSettings[i] as Number)
5756
{
5857
case 1: // trip energy
5958
_displayString += (_data.FLdata[FL_tripEnergy] >= 0) ? _data.FLdata[FL_tripEnergy] : "--";
@@ -76,7 +75,7 @@ class ForumsladerView extends WatchUi.SimpleDataField {
7675
break;
7776

7877
case 5: // dynamo impulse frequency
79-
_displayString += (_data.FLdata[FL_frequency] >= 0) ? _data.FLdata[FL_frequency] : "--";
78+
_displayString += freq >= 0 ? freq.toNumber() : "--";
8079
_displayString += "Hz";
8180
break;
8281

@@ -98,7 +97,7 @@ class ForumsladerView extends WatchUi.SimpleDataField {
9897

9998
case 9: // speed
10099
if (_data.FLdata[FL_poles] > 0) {
101-
_speed = _data.FLdata[FL_frequency] / _data.FLdata[FL_poles] * _data.FLdata[FL_wheelsize] / 277.777;
100+
_speed = freq / _data.FLdata[FL_poles] * _data.FLdata[FL_wheelsize] / 277.777;
102101
_displayString += _speed.toNumber();
103102
} else {
104103
_displayString += "--";
@@ -108,11 +107,11 @@ class ForumsladerView extends WatchUi.SimpleDataField {
108107

109108
case 10: // remaining battery capacity
110109
var _capacity = 0;
111-
if (_coloumbCalc) {
110+
if (userSettings[4] == true) { // use coloumb calculation method
112111
var x1 = (_data.FLdata[FL_ccadcValue].toLong() * _data.FLdata[FL_acc2mah].toLong() / 167772.16).toFloat();
113112
var x2 = _data.FLdata[FL_fullChargeCapacity];
114113
_capacity = (x1 / x2).toNumber();
115-
} else {
114+
} else { // use voltage calculation method
116115
_capacity = _data.FLdata[FL_socState];
117116
}
118117
_displayString += (_capacity > 0) ? _capacity : "--";
@@ -135,48 +134,4 @@ class ForumsladerView extends WatchUi.SimpleDataField {
135134

136135
return _displayString;
137136
}
138-
139-
//! Called by app when user made changes to settings in GCM while App is running
140-
public function onSettingsChanged() as Void {
141-
getUserSettings();
142-
}
143-
144-
// Safely read a number value from user settings
145-
private function propertiesGetNumber(p as String) as Number {
146-
var v = Application.Properties.getValue(p);
147-
if ((v == null) || (v instanceof Boolean))
148-
{
149-
v = 0;
150-
}
151-
else if (!(v instanceof Number))
152-
{
153-
v = v as Number;
154-
if (v == null)
155-
{
156-
v = 0;
157-
}
158-
}
159-
return v as Number;
160-
}
161-
162-
// Safely read a boolean value from user settings
163-
public function propertiesGetBoolean(p as String) as Boolean {
164-
var v = Application.Properties.getValue(p);
165-
if ((v == null) || !(v instanceof Boolean))
166-
{
167-
v = false;
168-
}
169-
return v as Boolean;
170-
}
171-
172-
// read the user settings and store locally
173-
public function getUserSettings() as Void {
174-
_showList[0] = propertiesGetNumber("Item1");
175-
_showList[1] = propertiesGetNumber("Item2");
176-
_showList[2] = propertiesGetNumber("Item3");
177-
_showList[3] = propertiesGetNumber("Item4");
178-
debug("Selected items: " + _showList.toString());
179-
_coloumbCalc = propertiesGetBoolean("BatteryCalcMethod");
180-
}
181-
182137
}

0 commit comments

Comments
 (0)