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

Commit

Permalink
fix: QML enum handling and UnitSystem fixes (#476)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
zehnm authored Jun 7, 2020
1 parent 63514fa commit f87c152
Show file tree
Hide file tree
Showing 33 changed files with 263 additions and 236 deletions.
47 changes: 28 additions & 19 deletions basic_ui/settings/System.qml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,25 @@ Rectangle {
triggeredOnStart: true

onTriggered: {
// TODO create a device class instead of launching hard coded shell scripts from QML
// TODO(zehnm) create a device class instead of launching hard coded shell scripts from QML
uptimeValue.text = settingsLauncher.launch("/usr/bin/yio-remote/uptime.sh").trim();
temperatureValue.text = Math.round(parseInt(settingsLauncher.launch("cat /sys/class/thermal/thermal_zone0/temp"))/1000) + "ºC";
// TODO(zehnm) create a sensor class for reading CPU temp instead of launching hard coded shell scripts from QML
var temp = parseInt(settingsLauncher.launch("cat /sys/class/thermal/thermal_zone0/temp")) / 1000
if (Number.isNaN(temp)) {
temp = 36
}

if (config.unitSystem === UnitSystem.IMPERIAL) {
temperatureValue.text = Math.round(temp * 9/5 + 32) + "ºF"
} else {
temperatureValue.text = Math.round(temp) + "ºC"
}
}
}

Component.onCompleted: timer.start()
Component.onCompleted: {
timer.start()
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// UI ELEMENTS
Expand All @@ -71,6 +83,8 @@ Rectangle {
color: Style.color.background
}

ButtonGroup { id: radioGroup }

Item {
width: parent.width; height: childrenRect.height + 40

Expand All @@ -82,11 +96,12 @@ Rectangle {
font: Style.font.button
}

CheckBox {
RadioButton {
id: metricCheckBox
width: 40; height: 40
anchors { left: parent.left; leftMargin: 20; top: unitText.bottom; topMargin: 20 }
checked: config.unitSystem == 0
checked: config.unitSystem === UnitSystem.METRIC
ButtonGroup.group: radioGroup

indicator: Rectangle {
implicitWidth: 20; implicitHeight: 20
Expand All @@ -102,9 +117,8 @@ Rectangle {
}

onCheckedChanged: {
if (checked) {
config.unitSystem = 0;
}
config.unitSystem = checked ? UnitSystem.METRIC : UnitSystem.IMPERIAL
timer.restart()
}

onPressed: {
Expand All @@ -123,11 +137,12 @@ Rectangle {
Behavior on opacity { NumberAnimation { duration: 200 } }
}

CheckBox {
RadioButton {
id: imperialCheckBox
width: 40; height: 40
anchors { left: metricCheckBoxText.right; leftMargin: 20; verticalCenter: metricCheckBox.verticalCenter }
checked: config.unitSystem == 1
checked: config.unitSystem === UnitSystem.IMPERIAL
ButtonGroup.group: radioGroup

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

onCheckedChanged: {
if (checked) {
config.unitSystem = 1;
}
}

onPressed: {
Haptic.playEffect(Haptic.Click);
}
Expand Down Expand Up @@ -211,7 +220,7 @@ Rectangle {
Text {
id: temperatureValue
color: Style.color.text
text: "36ºC"
text: ""
horizontalAlignment: Text.AlignRight
anchors { right: parent.right; rightMargin: 20; verticalCenter: temperatureText.verticalCenter }
font: Style.font.button
Expand All @@ -231,10 +240,10 @@ Rectangle {
anchors { top: parent.top; topMargin: 30; left: parent.left; leftMargin: (parent.width - (buttonReboot.width + buttonShutdown.width + 40))/2 }

mouseArea.onClicked: {
// TODO create a framebuffer device class instead of launching hard coded shell scripts from QML
// TODO(zehnm) create a framebuffer device class instead of launching hard coded shell scripts from QML
settingsLauncher.launch("fbv -d 1 $YIO_MEDIA_DIR/splash/bye.png")
console.debug("now reboot")
// TODO create a device class for system reboot instead of launching hard coded shell scripts from QML
// TODO(zehnm) create a device class for system reboot instead of launching hard coded shell scripts from QML
settingsLauncher.launch("reboot");
}
}
Expand Down
32 changes: 18 additions & 14 deletions basic_ui/settings/Wifi.qml
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,15 @@ Item {
Text {
color: Style.color.text
text: {
if (wifi.wifiStatus.signalStrength == SignalStrengthEnum.WEAK || wifi.wifiStatus.signalStrength == SignalStrengthEnum.NONE)
return Style.icon.wifi_1
else if (wifi.wifiStatus.signalStrength == SignalStrengthEnum.OK)
return Style.icon.wifi_2
else if (wifi.wifiStatus.signalStrength == SignalStrengthEnum.GOOD || wifi.wifiStatus.signalStrength == SignalStrengthEnum.EXCELLENT)
return Style.icon.wifi_3
else return ""
switch(wifi.wifiStatus.signalStrength) {
case SignalStrength.EXCELLENT:
case SignalStrength.GOOD:
return Style.icon.wifi_3;
case SignalStrength.OK:
return Style.icon.wifi_2;
default:
return Style.icon.wifi_1;
}
}
renderType: Text.NativeRendering
width: 70; height: 70
Expand Down Expand Up @@ -238,13 +240,15 @@ Item {
Text {
color: Style.color.text
text: {
if (wifi.networkScanResult[index].signalStrength == SignalStrengthEnum.WEAK || wifi.networkScanResult[index].signalStrength == SignalStrengthEnum.NONE)
return Style.icon.wifi_1
else if (wifi.networkScanResult[index].signalStrength == SignalStrengthEnum.OK)
return Style.icon.wifi_2
else if (wifi.networkScanResult[index].signalStrength == SignalStrengthEnum.GOOD || wifi.networkScanResult[index].signalStrength == SignalStrengthEnum.EXCELLENT)
return Style.icon.wifi_3
else return ""
switch(wifi.networkScanResult[index].signalStrength) {
case SignalStrength.EXCELLENT:
case SignalStrength.GOOD:
return Style.icon.wifi_3;
case SignalStrength.OK:
return Style.icon.wifi_2;
default:
return Style.icon.wifi_1;
}
}
renderType: Text.NativeRendering
width: 70; height: 70
Expand Down
10 changes: 10 additions & 0 deletions config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,16 @@
}
}
},
"unit": {
"$id": "#/properties/settings/properties/unit",
"type": "string",
"enum": [
"METRIC",
"IMPERIAL"
],
"title": "Unit system",
"default": "METRIC"
},
"wifitime": {
"$id": "#/properties/settings/properties/wifitime",
"type": "integer",
Expand Down
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"appUpdateScript": "/opt/yio/scripts/app-update.sh",
"systemUpdateScript": "/opt/yio/scripts/TODO.sh"
},
"unit": "METRIC",
"wifitime": 1740
},
"ui_config": {
Expand Down
2 changes: 1 addition & 1 deletion dependencies.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# name: dependency name
# separator: colon + optional white space
# version: git branch or tag
integrations.library: v0.4.3
integrations.library: v0.5.0
16 changes: 9 additions & 7 deletions setup/SetupStep3.qml
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,15 @@ Item {
Text {
color: Style.color.text
text: {
if (wifi.networkScanResult[index].signalStrength == SignalStrengthEnum.WEAK || wifi.networkScanResult[index].signalStrength == SignalStrengthEnum.NONE)
return Style.icon.wifi_1
else if (wifi.networkScanResult[index].signalStrength == SignalStrengthEnum.OK)
return Style.icon.wifi_2
else if (wifi.networkScanResult[index].signalStrength == SignalStrengthEnum.GOOD || wifi.networkScanResult[index].signalStrength == SignalStrengthEnum.EXCELLENT)
return Style.icon.wifi_3
else return ""
switch(wifi.networkScanResult[index].signalStrength) {
case SignalStrength.EXCELLENT:
case SignalStrength.GOOD:
return Style.icon.wifi_3;
case SignalStrength.OK:
return Style.icon.wifi_2;
default:
return Style.icon.wifi_1;
}
}
renderType: Text.NativeRendering
width: 70; height: 70
Expand Down
4 changes: 2 additions & 2 deletions setup/SetupStep4Other.qml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ Rectangle {

let security;
if (passwordField.text == "") {
security = WifiSecurityEnum.NONE_OPEN;
security = WifiSecurity.NONE_OPEN;
} else {
security = WifiSecurityEnum.DEFAULT;
security = WifiSecurity.DEFAULT;
}

wifi.join(name, passwordField.text, security);
Expand Down
4 changes: 2 additions & 2 deletions sources/bluetooth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
static Q_LOGGING_CATEGORY(CLASS_LC, "bluetooth");

BluetoothControl::BluetoothControl(QObject *parent) : QObject(parent) {
qCritical(CLASS_LC) << "Bluetooth starting";
qCInfo(CLASS_LC) << "Bluetooth starting";

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

} else {
qCritical(CLASS_LC) << "Bluetooth device was not found.";
qCCritical(CLASS_LC) << "Bluetooth device was not found.";
Notifications::getInstance()->add(true, tr("Bluetooth device was not found."));
}
}
Expand Down
Loading

0 comments on commit f87c152

Please sign in to comment.