mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-31 20:39:14 +03:00
Новый веб!
This commit is contained in:
69
src/modules/sensors/UART/Uart.cpp
Normal file
69
src/modules/sensors/UART/Uart.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
|
||||
#include "Global.h"
|
||||
#include "classes/IoTItem.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "modules/sensors/UART/Uart.h"
|
||||
|
||||
#ifdef ESP8266
|
||||
SoftwareSerial* myUART = nullptr;
|
||||
#else
|
||||
HardwareSerial* myUART = nullptr;
|
||||
#endif
|
||||
|
||||
class UART : public IoTItem {
|
||||
private:
|
||||
int tx;
|
||||
int rx;
|
||||
int speed;
|
||||
|
||||
public:
|
||||
UART(String parameters) : IoTItem(parameters) {
|
||||
tx = jsonReadInt(parameters, "tx");
|
||||
rx = jsonReadInt(parameters, "rx");
|
||||
speed = jsonReadInt(parameters, "speed");
|
||||
|
||||
if (!myUART) {
|
||||
#ifdef ESP8266
|
||||
myUART = new SoftwareSerial(tx, rx);
|
||||
myUART->begin(speed);
|
||||
#endif
|
||||
#ifdef ESP32
|
||||
myUART = new HardwareSerial(2);
|
||||
myUART->begin(speed, SERIAL_8N1, rx, tx);
|
||||
#endif
|
||||
}
|
||||
SerialPrint("i", F("UART"), F("UART Init"));
|
||||
}
|
||||
|
||||
void uartHandle() {
|
||||
if (myUART) {
|
||||
static String incStr;
|
||||
if (myUART->available()) {
|
||||
char inc;
|
||||
inc = myUART->read();
|
||||
incStr += inc;
|
||||
if (inc == '\n') {
|
||||
parse(incStr);
|
||||
incStr = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void parse(String& incStr) {
|
||||
SerialPrint("I", "=>UART", incStr);
|
||||
}
|
||||
|
||||
void uartPrint(String msg) {
|
||||
myUART->print(msg);
|
||||
}
|
||||
};
|
||||
|
||||
void* getAPI_UART(String subtype, String param) {
|
||||
if (subtype == F("UART")) {
|
||||
return new UART(param);
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
9
src/modules/sensors/UART/Uart.h
Normal file
9
src/modules/sensors/UART/Uart.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef ESP8266
|
||||
#include <SoftwareSerial.h>
|
||||
extern SoftwareSerial* myUART;
|
||||
#else
|
||||
#include <HardwareSerial.h>
|
||||
extern HardwareSerial* myUART;
|
||||
#endif
|
||||
45
src/modules/sensors/UART/modinfo.json
Normal file
45
src/modules/sensors/UART/modinfo.json
Normal file
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"menuSection": "Сенсоры",
|
||||
"configItem": [
|
||||
{
|
||||
"name": "UART",
|
||||
"type": "Reading",
|
||||
"subtype": "UART",
|
||||
"page": "",
|
||||
"descr": "",
|
||||
"widget": "nil",
|
||||
"id": "u",
|
||||
"tx": 12,
|
||||
"rx": 13,
|
||||
"speed": 9600
|
||||
}
|
||||
],
|
||||
"about": {
|
||||
"authorName": "Dmitry Borisenko",
|
||||
"authorContact": "https://t.me/Dmitry_Borisenko",
|
||||
"authorGit": "https://github.com/DmitryBorisenko33",
|
||||
"specialThanks": "Serghei Crasnicov @Serghei63",
|
||||
"moduleName": "UART",
|
||||
"moduleVersion": "1.0",
|
||||
"usedRam": 15,
|
||||
"subTypes": [
|
||||
"SoftUART"
|
||||
],
|
||||
"title": "Софтовый uart для esp8266 или harware uart для esp32",
|
||||
"moduleDesc": "Используется вместе с Pzem004t, в последствии будет доработан для связи с arduino платами",
|
||||
"propInfo": {
|
||||
"tx": "TX пин",
|
||||
"rx": "RX пин",
|
||||
"speed": "Скорость UART"
|
||||
}
|
||||
},
|
||||
"defActive": true,
|
||||
"devices": {
|
||||
"esp32_4mb": [
|
||||
"plerup/espsoftwareserial"
|
||||
],
|
||||
"esp8266_4mb": [
|
||||
"plerup/espsoftwareserial"
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user