From 3be8d094df5a8280c95d4df51dd20e3b22c9db1c Mon Sep 17 00:00:00 2001 From: dodoradio Date: Sun, 9 Jul 2023 23:06:27 +0100 Subject: 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. --- src/SettingsPage.qml | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) (limited to 'src/SettingsPage.qml') 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) + } + } + } + } } -- cgit v1.2.3-54-g00ecf