diff --git a/src/libty/class_teensy.c b/src/libty/class_teensy.c index 0e6952a..59bf147 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 8bc5dfe..391626b 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 e90896c..2ed12af 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 04dbd53..e59b599 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 74632d7..4308c4c 100644 --- a/src/tycommander/main_window.cc +++ b/src/tycommander/main_window.cc @@ -972,6 +972,10 @@ void MainWindow::refreshSettings() firmwarePath->setText(current_board_->firmware()); resetAfterCheck->setChecked(current_board_->resetAfter()); + rtcLayout->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); diff --git a/src/tycommander/main_window.ui b/src/tycommander/main_window.ui index 7141f76..790e9c3 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 + + + + + +