mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 06:32:19 +03:00
Добавляем модуль-драйвер для RTC часов
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "ESPConfiguration.h"
|
||||
|
||||
void* getAPI_IarduinoRTC(String subtype, String params);
|
||||
void* getAPI_Mcp23017(String subtype, String params);
|
||||
void* getAPI_SysExt(String subtype, String params);
|
||||
void* getAPI_Variable(String subtype, String params);
|
||||
@@ -23,6 +24,7 @@ void* getAPI_Lcd2004(String subtype, String params);
|
||||
|
||||
void* getAPI(String subtype, String params) {
|
||||
void* tmpAPI;
|
||||
if ((tmpAPI = getAPI_IarduinoRTC(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Mcp23017(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_SysExt(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Variable(subtype, params)) != nullptr) return tmpAPI;
|
||||
|
||||
78
src/modules/system/IarduinoRTC/IarduinoRTC.cpp
Normal file
78
src/modules/system/IarduinoRTC/IarduinoRTC.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
#include "Global.h"
|
||||
#include "classes/IoTItem.h"
|
||||
#include "classes/IoTRTC.h"
|
||||
|
||||
#include <iarduino_RTC.h>
|
||||
#include "iarduino_RTC_DS1302.h" // Подключаем файл iarduino_RTC_DS1302.h
|
||||
#include "iarduino_RTC_DS1307.h" // Подключаем файл iarduino_RTC_DS1307.h
|
||||
#include "iarduino_RTC_DS3231.h" // Подключаем файл iarduino_RTC_DS3231.h
|
||||
#include "iarduino_RTC_RX8025.h"
|
||||
|
||||
extern IoTRTC *watch;
|
||||
|
||||
|
||||
class IarduinoRTC : public IoTItem {
|
||||
private:
|
||||
int _chipNum, _rst, _clk, _dat;
|
||||
iarduino_RTC_BASE *RTCDriver;
|
||||
|
||||
public:
|
||||
|
||||
IarduinoRTC(String parameters): IoTItem(parameters) {
|
||||
jsonRead(parameters, "chipNum", _chipNum);
|
||||
jsonRead(parameters, "rst", _rst);
|
||||
jsonRead(parameters, "clk", _clk);
|
||||
jsonRead(parameters, "dat", _dat);
|
||||
|
||||
switch (_chipNum) {
|
||||
case 1:
|
||||
RTCDriver = new iarduino_RTC_DS1302(_rst, _clk, _dat);
|
||||
break;
|
||||
case 2:
|
||||
RTCDriver = new iarduino_RTC_DS1307();
|
||||
break;
|
||||
case 3:
|
||||
RTCDriver = new iarduino_RTC_DS3231();
|
||||
break;
|
||||
case 4:
|
||||
RTCDriver = new iarduino_RTC_RX8025();
|
||||
break;
|
||||
}
|
||||
if (RTCDriver) RTCDriver->begin();
|
||||
}
|
||||
|
||||
void doByInterval() { }
|
||||
|
||||
IoTValue execute(String command, std::vector<IoTValue> ¶m) {
|
||||
if (command == "getTime") {
|
||||
if (param.size()) {
|
||||
value.isDecimal = false;
|
||||
value.valS = watch->gettime(param[0].valS);
|
||||
return value;
|
||||
}
|
||||
} else if (command == "saveSysTime") {
|
||||
tm localTimeVar;
|
||||
time_t timeNowVar;
|
||||
time(&timeNowVar);
|
||||
localTimeVar = *localtime(&timeNowVar);
|
||||
watch->settime(localTimeVar.tm_sec, localTimeVar.tm_min, localTimeVar.tm_hour, localTimeVar.tm_mday, localTimeVar.tm_mon+1, localTimeVar.tm_year-100, localTimeVar.tm_wday);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
iarduino_RTC_BASE* getRtcDriver() {
|
||||
return RTCDriver;
|
||||
}
|
||||
|
||||
~IarduinoRTC() {};
|
||||
};
|
||||
|
||||
|
||||
void* getAPI_IarduinoRTC(String subtype, String param) {
|
||||
if (subtype == F("IarduinoRTC")) {
|
||||
return new IarduinoRTC(param);
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
18
src/modules/system/IarduinoRTC/items.json
Normal file
18
src/modules/system/IarduinoRTC/items.json
Normal file
@@ -0,0 +1,18 @@
|
||||
[
|
||||
{
|
||||
"name": "Поддержка DS1302(1), DS1307(2), DS3231(3), RX8025(4)",
|
||||
"num": 29,
|
||||
"type": "Reading",
|
||||
"subtype": "IarduinoRTC",
|
||||
"id": "RTC",
|
||||
"widget": "",
|
||||
"page": "",
|
||||
"descr": "",
|
||||
|
||||
"int": "0",
|
||||
"chipNum": 1,
|
||||
"rst": 16,
|
||||
"clk": 5,
|
||||
"dat": 4
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user