From b1875b7fa5a908ae171348300e4ed4d283ebf68c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Martign=C3=A8ne?= Date: Tue, 2 Nov 2021 12:29:23 +0100 Subject: [PATCH] Add explicit GUI setting for RTC mode --- src/libty/class_teensy.c | 7 ++--- src/tycommander/board.cc | 27 +++++++++++++++++++- src/tycommander/board.hpp | 9 +++++++ src/tycommander/main.cc | 2 ++ src/tycommander/main_window.cc | 14 ++++++++++ src/tycommander/main_window.hpp | 2 ++ src/tycommander/main_window.ui | 45 ++++++++++++++++++++++++++++++++- 7 files changed, 101 insertions(+), 5 deletions(-) diff --git a/src/libty/class_teensy.c b/src/libty/class_teensy.c index 0e6952ab..59bf1473 100644 --- a/src/libty/class_teensy.c +++ b/src/libty/class_teensy.c @@ -133,9 +133,6 @@ static int teensy_load_interface(ty_board_interface *iface) iface->capabilities |= 1 << TY_BOARD_CAPABILITY_UPLOAD; iface->capabilities |= 1 << TY_BOARD_CAPABILITY_RESET; } - if (iface->model == TY_MODEL_TEENSY_40 || iface->model == TY_MODEL_TEENSY_41 || - iface->model == TY_MODEL_TEENSY_MM) - iface->capabilities |= 1 << TY_BOARD_CAPABILITY_RTC; } break; case TEENSY_USAGE_PAGE_RAWHID: { @@ -163,6 +160,10 @@ static int teensy_load_interface(ty_board_interface *iface) iface->model = TY_MODEL_TEENSY; } + if (iface->model == TY_MODEL_TEENSY_40 || iface->model == TY_MODEL_TEENSY_41 || + iface->model == TY_MODEL_TEENSY_MM) + iface->capabilities |= 1 << TY_BOARD_CAPABILITY_RTC; + iface->class_vtable = &_ty_teensy_class_vtable; return 1; diff --git a/src/tycommander/board.cc b/src/tycommander/board.cc index 8bc5dfed..391626b2 100644 --- a/src/tycommander/board.cc +++ b/src/tycommander/board.cc @@ -102,6 +102,11 @@ void Board::loadSettings(Monitor *monitor) "serialLogSize", static_cast(monitor ? monitor->serialLogSize() : 0)).toULongLong(); serial_rate_ = db_.get("serialRate", 115200).toUInt(); + { + int mode = db_.get("rtcMode", 0).toInt(); + if (mode >= 0 && mode <= (int)RTC_IGNORE) + rtc_mode_ = (RtcMode)mode; + } /* Even if the user decides to enable persistence for ambiguous identifiers, we still don't want to cache the board model. */ @@ -304,7 +309,16 @@ TaskInterface Board::upload(const QString &filename) TaskInterface Board::upload(const vector> &fws) { - return upload(fws, reset_after_ ? 0 : TY_UPLOAD_NORESET); + int flags = 0; + + flags |= reset_after_ ? 0 : TY_UPLOAD_NORESET; + switch (rtc_mode_) { + case RTC_LOCALTIME: {} break; + case RTC_UTC: { flags |= TY_UPLOAD_RTC_UTC; } break; + case RTC_IGNORE: { flags |= TY_UPLOAD_NORTC; } break; + } + + return upload(fws, flags); } TaskInterface Board::upload(const vector> &fws, int flags) @@ -533,6 +547,17 @@ void Board::setSerialLogSize(size_t size) emit settingsChanged(); } +void Board::setRtcMode(RtcMode mode) +{ + if (mode == rtc_mode_) + return; + + rtc_mode_ = mode; + + db_.put("rtcMode", static_cast(mode)); + emit settingsChanged(); +} + TaskInterface Board::startUpload(const QString &filename) { auto task = upload(filename); diff --git a/src/tycommander/board.hpp b/src/tycommander/board.hpp index e90896cc..2ed12af3 100644 --- a/src/tycommander/board.hpp +++ b/src/tycommander/board.hpp @@ -42,6 +42,12 @@ struct BoardInterfaceInfo { bool open; }; +enum RtcMode { + RTC_LOCALTIME, + RTC_UTC, + RTC_IGNORE +}; + class Board : public QObject, public std::enable_shared_from_this { Q_OBJECT @@ -71,6 +77,7 @@ class Board : public QObject, public std::enable_shared_from_this { bool enable_serial_; QString serial_log_dir_; size_t serial_log_size_; + RtcMode rtc_mode_; QString status_text_; QString status_icon_name_; @@ -127,6 +134,7 @@ class Board : public QObject, public std::enable_shared_from_this { bool enableSerial() const { return enable_serial_; } size_t serialLogSize() const { return serial_log_size_; } QString serialLogFilename() const { return serial_log_file_.fileName(); } + RtcMode rtcMode() const { return rtc_mode_; } bool serialOpen() const { return serial_iface_; } bool serialIsSerial() const; @@ -161,6 +169,7 @@ public slots: void setScrollBackLimit(unsigned int limit); void setEnableSerial(bool enable, bool persist = true); void setSerialLogSize(size_t size); + void setRtcMode(RtcMode mode); TaskInterface startUpload(const QString &filename = QString()); TaskInterface startUpload(const std::vector> &fws); diff --git a/src/tycommander/main.cc b/src/tycommander/main.cc index 04dbd53d..e59b599b 100644 --- a/src/tycommander/main.cc +++ b/src/tycommander/main.cc @@ -22,6 +22,7 @@ #include "../libhs/common.h" #include "../libty/class.h" #include "tycommander.hpp" +#include "board.hpp" #ifdef QT_STATIC #include @@ -141,6 +142,7 @@ int main(int argc, char *argv[]) qRegisterMetaType("ty_descriptor"); qRegisterMetaType("SessionPeer::CloseReason"); qRegisterMetaType("uint64_t"); + qRegisterMetaType("RtcMode"); QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); diff --git a/src/tycommander/main_window.cc b/src/tycommander/main_window.cc index 74632d7c..9b2c846b 100644 --- a/src/tycommander/main_window.cc +++ b/src/tycommander/main_window.cc @@ -249,6 +249,10 @@ MainWindow::MainWindow(QWidget *parent) connect(firmwareBrowseButton, &QToolButton::clicked, this, &MainWindow::browseForFirmware); firmwareBrowseButton->setMenu(menuBrowseFirmware); connect(resetAfterCheck, &QCheckBox::clicked, this, &MainWindow::setResetAfterForSelection); + connect(rtcComboBox, static_cast(&QComboBox::currentIndexChanged), this, [=](int idx) { + RtcMode mode = (RtcMode)idx; + setRtcModeForSelection(mode); + }); connect(rateComboBox, &QComboBox::currentTextChanged, this, [=](const QString &str) { unsigned int rate = str.toUInt(); setSerialRateForSelection(rate); @@ -972,6 +976,10 @@ void MainWindow::refreshSettings() firmwarePath->setText(current_board_->firmware()); resetAfterCheck->setChecked(current_board_->resetAfter()); + rtcComboBox->setEnabled(current_board_->hasCapability(TY_BOARD_CAPABILITY_RTC)); + rtcComboBox->blockSignals(true); + rtcComboBox->setCurrentIndex((int)current_board_->rtcMode()); + rtcComboBox->blockSignals(false); rateComboBox->blockSignals(true); rateComboBox->setCurrentText(QString::number(current_board_->serialRate())); rateComboBox->blockSignals(false); @@ -1116,3 +1124,9 @@ void MainWindow::setSerialLogSizeForSelection(int size) for (auto &board: selected_boards_) board->setSerialLogSize(size * 1000); } + +void MainWindow::setRtcModeForSelection(RtcMode mode) +{ + for (auto &board: selected_boards_) + board->setRtcMode(mode); +} diff --git a/src/tycommander/main_window.hpp b/src/tycommander/main_window.hpp index 1f164737..23e398f5 100644 --- a/src/tycommander/main_window.hpp +++ b/src/tycommander/main_window.hpp @@ -24,6 +24,7 @@ class AboutDialog; class ArduinoDialog; class Board; class Monitor; +enum RtcMode; class MainWindow : public QMainWindow, private Ui::MainWindow { Q_OBJECT @@ -133,6 +134,7 @@ private slots: void setScrollBackLimitForSelection(int limit); void setEnableSerialForSelection(bool enable); void setSerialLogSizeForSelection(int size); + void setRtcModeForSelection(RtcMode mode); }; #endif diff --git a/src/tycommander/main_window.ui b/src/tycommander/main_window.ui index 7141f761..790e9c3c 100644 --- a/src/tycommander/main_window.ui +++ b/src/tycommander/main_window.ui @@ -7,7 +7,7 @@ 0 0 558 - 468 + 492 @@ -328,6 +328,49 @@ + + + + + + RTC: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + Local time + + + + + UTC + + + + + Ignore RTC + + + + + +