diff --git a/app/gui/oven_control/config.cpp b/app/gui/oven_control/config.cpp index 15aace2..527c070 100644 --- a/app/gui/oven_control/config.cpp +++ b/app/gui/oven_control/config.cpp @@ -265,7 +265,6 @@ bool Config::loadFavorite(void){ itemp = strTemp.toInt(&rst,10); if(rst && itemp < (uint32_t)config_invalid) { m_setFavorite.insert(itemp); - qDebug()<< "load favorite index " << itemp; } } file.close(); @@ -328,9 +327,6 @@ void Config::execConfigWindow(QWidget *parent, Define::ConfigType idx){ QDialog *dlg; bool bUsbDetect = false; switch(idx){ - case config_datetime: - dlg = new ConfigDateTimeDlg(parent); - break; case config_language: dlg = new ConfigLanguageDlg(parent); break; diff --git a/app/gui/oven_control/config.h b/app/gui/oven_control/config.h index 8ed0cc7..8d06e6f 100644 --- a/app/gui/oven_control/config.h +++ b/app/gui/oven_control/config.h @@ -404,6 +404,7 @@ public: static QString getTempString(int cel_temp); + void execConfigWindow(QWidget *parent, Define::ConfigType idx); diff --git a/app/gui/oven_control/configdatetimedlg.cpp b/app/gui/oven_control/configdatetimedlg.cpp index 74a8e35..d596982 100644 --- a/app/gui/oven_control/configdatetimedlg.cpp +++ b/app/gui/oven_control/configdatetimedlg.cpp @@ -1,5 +1,8 @@ +#include #include "configdatetimedlg.h" #include "ui_configdatetimedlg.h" +#include "system.h" + ConfigDateTimeDlg::ConfigDateTimeDlg(QWidget *parent) : QDialog(parent), @@ -9,6 +12,14 @@ ConfigDateTimeDlg::ConfigDateTimeDlg(QWidget *parent) : this->setWindowFlags( Qt::FramelessWindowHint); this->setAttribute( Qt::WA_DeleteOnClose); ui->ctrSpBxYear->setFormatterWidth(4); + QDateTime dt_tm = QDateTime::currentDateTime(); + QDate dt_ = dt_tm.date(); + QTime tm_ = dt_tm.time(); + ui->ctrSpBxYear->setValue(dt_.year()); + ui->ctrSpBxMonth->setValue(dt_.month()); + ui->ctrSpBxDay->setValue(dt_.day()); + ui->ctrSpBxHour->setValue(tm_.hour()); + ui->ctrSpBxMin->setValue(tm_.minute()); } ConfigDateTimeDlg::~ConfigDateTimeDlg() @@ -18,6 +29,15 @@ ConfigDateTimeDlg::~ConfigDateTimeDlg() void ConfigDateTimeDlg::on_ctrBtnOk_clicked() { + time_t tm_t; + QDate dt_(ui->ctrSpBxYear->value(), ui->ctrSpBxMonth->value(), ui->ctrSpBxDay->value()); + QTime tm_(ui->ctrSpBxHour->value(), ui->ctrSpBxMin->value()); + QDateTime dt_tm; + dt_tm.setTime(tm_); + dt_tm.setDate(dt_); + tm_t = (time_t)dt_tm.toTime_t(); + System::setRtcTime(dt_tm); + stime(&tm_t); this->accept(); } diff --git a/app/gui/oven_control/configdatetimedlg.h b/app/gui/oven_control/configdatetimedlg.h index dda080b..8aa2d9a 100644 --- a/app/gui/oven_control/configdatetimedlg.h +++ b/app/gui/oven_control/configdatetimedlg.h @@ -3,10 +3,12 @@ #include + namespace Ui { class ConfigDateTimeDlg; } + class ConfigDateTimeDlg : public QDialog { Q_OBJECT diff --git a/app/gui/oven_control/configwindow.cpp b/app/gui/oven_control/configwindow.cpp index 8c1e924..31e9c12 100644 --- a/app/gui/oven_control/configwindow.cpp +++ b/app/gui/oven_control/configwindow.cpp @@ -7,6 +7,7 @@ #include "config.h" #include "configinfodlg.h" #include "yesnopopupdlg.h" +#include "configdatetimedlg.h" @@ -102,6 +103,11 @@ void ConfigWindow::onConfigBtnClicked(uint16_t id){ Config *cfg = Config::getInstance(); QDialog* dlg; switch(id){ + case config_datetime: + dlg = new ConfigDateTimeDlg(this); + dlg->show(); + if(m_nCurConfigPos != config_menu_favorite) reloadValue(); + break; case config_enter_engineer_mode: { EngineerMenuWindow *w = new EngineerMenuWindow(this); diff --git a/app/gui/oven_control/rtc_control.cpp b/app/gui/oven_control/rtc_control.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/app/gui/oven_control/rtc_control.h b/app/gui/oven_control/rtc_control.h deleted file mode 100644 index 0b14b75..0000000 --- a/app/gui/oven_control/rtc_control.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef RTC_CONTROL_H -#define RTC_CONTROL_H - -#endif // RTC_CONTROL_H diff --git a/app/gui/oven_control/system.cpp b/app/gui/oven_control/system.cpp index e47831e..cb24d24 100644 --- a/app/gui/oven_control/system.cpp +++ b/app/gui/oven_control/system.cpp @@ -1,4 +1,8 @@ #include "system.h" +#include +#include +#include +#include void System::setIP(System::IPData &data) { @@ -27,3 +31,26 @@ void System::setVolume(int percentage) QString command = QString("/usr/bin/amixer -c 0 sset 'PCM',0 %1% %1% on").arg(percentage); system(command.toLocal8Bit().constData()); } + + + + +bool System::setRtcTime(QDateTime dt_tm){ + int fd; + rtc_time rt; + rt.tm_year = dt_tm.date().year() - 1900; + rt.tm_mon = dt_tm.date().month()-1; + rt.tm_mday = dt_tm.date().day(); + rt.tm_hour = dt_tm.time().hour(); + rt.tm_min = dt_tm.time().minute(); + rt.tm_sec = 0; + + fd = open("/dev/rtc0", O_WRONLY); + if(fd <0){ + return false; + }{ + ioctl(fd, RTC_SET_TIME, &rt); + close(fd); + return true; + } +} diff --git a/app/gui/oven_control/system.h b/app/gui/oven_control/system.h index a789f89..260d348 100644 --- a/app/gui/oven_control/system.h +++ b/app/gui/oven_control/system.h @@ -3,6 +3,7 @@ #include +#include namespace System { struct IPData @@ -17,6 +18,9 @@ void setIP(IPData &data); void setBacklight(int level); void setVolume(int percentage); + +bool setRtcTime(QDateTime dt_tm); + } #endif // SYSTEM_H