Skip to content
This repository was archived by the owner on Jan 28, 2022. It is now read-only.

Commit f87c152

Browse files
authored
fix: QML enum handling and UnitSystem fixes (#476)
Moved UnitSystem enum from ConfigInterface into dedicated enum class for type safe QML integration. Removed enum typedefs for correct QML integration since the strict equality comparison `===` wasn't working in QML! - Cleaned up and improved Config class. - Reading and persisting UnitSystem from config file. - JSON schema definition for unit system - Added unit support for CPU temperature. This closes #442 and #473
1 parent 63514fa commit f87c152

33 files changed

+263
-236
lines changed

basic_ui/settings/System.qml

+28-19
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,25 @@ Rectangle {
4747
triggeredOnStart: true
4848

4949
onTriggered: {
50-
// TODO create a device class instead of launching hard coded shell scripts from QML
50+
// TODO(zehnm) create a device class instead of launching hard coded shell scripts from QML
5151
uptimeValue.text = settingsLauncher.launch("/usr/bin/yio-remote/uptime.sh").trim();
52-
temperatureValue.text = Math.round(parseInt(settingsLauncher.launch("cat /sys/class/thermal/thermal_zone0/temp"))/1000) + "ºC";
52+
// TODO(zehnm) create a sensor class for reading CPU temp instead of launching hard coded shell scripts from QML
53+
var temp = parseInt(settingsLauncher.launch("cat /sys/class/thermal/thermal_zone0/temp")) / 1000
54+
if (Number.isNaN(temp)) {
55+
temp = 36
56+
}
57+
58+
if (config.unitSystem === UnitSystem.IMPERIAL) {
59+
temperatureValue.text = Math.round(temp * 9/5 + 32) + "ºF"
60+
} else {
61+
temperatureValue.text = Math.round(temp) + "ºC"
62+
}
5363
}
5464
}
5565

56-
Component.onCompleted: timer.start()
66+
Component.onCompleted: {
67+
timer.start()
68+
}
5769

5870
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
5971
// UI ELEMENTS
@@ -71,6 +83,8 @@ Rectangle {
7183
color: Style.color.background
7284
}
7385

86+
ButtonGroup { id: radioGroup }
87+
7488
Item {
7589
width: parent.width; height: childrenRect.height + 40
7690

@@ -82,11 +96,12 @@ Rectangle {
8296
font: Style.font.button
8397
}
8498

85-
CheckBox {
99+
RadioButton {
86100
id: metricCheckBox
87101
width: 40; height: 40
88102
anchors { left: parent.left; leftMargin: 20; top: unitText.bottom; topMargin: 20 }
89-
checked: config.unitSystem == 0
103+
checked: config.unitSystem === UnitSystem.METRIC
104+
ButtonGroup.group: radioGroup
90105

91106
indicator: Rectangle {
92107
implicitWidth: 20; implicitHeight: 20
@@ -102,9 +117,8 @@ Rectangle {
102117
}
103118

104119
onCheckedChanged: {
105-
if (checked) {
106-
config.unitSystem = 0;
107-
}
120+
config.unitSystem = checked ? UnitSystem.METRIC : UnitSystem.IMPERIAL
121+
timer.restart()
108122
}
109123

110124
onPressed: {
@@ -123,11 +137,12 @@ Rectangle {
123137
Behavior on opacity { NumberAnimation { duration: 200 } }
124138
}
125139

126-
CheckBox {
140+
RadioButton {
127141
id: imperialCheckBox
128142
width: 40; height: 40
129143
anchors { left: metricCheckBoxText.right; leftMargin: 20; verticalCenter: metricCheckBox.verticalCenter }
130-
checked: config.unitSystem == 1
144+
checked: config.unitSystem === UnitSystem.IMPERIAL
145+
ButtonGroup.group: radioGroup
131146

132147
indicator: Rectangle {
133148
implicitWidth: 20; implicitHeight: 20
@@ -143,12 +158,6 @@ Rectangle {
143158
border { width: 2; color: imperialCheckBox.checked ? Style.color.highlight1 : Style.color.light }
144159
}
145160

146-
onCheckedChanged: {
147-
if (checked) {
148-
config.unitSystem = 1;
149-
}
150-
}
151-
152161
onPressed: {
153162
Haptic.playEffect(Haptic.Click);
154163
}
@@ -211,7 +220,7 @@ Rectangle {
211220
Text {
212221
id: temperatureValue
213222
color: Style.color.text
214-
text: "36ºC"
223+
text: ""
215224
horizontalAlignment: Text.AlignRight
216225
anchors { right: parent.right; rightMargin: 20; verticalCenter: temperatureText.verticalCenter }
217226
font: Style.font.button
@@ -231,10 +240,10 @@ Rectangle {
231240
anchors { top: parent.top; topMargin: 30; left: parent.left; leftMargin: (parent.width - (buttonReboot.width + buttonShutdown.width + 40))/2 }
232241

233242
mouseArea.onClicked: {
234-
// TODO create a framebuffer device class instead of launching hard coded shell scripts from QML
243+
// TODO(zehnm) create a framebuffer device class instead of launching hard coded shell scripts from QML
235244
settingsLauncher.launch("fbv -d 1 $YIO_MEDIA_DIR/splash/bye.png")
236245
console.debug("now reboot")
237-
// TODO create a device class for system reboot instead of launching hard coded shell scripts from QML
246+
// TODO(zehnm) create a device class for system reboot instead of launching hard coded shell scripts from QML
238247
settingsLauncher.launch("reboot");
239248
}
240249
}

basic_ui/settings/Wifi.qml

+18-14
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,15 @@ Item {
159159
Text {
160160
color: Style.color.text
161161
text: {
162-
if (wifi.wifiStatus.signalStrength == SignalStrengthEnum.WEAK || wifi.wifiStatus.signalStrength == SignalStrengthEnum.NONE)
163-
return Style.icon.wifi_1
164-
else if (wifi.wifiStatus.signalStrength == SignalStrengthEnum.OK)
165-
return Style.icon.wifi_2
166-
else if (wifi.wifiStatus.signalStrength == SignalStrengthEnum.GOOD || wifi.wifiStatus.signalStrength == SignalStrengthEnum.EXCELLENT)
167-
return Style.icon.wifi_3
168-
else return ""
162+
switch(wifi.wifiStatus.signalStrength) {
163+
case SignalStrength.EXCELLENT:
164+
case SignalStrength.GOOD:
165+
return Style.icon.wifi_3;
166+
case SignalStrength.OK:
167+
return Style.icon.wifi_2;
168+
default:
169+
return Style.icon.wifi_1;
170+
}
169171
}
170172
renderType: Text.NativeRendering
171173
width: 70; height: 70
@@ -238,13 +240,15 @@ Item {
238240
Text {
239241
color: Style.color.text
240242
text: {
241-
if (wifi.networkScanResult[index].signalStrength == SignalStrengthEnum.WEAK || wifi.networkScanResult[index].signalStrength == SignalStrengthEnum.NONE)
242-
return Style.icon.wifi_1
243-
else if (wifi.networkScanResult[index].signalStrength == SignalStrengthEnum.OK)
244-
return Style.icon.wifi_2
245-
else if (wifi.networkScanResult[index].signalStrength == SignalStrengthEnum.GOOD || wifi.networkScanResult[index].signalStrength == SignalStrengthEnum.EXCELLENT)
246-
return Style.icon.wifi_3
247-
else return ""
243+
switch(wifi.networkScanResult[index].signalStrength) {
244+
case SignalStrength.EXCELLENT:
245+
case SignalStrength.GOOD:
246+
return Style.icon.wifi_3;
247+
case SignalStrength.OK:
248+
return Style.icon.wifi_2;
249+
default:
250+
return Style.icon.wifi_1;
251+
}
248252
}
249253
renderType: Text.NativeRendering
250254
width: 70; height: 70

config-schema.json

+10
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,16 @@
936936
}
937937
}
938938
},
939+
"unit": {
940+
"$id": "#/properties/settings/properties/unit",
941+
"type": "string",
942+
"enum": [
943+
"METRIC",
944+
"IMPERIAL"
945+
],
946+
"title": "Unit system",
947+
"default": "METRIC"
948+
},
939949
"wifitime": {
940950
"$id": "#/properties/settings/properties/wifitime",
941951
"type": "integer",

config.json

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"appUpdateScript": "/opt/yio/scripts/app-update.sh",
2727
"systemUpdateScript": "/opt/yio/scripts/TODO.sh"
2828
},
29+
"unit": "METRIC",
2930
"wifitime": 1740
3031
},
3132
"ui_config": {

dependencies.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
# name: dependency name
44
# separator: colon + optional white space
55
# version: git branch or tag
6-
integrations.library: v0.4.3
6+
integrations.library: v0.5.0

setup/SetupStep3.qml

+9-7
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,15 @@ Item {
122122
Text {
123123
color: Style.color.text
124124
text: {
125-
if (wifi.networkScanResult[index].signalStrength == SignalStrengthEnum.WEAK || wifi.networkScanResult[index].signalStrength == SignalStrengthEnum.NONE)
126-
return Style.icon.wifi_1
127-
else if (wifi.networkScanResult[index].signalStrength == SignalStrengthEnum.OK)
128-
return Style.icon.wifi_2
129-
else if (wifi.networkScanResult[index].signalStrength == SignalStrengthEnum.GOOD || wifi.networkScanResult[index].signalStrength == SignalStrengthEnum.EXCELLENT)
130-
return Style.icon.wifi_3
131-
else return ""
125+
switch(wifi.networkScanResult[index].signalStrength) {
126+
case SignalStrength.EXCELLENT:
127+
case SignalStrength.GOOD:
128+
return Style.icon.wifi_3;
129+
case SignalStrength.OK:
130+
return Style.icon.wifi_2;
131+
default:
132+
return Style.icon.wifi_1;
133+
}
132134
}
133135
renderType: Text.NativeRendering
134136
width: 70; height: 70

setup/SetupStep4Other.qml

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ Rectangle {
4848

4949
let security;
5050
if (passwordField.text == "") {
51-
security = WifiSecurityEnum.NONE_OPEN;
51+
security = WifiSecurity.NONE_OPEN;
5252
} else {
53-
security = WifiSecurityEnum.DEFAULT;
53+
security = WifiSecurity.DEFAULT;
5454
}
5555

5656
wifi.join(name, passwordField.text, security);

sources/bluetooth.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@
3030
static Q_LOGGING_CATEGORY(CLASS_LC, "bluetooth");
3131

3232
BluetoothControl::BluetoothControl(QObject *parent) : QObject(parent) {
33-
qCritical(CLASS_LC) << "Bluetooth starting";
33+
qCInfo(CLASS_LC) << "Bluetooth starting";
3434

3535
// if there is a bluetooth device, let's set up some things
3636
if (m_localDevice.isValid()) {
3737
qCDebug(CLASS_LC) << "Bluetooth init OK";
3838

3939
} else {
40-
qCritical(CLASS_LC) << "Bluetooth device was not found.";
40+
qCCritical(CLASS_LC) << "Bluetooth device was not found.";
4141
Notifications::getInstance()->add(true, tr("Bluetooth device was not found."));
4242
}
4343
}

0 commit comments

Comments
 (0)