mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 20:09:14 +03:00
Добавил модуль A02Distance
This commit is contained in:
@@ -230,6 +230,13 @@
|
|||||||
"after": "mWt",
|
"after": "mWt",
|
||||||
"icon": "speedometer"
|
"icon": "speedometer"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "anydataCm",
|
||||||
|
"label": "Сантиметры",
|
||||||
|
"widget": "anydata",
|
||||||
|
"after": "cm",
|
||||||
|
"icon": "speedometer"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "nil",
|
"name": "nil",
|
||||||
"label": "Без виджета"
|
"label": "Без виджета"
|
||||||
|
|||||||
99
src/modules/sensors/A02Distance/A02Distance.cpp
Normal file
99
src/modules/sensors/A02Distance/A02Distance.cpp
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
|
||||||
|
#include "Global.h"
|
||||||
|
#include "classes/IoTItem.h"
|
||||||
|
|
||||||
|
#include "modules/sensors/UART/Uart.h"
|
||||||
|
|
||||||
|
#define READ_TIMEOUT 100
|
||||||
|
|
||||||
|
class A02Distance : public IoTItem
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
public:
|
||||||
|
A02Distance(String parameters) : IoTItem(parameters)
|
||||||
|
{
|
||||||
|
if (myUART)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Периодическое выполнение программы, в int секунд, которые зададим в конфигурации
|
||||||
|
void doByInterval()
|
||||||
|
{
|
||||||
|
if (myUART)
|
||||||
|
{
|
||||||
|
static uint8_t data[4];
|
||||||
|
|
||||||
|
if (recieve(data, 4) == 4)
|
||||||
|
{
|
||||||
|
if (data[0] == 0xff)
|
||||||
|
{
|
||||||
|
int sum;
|
||||||
|
sum = (data[0] + data[1] + data[2]) & 0x00FF;
|
||||||
|
if (sum == data[3])
|
||||||
|
{
|
||||||
|
float distance = (data[1] << 8) + data[2];
|
||||||
|
if (distance > 30)
|
||||||
|
{
|
||||||
|
value.valD = distance / 10;
|
||||||
|
//SerialPrint("i", F("A02Distance"), "distance = " + String(value.valD) + "cm");
|
||||||
|
regEvent(value.valD, "A02Distance");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SerialPrint("E", "A02Distance", "Below the lower limit");
|
||||||
|
regEvent(NAN, "A02Distance");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
regEvent(NAN, "A02Distance");
|
||||||
|
SerialPrint("E", "A02Distance", "Distance data error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
regEvent(NAN, "A02Distance");
|
||||||
|
SerialPrint("E", "A02Distance", "Recieve data error");
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
regEvent(NAN, "A02Distance");
|
||||||
|
SerialPrint("E", "A02Distance", "Not find UART");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Приём данных из COM порта
|
||||||
|
uint16_t recieve(uint8_t *resp, uint16_t len)
|
||||||
|
{
|
||||||
|
((SoftwareSerial *)myUART)->listen(); // Start software serial listen
|
||||||
|
unsigned long startTime = millis(); // Start time for Timeout
|
||||||
|
uint8_t index = 0; // Bytes we have read
|
||||||
|
while ((index < len) && (millis() - startTime < READ_TIMEOUT))
|
||||||
|
{
|
||||||
|
if (myUART->available() > 0)
|
||||||
|
{
|
||||||
|
uint8_t c = (uint8_t)myUART->read();
|
||||||
|
resp[index++] = c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
~A02Distance(){};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//Функиця ядра, чтобы нашел наш модуль
|
||||||
|
void *getAPI_A02Distance(String subtype, String param)
|
||||||
|
{
|
||||||
|
if (subtype == F("A02Distance"))
|
||||||
|
{
|
||||||
|
return new A02Distance(param);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
40
src/modules/sensors/A02Distance/modinfo.json
Normal file
40
src/modules/sensors/A02Distance/modinfo.json
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
{
|
||||||
|
"menuSection": "Сенсоры",
|
||||||
|
"configItem": [
|
||||||
|
{
|
||||||
|
"name": "A02 Дальность",
|
||||||
|
"type": "Reading",
|
||||||
|
"subtype": "A02Distance",
|
||||||
|
"id": "dist",
|
||||||
|
"widget": "anydataCm",
|
||||||
|
"page": "Сенсоры",
|
||||||
|
"descr": "Дальность",
|
||||||
|
"int": 5,
|
||||||
|
"round": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"about": {
|
||||||
|
"authorName": "Bubnov Mikhail",
|
||||||
|
"authorContact": "https://t.me/Mitchel",
|
||||||
|
"authorGit": "https://github.com/Mit4el",
|
||||||
|
"exampleURL": "https://iotmanager.org/wiki",
|
||||||
|
"specialThanks": "",
|
||||||
|
"moduleName": "A02Distance",
|
||||||
|
"moduleVersion": "0.1",
|
||||||
|
"moduleDesc": "A0221AU, A02YYUW Ультразвуковой датчик. Позволяет получить дальность с ультрозвуковых датчиков A0221AU, A02YYUW",
|
||||||
|
"propInfo": {
|
||||||
|
"int": "Количество секунд между опросами датчика."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"defActive": true,
|
||||||
|
"usedLibs": {
|
||||||
|
"esp32_4mb": [],
|
||||||
|
"esp8266_4mb": [],
|
||||||
|
"esp8266_1mb": [],
|
||||||
|
"esp8266_1mb_ota": [],
|
||||||
|
"esp8285_1mb": [],
|
||||||
|
"esp8285_1mb_ota": [],
|
||||||
|
"esp8266_2mb": [],
|
||||||
|
"esp8266_2mb_ota": []
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user