| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,70 @@ |
| 1 |
+/* |
|
| 2 |
+ * Author: Pawel Jablonski |
|
| 3 |
+ * E-mail: pj@xirx.net |
|
| 4 |
+ * WWW: xirx.net |
|
| 5 |
+ * GIT: git.xirx.net |
|
| 6 |
+ * |
|
| 7 |
+ * License: You can use this code however you like |
|
| 8 |
+ * but leave information about the original author. |
|
| 9 |
+ * Code is free for non-commercial and commercial use. |
|
| 10 |
+ */ |
|
| 11 |
+ |
|
| 12 |
+#include "rtc.h" |
|
| 13 |
+ |
|
| 14 |
+//! Constructor for Real Time Clock functions |
|
| 15 |
+RTC::RTC(QObject *parent) : QObject(parent) |
|
| 16 |
+{
|
|
| 17 |
+ this->reset(); |
|
| 18 |
+} |
|
| 19 |
+ |
|
| 20 |
+//! Reset RTC to default values |
|
| 21 |
+void RTC::reset() |
|
| 22 |
+{
|
|
| 23 |
+ this->dateTime.setTime(QTime(0, 0, 0)); |
|
| 24 |
+ this->dateTime.setDate(QDate(2000, 1, 1)); |
|
| 25 |
+} |
|
| 26 |
+ |
|
| 27 |
+/** |
|
| 28 |
+ * Set date and time |
|
| 29 |
+ * |
|
| 30 |
+ * @param dateTime Date and time to set in Qt format |
|
| 31 |
+ */ |
|
| 32 |
+void RTC::setDateTime(const QDateTime &dateTime) |
|
| 33 |
+{
|
|
| 34 |
+ this->dateTime = dateTime; |
|
| 35 |
+ |
|
| 36 |
+ emit updateDateTimeSignal(this->dateTime); |
|
| 37 |
+} |
|
| 38 |
+ |
|
| 39 |
+/** |
|
| 40 |
+ * Set date and time |
|
| 41 |
+ * |
|
| 42 |
+ * @param dateTime Date and time to set in own RTC format |
|
| 43 |
+ */ |
|
| 44 |
+void RTC::setDateTime(const RTC::DateTime &dateTime) |
|
| 45 |
+{
|
|
| 46 |
+ this->dateTime.setTime(QTime(dateTime.hour, dateTime.minute, dateTime.second)); |
|
| 47 |
+ this->dateTime.setDate(QDate((static_cast<int>(dateTime.year) + 2000), dateTime.month, dateTime.day)); |
|
| 48 |
+ |
|
| 49 |
+ emit updateDateTimeSignal(this->dateTime); |
|
| 50 |
+} |
|
| 51 |
+ |
|
| 52 |
+/** |
|
| 53 |
+ * Get date and time |
|
| 54 |
+ * |
|
| 55 |
+ * @return Date and time in own RTC format |
|
| 56 |
+ */ |
|
| 57 |
+RTC::DateTime RTC::getDateTime() |
|
| 58 |
+{
|
|
| 59 |
+ RTC::DateTime dateTime = {};
|
|
| 60 |
+ |
|
| 61 |
+ dateTime.year = static_cast<unsigned char>(this->dateTime.date().year() % 100); |
|
| 62 |
+ dateTime.month = static_cast<unsigned char>(this->dateTime.date().month()); |
|
| 63 |
+ dateTime.day = static_cast<unsigned char>(this->dateTime.date().day()); |
|
| 64 |
+ |
|
| 65 |
+ dateTime.hour = static_cast<unsigned char>(this->dateTime.time().hour()); |
|
| 66 |
+ dateTime.minute = static_cast<unsigned char>(this->dateTime.time().minute()); |
|
| 67 |
+ dateTime.second = static_cast<unsigned char>(this->dateTime.time().second()); |
|
| 68 |
+ |
|
| 69 |
+ return(dateTime); |
|
| 70 |
+} |