Implemented time adjustment on the board

This commit is contained in:
Yury Shuvakin
2022-09-16 06:57:03 +03:00
parent dd63a2bf4c
commit 1d77dcbfcd
9 changed files with 668 additions and 10 deletions

View File

@@ -27,6 +27,10 @@ RowLayout {
property string title: qsTr("Network settings")
}
Screens.TimeSettingsScreen {
id: timeSettingsScreen
property string title: qsTr("Time settings")
}
Layout.fillWidth: true
Layout.fillHeight: true
@@ -36,7 +40,12 @@ RowLayout {
spacing: 20
Repeater {
model: [terminalScreen.title, firmwareUpdateScreen.title, networkSettingsScreen.title]
model: [
terminalScreen.title,
firmwareUpdateScreen.title,
networkSettingsScreen.title,
timeSettingsScreen.title
]
delegate: Controls.LinkLabel {
text: modelData
onClicked: stack.currentIndex = index

View File

@@ -6,6 +6,7 @@ import Controls 1.0 as Controls
import Cubo 1.0
ColumnLayout {
id: root
spacing: 20
Keys.onReturnPressed: sendButton.clicked()
@@ -66,6 +67,7 @@ ColumnLayout {
Connections {
target: BmsInterface.commands()
enabled: root.visible
onPrintReceived: {
outputArea.append(str)
outputArea.cursorPosition = outputArea.length

View File

@@ -0,0 +1,276 @@
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import Controls 1.0 as Controls
import Cubo 1.0
ColumnLayout {
id: root
spacing: 20
GridLayout {
columns: 2
rowSpacing: 20
columnSpacing: 20
Controls.TitleLabel {
text: qsTr("Date")
}
Controls.TitleLabel {
text: qsTr("Time")
}
Controls.Frame {
GridLayout {
anchors.fill: parent
columns: 3
columnSpacing: 10
Controls.SubtitleLabel {
text: qsTr("Day")
Layout.alignment: Qt.AlignCenter
}
Controls.SubtitleLabel {
text: qsTr("Month")
Layout.alignment: Qt.AlignCenter
}
Controls.SubtitleLabel {
text: qsTr("Year")
Layout.alignment: Qt.AlignCenter
}
Controls.LineSeparator {
Layout.fillWidth: true
}
Controls.LineSeparator {
Layout.fillWidth: true
}
Controls.LineSeparator {
Layout.fillWidth: true
}
Tumbler {
id: dayTumbler
model: {
switch (monthTumbler.currentIndex) {
case 0: return range(1, 31)
case 1: return range(1, yearTumbler.model[yearTumbler.currentIndex] % 4 || monthTumbler.currentIndex !== 1 ? 28 : 29)
case 2: return range(1, 31)
case 3: return range(1, 30)
case 4: return range(1, 31)
case 5: return range(1, 30)
case 6: return range(1, 31)
case 7: return range(1, 31)
case 8: return range(1, 30)
case 9: return range(1, 31)
case 10: return range(1, 30)
case 11: return range(1, 31)
default: return range(1, 0)
}
}
delegate: tumblerComponent
Layout.alignment: Qt.AlignCenter
Layout.fillWidth: true
}
Tumbler {
id: monthTumbler
model: [
qsTr("January"),
qsTr("February"),
qsTr("March"),
qsTr("April"),
qsTr("May"),
qsTr("June"),
qsTr("July"),
qsTr("August"),
qsTr("September"),
qsTr("October"),
qsTr("November"),
qsTr("December")
]
delegate: tumblerComponent
Layout.alignment: Qt.AlignCenter
Layout.fillWidth: true
}
Tumbler {
id: yearTumbler
model: range(1970, 230)
delegate: tumblerComponent
Layout.alignment: Qt.AlignCenter
Layout.fillWidth: true
}
}
Layout.fillWidth: true
}
Controls.Frame {
GridLayout {
anchors.fill: parent
columns: 3
columnSpacing: 10
Controls.SubtitleLabel {
text: qsTr("Hour")
Layout.alignment: Qt.AlignCenter
}
Controls.SubtitleLabel {
text: qsTr("Minute")
Layout.alignment: Qt.AlignCenter
}
Controls.SubtitleLabel {
text: qsTr("Second")
Layout.alignment: Qt.AlignCenter
}
Controls.LineSeparator {
Layout.fillWidth: true
}
Controls.LineSeparator {
Layout.fillWidth: true
}
Controls.LineSeparator {
Layout.fillWidth: true
}
Tumbler {
id: hoursTumbler
model: 24
delegate: tumblerComponent
Layout.alignment: Qt.AlignCenter
Layout.fillWidth: true
}
Tumbler {
id: minutesTumbler
model: 60
delegate: tumblerComponent
Layout.alignment: Qt.AlignCenter
Layout.fillWidth: true
}
Tumbler {
id: secondsTumbler
model: 60
delegate: tumblerComponent
Layout.alignment: Qt.AlignCenter
Layout.fillWidth: true
}
}
Layout.fillWidth: true
}
}
RowLayout {
spacing: 20
Controls.OutlineButton {
text: qsTr("Read from board")
onClicked: BmsInterface.commands().sendTerminalCmd("checkUnixTime")
}
Controls.OutlineButton {
text: qsTr("Read from computer")
onClicked: {
const date = new Date()
yearTumbler.currentIndex = date.getFullYear() - 1970
monthTumbler.currentIndex = date.getMonth()
dayTumbler.currentIndex = date.getDate() - 1
hoursTumbler.currentIndex = date.getHours()
minutesTumbler.currentIndex = date.getMinutes()
secondsTumbler.currentIndex = date.getSeconds()
}
}
Controls.Button {
text: qsTr("Write to board")
onClicked: {
const date = new Date()
date.setFullYear(yearTumbler.model[yearTumbler.currentIndex])
date.setMonth(monthTumbler.currentIndex)
date.setDate(dayTumbler.currentIndex + 1)
date.setHours(hoursTumbler.currentIndex)
date.setMinutes(minutesTumbler.currentIndex)
date.setSeconds(secondsTumbler.currentIndex)
BmsInterface.commands().sendTerminalCmd("setUnixTime " + Math.round(date / 1000))
}
}
}
Component {
id: tumblerComponent
Controls.SubtitleLabel {
text: modelData
opacity: 1.0 - Math.abs(Tumbler.displacement) / (Tumbler.tumbler.visibleItemCount / 2)
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
}
Connections {
target: BmsInterface.commands()
enabled: root.visible
onPrintReceived: {
const lines = str.split(/\r?\n/)
for (const line of lines) {
if (line.includes("Year")) {
const value = extractValue(line)
if (value.length === 0) contine
yearTumbler.currentIndex = parseInt(value)
} else if (line.includes("Month")) {
const value = extractValue(line)
if (value.length === 0) contine
monthTumbler.currentIndex = parseInt(value) - 1
} else if (line.includes("Day")) {
const value = extractValue(line)
if (value.length === 0) contine
dayTumbler.currentIndex = parseInt(value) - 1
} else if (line.includes("Hours")) {
const value = extractValue(line)
if (value.length === 0) contine
hoursTumbler.currentIndex = parseInt(value)
} else if (line.includes("Minutes")) {
const value = extractValue(line)
if (value.length === 0) contine
minutesTumbler.currentIndex = parseInt(value)
} else if (line.includes("Seconds")) {
const value = extractValue(line)
if (value.length === 0) contine
secondsTumbler.currentIndex = parseInt(value)
}
}
}
function extractValue(valueHolder) {
const values = valueHolder.split(":")
return values.length < 2 ? "" : values[1].trim()
}
}
function range(startAt, size) {
return [...Array(size).keys()].map(i => i + startAt);
}
onVisibleChanged: if (visible) {
BmsInterface.commands().sendTerminalCmd("checkUnixTime")
}
}

View File

@@ -11,3 +11,4 @@ StatusPopup 1.0 StatusPopup.qml
TerminalScreen 1.0 TerminalScreen.qml
FirmwareUpdateScreen 1.0 FirmwareUpdateScreen.qml
NetworkSettingsScreen 1.0 NetworkSettingsScreen.qml
TimeSettingsScreen 1.0 TimeSettingsScreen.qml

View File

@@ -45,5 +45,6 @@
<file>Screens/FirmwareUpdateScreen.qml</file>
<file>Controls/ProgressBar.qml</file>
<file>Screens/NetworkSettingsScreen.qml</file>
<file>Screens/TimeSettingsScreen.qml</file>
</qresource>
</RCC>