aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordodoradio <dodoradio@outlook.com>2023-07-09 23:06:27 +0100
committerdodoradio <dodoradio@outlook.com>2023-07-10 22:37:51 +0100
commit3be8d094df5a8280c95d4df51dd20e3b22c9db1c (patch)
tree67839cb644cabc9108f85b5dfb189fa92f87807b
parent16dcaae647c081ba60b239e425b26bf36ca327d3 (diff)
Add altimeter
Asteroid watches don't generally have a pressure sensor, as it isn't generally exposed by android's HAL. Hence we use the basic 12Pa/m relationship to calculate an approximation for altitude from the pressure sensor (barometer) reading. This kind of precision seems appropriate given that a) we don't expect this to be used as a flight computer and b) the android barometer, while precise, isn't super accurate anyway. In order to make the reading a bit more useful, we allow the user to calibrate the current altitude. Since we allow separate calibration of this from the barometer calibration, we use the uncalibrated barometer reading as the input for our calculation.
Diffstat (limited to '')
-rw-r--r--src/Altimeter.qml62
-rw-r--r--src/SettingsPage.qml85
-rw-r--r--src/main.qml5
-rw-r--r--src/resources.qrc1
4 files changed, 153 insertions, 0 deletions
diff --git a/src/Altimeter.qml b/src/Altimeter.qml
new file mode 100644
index 0000000..ae71493
--- /dev/null
+++ b/src/Altimeter.qml
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2023 Arseniy Movshev <dodoradio@outlook.com>
+ * 2021 Timo Könnecke <github.com/eLtMosen>
+ * 2021 Darrel Griët <dgriet@gmail.com>
+ * 2019 Florent Revest <revestflo@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+import QtQuick 2.9
+import QtSensors 5.11
+import org.asteroid.controls 1.0
+import org.asteroid.utils 1.0
+import Nemo.Configuration 1.0
+
+Item {
+ id: altimeterRoot
+
+
+ PressureSensor {
+ id: pressureSensor
+ active: true
+ }
+ IconButton {
+ onClicked: pageStack.push(settingsPage)
+ iconName: "ios-settings-outline"
+ width: parent.width*0.2
+ height: width
+ anchors.horizontalCenter: parent.horizontalCenter
+ anchors.bottom: pressureText.top
+ }
+ Label {
+ id: pressureText
+ anchors.centerIn: parent
+ horizontalAlignment: Text.AlignHCenter
+ text: Math.round(pressureSensor.reading.pressure/12 + altimeterOffset.value)
+ font.pixelSize: parent.height / 4
+ }
+ ConfigurationValue {
+ id: altimeterOffset
+ key: "/org/asteroidos/sensors/altimeter-offset"
+ defaultValue: -8443
+ }
+ Label {
+ anchors.horizontalCenter: parent.horizontalCenter
+ anchors.top: pressureText.bottom
+ horizontalAlignment: Text.AlignHCenter
+ text: "m"
+ font.pixelSize: parent.height / 6
+ }
+}
diff --git a/src/SettingsPage.qml b/src/SettingsPage.qml
index c5c81f1..4d36e7f 100644
--- a/src/SettingsPage.qml
+++ b/src/SettingsPage.qml
@@ -42,6 +42,13 @@ Item {
icon: "ios-settings-outline"
onClicked: pageStack.push(barometerAdjustDialog,{})
}
+ LabeledActionButton {
+ width: parent.width
+ height: width*0.2
+ text: qsTr("Adjust altimeter")
+ icon: "ios-settings-outline"
+ onClicked: pageStack.push(altimeterAdjustDialog,{})
+ }
}
}
PressureSensor {
@@ -53,6 +60,11 @@ Item {
key: "/org/asteroidos/sensors/barometer-offset"
defaultValue: 0
}
+ ConfigurationValue {
+ id: altimeterOffset
+ key: "/org/asteroidos/sensors/altimeter-offset"
+ defaultValue: -8443
+ }
Component {
id: barometerAdjustDialog
Item {
@@ -135,4 +147,77 @@ Item {
}
}
}
+ Component {
+ id: altimeterAdjustDialog
+ Item {
+ id: root
+ Row {
+ id: valueSelector
+ anchors {
+ left: parent.left
+ leftMargin: DeviceInfo.hasRoundScreen ? Dims.w(5) : 0
+ right: parent.right
+ rightMargin: DeviceInfo.hasRoundScreen ? Dims.w(5) : 0
+ verticalCenter: parent.verticalCenter
+ }
+ height: parent.height*0.6
+
+ CircularSpinner {
+ id: thousandsSelector
+ height: parent.height
+ width: parent.width/3
+ model: 10
+ showSeparator: false
+ delegate: SpinnerDelegate { text: index }
+ }
+ CircularSpinner {
+ id: hundredsSelector
+ height: parent.height
+ width: parent.width/4
+ model: 10
+ showSeparator: false
+ delegate: SpinnerDelegate { text: index }
+ }
+ CircularSpinner {
+ id: tensSelector
+ height: parent.height
+ width: parent.width/4
+ model: 10
+ delegate: SpinnerDelegate { text: index }
+ }
+ CircularSpinner {
+ id: onesSelector
+ height: parent.height
+ width: parent.width/4
+ model: 10
+ showSeparator: true
+ delegate: SpinnerDelegate { text: index }
+ }
+ }
+
+ Component.onCompleted: {
+ var currValue = Math.round(altimeterOffset.value + pressureSensor.reading.pressure/12);
+ console.log(currValue)
+ thousandsSelector.currentIndex = Math.floor((currValue/1000))
+ hundredsSelector.currentIndex = Math.floor((currValue/100)%10)
+ tensSelector.currentIndex = Math.floor((currValue/10)%10)
+ onesSelector.currentIndex = Math.floor((currValue)%10)
+ }
+
+ IconButton {
+ iconName: "ios-checkmark-circle-outline"
+ anchors {
+ bottom: parent.bottom
+ horizontalCenter: parent.horizontalCenter
+ bottomMargin: Dims.iconButtonMargin
+ }
+
+ onClicked: {
+ var newValue = thousandsSelector.currentIndex*1000 + hundredsSelector.currentIndex*100 + tensSelector.currentIndex*10 + onesSelector.currentIndex
+ altimeterOffset.value = newValue - Math.round(pressureSensor.reading.pressure/12)
+ pageStack.pop(pageStack.currentLayer)
+ }
+ }
+ }
+ }
}
diff --git a/src/main.qml b/src/main.qml
index 5471752..2457d8c 100644
--- a/src/main.qml
+++ b/src/main.qml
@@ -55,6 +55,11 @@ Application {
width: pv.width
property string name: qsTr("Barometer")
}
+ Altimeter {
+ height: pv.height
+ width: pv.width
+ property string name: qsTr("Altimeter")
+ }
}
path: Path {
diff --git a/src/resources.qrc b/src/resources.qrc
index 804fc9e..6b7d9fa 100644
--- a/src/resources.qrc
+++ b/src/resources.qrc
@@ -1,6 +1,7 @@
<RCC>
<qresource prefix="/">
<file>main.qml</file>
+ <file>Altimeter.qml</file>
<file>Compass.qml</file>
<file>Barometer.qml</file>
<file>compass.svg</file>