diff --git a/qml/Screens/BmsServiceScreen.qml b/qml/Screens/BmsServiceScreen.qml index d43d114..64ea283 100644 --- a/qml/Screens/BmsServiceScreen.qml +++ b/qml/Screens/BmsServiceScreen.qml @@ -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 diff --git a/qml/Screens/TerminalScreen.qml b/qml/Screens/TerminalScreen.qml index 11da120..c8f24ce 100644 --- a/qml/Screens/TerminalScreen.qml +++ b/qml/Screens/TerminalScreen.qml @@ -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 diff --git a/qml/Screens/TimeSettingsScreen.qml b/qml/Screens/TimeSettingsScreen.qml new file mode 100644 index 0000000..ae60e1f --- /dev/null +++ b/qml/Screens/TimeSettingsScreen.qml @@ -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") + } +} diff --git a/qml/Screens/qmldir b/qml/Screens/qmldir index 5771621..73b47d6 100644 --- a/qml/Screens/qmldir +++ b/qml/Screens/qmldir @@ -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 diff --git a/qml/qml_items.qrc b/qml/qml_items.qrc index 57f92e4..18f98ef 100644 --- a/qml/qml_items.qrc +++ b/qml/qml_items.qrc @@ -45,5 +45,6 @@ Screens/FirmwareUpdateScreen.qml Controls/ProgressBar.qml Screens/NetworkSettingsScreen.qml + Screens/TimeSettingsScreen.qml diff --git a/translations/cubo_en.ts b/translations/cubo_en.ts index c9fcea8..44ec989 100644 --- a/translations/cubo_en.ts +++ b/translations/cubo_en.ts @@ -223,6 +223,11 @@ Network settings + + + Time settings + + BmsSettingsScreen @@ -798,21 +803,139 @@ Reconnect to the board if you want to continue working with it. TerminalScreen - + Clear - + Send - + Help + + TimeSettingsScreen + + + Date + + + + + Time + + + + + Day + + + + + Month + + + + + Year + + + + + January + + + + + February + + + + + March + + + + + April + + + + + May + + + + + June + + + + + July + + + + + August + + + + + September + + + + + October + + + + + November + + + + + December + + + + + Hour + + + + + Minute + + + + + Second + + + + + Read from board + + + + + Read from computer + + + + + Write to board + + + Translator diff --git a/translations/cubo_it.ts b/translations/cubo_it.ts index 16ba504..28258c1 100644 --- a/translations/cubo_it.ts +++ b/translations/cubo_it.ts @@ -223,6 +223,11 @@ Network settings + + + Time settings + + BmsSettingsScreen @@ -798,21 +803,139 @@ Reconnect to the board if you want to continue working with it. TerminalScreen - + Clear - + Send - + Help + + TimeSettingsScreen + + + Date + + + + + Time + + + + + Day + + + + + Month + + + + + Year + + + + + January + + + + + February + + + + + March + + + + + April + + + + + May + + + + + June + + + + + July + + + + + August + + + + + September + + + + + October + + + + + November + + + + + December + + + + + Hour + + + + + Minute + + + + + Second + + + + + Read from board + + + + + Read from computer + + + + + Write to board + + + Translator diff --git a/translations/cubo_ru.qm b/translations/cubo_ru.qm index 6d191b2..d7b9f6e 100644 Binary files a/translations/cubo_ru.qm and b/translations/cubo_ru.qm differ diff --git a/translations/cubo_ru.ts b/translations/cubo_ru.ts index f980922..fb805bb 100644 --- a/translations/cubo_ru.ts +++ b/translations/cubo_ru.ts @@ -235,6 +235,11 @@ Network settings Настройки сети + + + Time settings + Настройки времени + BmsSettingsScreen @@ -833,21 +838,139 @@ Reconnect to the board if you want to continue working with it. TerminalScreen - + Clear Очистить - + Send Отправить - + Help Помощь + + TimeSettingsScreen + + + Date + Дата + + + + Time + Время + + + + Day + День + + + + Month + Месяц + + + + Year + Год + + + + January + Январь + + + + February + Февраль + + + + March + Март + + + + April + Апрель + + + + May + Май + + + + June + Июнь + + + + July + Июль + + + + August + Август + + + + September + Сентябрь + + + + October + Октябрь + + + + November + Ноябрь + + + + December + Декабрь + + + + Hour + Час + + + + Minute + Минута + + + + Second + Секунда + + + + Read from board + Прочитать с платы + + + + Read from computer + Прочитать с компьютера + + + + Write to board + Записать на плату + + Translator