aboutsummaryrefslogtreecommitdiff
path: root/src/Compass.qml
diff options
context:
space:
mode:
authordodoradio <dodoradio@outlook.com>2023-07-09 01:19:34 +0100
committerdodoradio <dodoradio@outlook.com>2023-07-10 14:14:48 +0100
commit16dcaae647c081ba60b239e425b26bf36ca327d3 (patch)
treef94373322980a8df13e8edd8d860548c0c76baff /src/Compass.qml
parent6c6ef8cdb09a2c47b60f4f8de875243b559c9fe4 (diff)
Fork and start work on asteroid-toolwatch
This is meant as a multitool app that currently allows usage of compass and barometer. The app includes a means of 'calibrating' the barometer reading. This is not a system level calibration and only affects the app (or any other apps that choose to use the value I'm setting in dconf). The mechanism was initially inspired by the same feature on Casio's watches: under WearOS, all of Casio's apps use a shared calibration offset for barometer. The calibration aims to rectify the infamous inaccuracy of the android barometer sensor. While the sensors are generally very precise and can sense small changes in air pressure, the sensors often lose calibraton and hence suffer from zero error. This can be somewhat helped by allowing the user to set a zero point - it seems this allowed Casio to make the sensor into an actually useful feature. There was discussion about making this calibration into a system-level feature (for example, as a patch to sensorfw or to QtSensors) but I think it's reasonable to expect the sensor to always return the raw value (even if it is wrong) and then have the calibration as a separate, opt-in feature.
Diffstat (limited to '')
-rw-r--r--src/Compass.qml118
1 files changed, 118 insertions, 0 deletions
diff --git a/src/Compass.qml b/src/Compass.qml
new file mode 100644
index 0000000..48e9557
--- /dev/null
+++ b/src/Compass.qml
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2022 - Darrel Griët <dgriet@gmail.com>
+ * 2017 - Florent Revest <revestflo@gmail.com>
+ * - Niels Tholenaar <info@123quality.nl>
+ *
+ * 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.5
+import org.asteroid.controls 1.0
+import QtSensors 5.3
+import QtGraphicalEffects 1.15
+
+Item {
+ id: compassRoot
+
+ property int rotation: 0;
+ property int calibration: 0;
+ property int ringValueOffset: Math.sqrt(Math.pow(Dims.l(40), 2) / 2);
+
+ Compass {
+ active: true
+ onReadingChanged: {
+ compassRoot.rotation = reading.azimuth;
+ compassRoot.calibration = reading.calibrationLevel;
+ }
+ }
+
+ StatusPage {
+ //% "<h3>No data</h3>Calibrate the sensor by moving it in an ∞ figure."
+ text: qsTrId("id-no-data-calibrate")
+ icon: "ios-infinite-outline"
+ visible: !compassRoot.calibration
+ }
+
+ Item {
+ visible: compassRoot.calibration
+ anchors.fill: parent
+
+ Item {
+ id: centerDisplay
+ anchors.fill: parent
+ Label {
+ id: magneticRotation
+ anchors.centerIn: parent
+ text: compassRoot.rotation
+ font {
+ pixelSize: parent.height / 4
+ capitalization: Font.Capitalize
+ styleName: "SemiCondensed"
+ kerning: true
+ preferShaping: true
+ }
+ }
+ Label {
+ id: degreeSymbol
+ anchors.top: magneticRotation.top
+ anchors.left: magneticRotation.right
+ text: "°"
+ font {
+ pixelSize: parent.height / 4
+ capitalization: Font.Capitalize
+ styleName: "SemiCondensed"
+ kerning: true
+ preferShaping: true
+ }
+ }
+ Image {
+ anchors.top: parent.top
+ anchors.centerIn: parent
+ anchors.verticalCenterOffset: -Dims.l(35)
+ width: Dims.l(10)
+ height: width
+ source: "compass.svg"
+ }
+ }
+
+ Item {
+ anchors.fill: parent
+ rotation: -compassRoot.rotation
+ Repeater {
+ id: outerRing
+ anchors.fill: parent
+ model: 8
+ Label {
+ property var angle: (index / outerRing.count) * 2 * Math.PI
+ property var cardinalDirections: ["N", "NE", "E", "SE", "S", "SW", "W", "NW"]
+ rotation: compassRoot.rotation
+ color: index == 0 ? "#c2620c" : "white"
+ text: cardinalDirections[index]
+ anchors {
+ centerIn: parent
+ verticalCenterOffset: -Math.cos(angle) * Dims.l(40)
+ horizontalCenterOffset: Math.sin(angle) * Dims.l(40)
+ }
+ font {
+ pixelSize: index % 2 ? Dims.l(8) : Dims.l(10)
+ capitalization: Font.Capitalize
+ styleName: "Condensed Bold"
+ kerning: true
+ preferShaping: true
+ }
+ }
+ }
+ }
+ }
+}