Skip to content

Commit

Permalink
Add explicit GUI setting for RTC mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Koromix committed Nov 2, 2021
1 parent 2098ce9 commit b1875b7
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/libty/class_teensy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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;
Expand Down
27 changes: 26 additions & 1 deletion src/tycommander/board.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ void Board::loadSettings(Monitor *monitor)
"serialLogSize",
static_cast<quint64>(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. */
Expand Down Expand Up @@ -304,7 +309,16 @@ TaskInterface Board::upload(const QString &filename)

TaskInterface Board::upload(const vector<shared_ptr<Firmware>> &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<shared_ptr<Firmware>> &fws, int flags)
Expand Down Expand Up @@ -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<int>(mode));
emit settingsChanged();
}

TaskInterface Board::startUpload(const QString &filename)
{
auto task = upload(filename);
Expand Down
9 changes: 9 additions & 0 deletions src/tycommander/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Board> {
Q_OBJECT

Expand Down Expand Up @@ -71,6 +77,7 @@ class Board : public QObject, public std::enable_shared_from_this<Board> {
bool enable_serial_;
QString serial_log_dir_;
size_t serial_log_size_;
RtcMode rtc_mode_;

QString status_text_;
QString status_icon_name_;
Expand Down Expand Up @@ -127,6 +134,7 @@ class Board : public QObject, public std::enable_shared_from_this<Board> {
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;
Expand Down Expand Up @@ -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<std::shared_ptr<Firmware>> &fws);
Expand Down
2 changes: 2 additions & 0 deletions src/tycommander/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "../libhs/common.h"
#include "../libty/class.h"
#include "tycommander.hpp"
#include "board.hpp"

#ifdef QT_STATIC
#include <QtPlugin>
Expand Down Expand Up @@ -141,6 +142,7 @@ int main(int argc, char *argv[])
qRegisterMetaType<ty_descriptor>("ty_descriptor");
qRegisterMetaType<SessionPeer::CloseReason>("SessionPeer::CloseReason");
qRegisterMetaType<uint64_t>("uint64_t");
qRegisterMetaType<RtcMode>("RtcMode");

QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

Expand Down
14 changes: 14 additions & 0 deletions src/tycommander/main_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<void(QComboBox::*)(int)>(&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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
2 changes: 2 additions & 0 deletions src/tycommander/main_window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class AboutDialog;
class ArduinoDialog;
class Board;
class Monitor;
enum RtcMode;

class MainWindow : public QMainWindow, private Ui::MainWindow {
Q_OBJECT
Expand Down Expand Up @@ -133,6 +134,7 @@ private slots:
void setScrollBackLimitForSelection(int limit);
void setEnableSerialForSelection(bool enable);
void setSerialLogSizeForSelection(int size);
void setRtcModeForSelection(RtcMode mode);
};

#endif
45 changes: 44 additions & 1 deletion src/tycommander/main_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>558</width>
<height>468</height>
<height>492</height>
</rect>
</property>
<property name="contextMenuPolicy">
Expand Down Expand Up @@ -328,6 +328,49 @@
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="rtcLayout">
<item>
<widget class="QLabel" name="label_13">
<property name="text">
<string>RTC:</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QComboBox" name="rtcComboBox">
<item>
<property name="text">
<string>Local time</string>
</property>
</item>
<item>
<property name="text">
<string>UTC</string>
</property>
</item>
<item>
<property name="text">
<string>Ignore RTC</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
Expand Down

0 comments on commit b1875b7

Please sign in to comment.