From 94ee707bfe8ea7535b42fd2031a5f94bdef84300 Mon Sep 17 00:00:00 2001 From: Miikasda <47296738+miikasda@users.noreply.github.com> Date: Mon, 22 Jul 2024 22:31:02 +0300 Subject: [PATCH 1/2] Add voltage and movement information to PlotDataPage This was proposed in #8 --- qml/pages/GetDataPage.qml | 2 ++ qml/pages/PlotDataPage.qml | 39 +++++++++++++++++++++++++++++++++- qml/pages/SelectDevicePage.qml | 4 +++- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/qml/pages/GetDataPage.qml b/qml/pages/GetDataPage.qml index 5933174..6e76026 100644 --- a/qml/pages/GetDataPage.qml +++ b/qml/pages/GetDataPage.qml @@ -265,7 +265,9 @@ Page { } else if (data[0] === "extra_data") { // Update voltage and movement counter db.setVoltage(selectedDevice.deviceAddress, data[1]) + selectedDevice.deviceVoltage = data[1] db.setMovement(selectedDevice.deviceAddress, data[2]) + selectedDevice.deviceMovement = data[2] } else if (data[0] === "failed") { loadingScreen.running = false; failureOverlay.visible = true; diff --git a/qml/pages/PlotDataPage.qml b/qml/pages/PlotDataPage.qml index 0f6da45..4c4afba 100644 --- a/qml/pages/PlotDataPage.qml +++ b/qml/pages/PlotDataPage.qml @@ -1,6 +1,6 @@ /* Skruuvi - Reader for Ruuvi sensors - Copyright (C) 2023 Miika Malin + Copyright (C) 2023-2024 Miika Malin 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 @@ -123,6 +123,43 @@ Page { text: selectedDevice.deviceName } + Row { + spacing: Theme.paddingSmall + anchors.left: parent.left + anchors.leftMargin: leftMargin + + Image { + id: batteryIcon + source: "image://theme/icon-m-battery" + width: Theme.iconSizeSmall + height: Theme.iconSizeSmall + anchors.verticalCenter: parent.verticalCenter + } + + Label { + id: voltageLabel + text: selectedDevice.deviceVoltage + " V" + anchors.verticalCenter: parent.verticalCenter + color: Theme.highlightColor + } + + Image { + id: movementIcon + source: "image://theme/icon-s-sync" + width: Theme.iconSizeSmall + height: Theme.iconSizeSmall + anchors.verticalCenter: parent.verticalCenter + } + + Label { + id: movementLabel + text: selectedDevice.deviceMovement + " Moves" + font.pixelSize: Theme.fontSizeSmall + anchors.verticalCenter: parent.verticalCenter + color: Theme.highlightColor + } + } + Label { id: deviceAddressLabel leftPadding: leftMargin diff --git a/qml/pages/SelectDevicePage.qml b/qml/pages/SelectDevicePage.qml index 5ac660d..a79ab2a 100644 --- a/qml/pages/SelectDevicePage.qml +++ b/qml/pages/SelectDevicePage.qml @@ -240,7 +240,9 @@ Page { onClicked: { var selectedDevice = { deviceName: model.deviceName, - deviceAddress: model.deviceAddress + deviceAddress: model.deviceAddress, + deviceVoltage: model.deviceVoltage, + deviceMovement: model.deviceMovement } // On default show last 24h data var currentTime = Math.floor(Date.now() / 1000); From 6e38501489d58beabb39cc252a76326e738454dc Mon Sep 17 00:00:00 2001 From: Miikasda <47296738+miikasda@users.noreply.github.com> Date: Tue, 23 Jul 2024 23:01:19 +0300 Subject: [PATCH 2/2] Add support for time selection in data plotting --- qml/pages/PlotDataPage.qml | 67 +++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/qml/pages/PlotDataPage.qml b/qml/pages/PlotDataPage.qml index 4c4afba..e69b03e 100644 --- a/qml/pages/PlotDataPage.qml +++ b/qml/pages/PlotDataPage.qml @@ -22,6 +22,7 @@ import Sailfish.Share 1.0 import "../modules/GraphData" Page { + id: plotDataPage property var startTime: pageStack.pop().startTime property var endTime: pageStack.pop().endTime @@ -34,15 +35,9 @@ Page { property var humidityData: [] property var pressureData: [] - function calculateUnixTimestamp(day, month, year, start) { + function calculateUnixTimestamp(minute, hour, day, month, year) { var date = new Date(year, month - 1, day); - if (start) { - // Set the time to the start of the day (00:00:00) - date.setHours(0, 0, 0, 0); - } else { - // Set the time to the end of the day (23:59:59) - date.setHours(23, 59, 59, 999); - } + date.setHours(hour, minute, 0, 0); var unixTimestamp = Math.floor(date.getTime() / 1000); return unixTimestamp; } @@ -250,22 +245,29 @@ Page { anchors.top: parent.top width: parent.width - leftMargin - rightMargin anchors.horizontalCenter: parent.horizontalCenter - text: "Start date" + text: "Start time" property bool clicked: false onClicked: { - var dialog = pageStack.push(startPicker, {}) - dialog.accepted.connect(function() { - startDateButton.text = "Start date: " + dialog.dateText - startTime = calculateUnixTimestamp(dialog.day, dialog.month, dialog.year, true) - startDateButton.clicked = true + var startDatePicker = pageStack.push("Sailfish.Silica.DatePickerDialog", {}) + startDatePicker.accepted.connect(function() { + // Ask for time + var startTimePicker = pageStack.push("Sailfish.Silica.TimePickerDialog", { + hourMode: DateTime.TwentyFourHours, + hour: 0, + minute: 0 + }) + // Set plotDataPage as return destination on accept, + // otherwise we will return to datepicker + startTimePicker.acceptDestinationAction = PageStackAction.Pop + startTimePicker.acceptDestination = plotDataPage + startTimePicker.accepted.connect(function() { + startDateButton.text = "Start time: " + startDatePicker.dateText + " " + startTimePicker.timeText + startTime = calculateUnixTimestamp(startTimePicker.minute, startTimePicker.hour, startDatePicker.day, startDatePicker.month, startDatePicker.year) + startDateButton.clicked = true + }) }) } - - Component { - id: startPicker - DatePickerDialog {} - } } // Whitespace inbetween buttons @@ -281,22 +283,27 @@ Page { anchors.top: whiteSpace.bottom width: parent.width - leftMargin - rightMargin anchors.horizontalCenter: parent.horizontalCenter - text: "End date" + text: "End time" property bool clicked: false onClicked: { - var dialog = pageStack.push(endPicker, {}) - dialog.accepted.connect(function() { - endDateButton.text = "End date: " + dialog.dateText - endTime = calculateUnixTimestamp(dialog.day, dialog.month, dialog.year, false) - endDateButton.clicked = true + var endDatePicker = pageStack.push("Sailfish.Silica.DatePickerDialog", {}) + endDatePicker.accepted.connect(function() { + // Ask for time + var endTimePicker = pageStack.push("Sailfish.Silica.TimePickerDialog", { + hourMode: DateTime.TwentyFourHours, + hour: 23, + minute: 59 + }) + endTimePicker.acceptDestinationAction = PageStackAction.Pop + endTimePicker.acceptDestination = plotDataPage + endTimePicker.accepted.connect(function() { + endDateButton.text = "End time: " + endDatePicker.dateText + " " + endTimePicker.timeText + endTime = calculateUnixTimestamp(endTimePicker.minute, endTimePicker.hour, endDatePicker.day, endDatePicker.month, endDatePicker.year) + endDateButton.clicked = true + }) }) } - - Component { - id: endPicker - DatePickerDialog {} - } } } }