From f53943521614742f49031720cc0668e4f4dd3f59 Mon Sep 17 00:00:00 2001 From: biver Date: Mon, 21 Nov 2022 21:40:20 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F?= =?UTF-8?q?=D0=B5=D0=BC=20=D0=B4=D0=B0=D1=82=D1=87=D0=B8=D0=BA=20=D0=B4?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20Hx710?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/sensors/Hx710/Hx710.cpp | 48 +++++++++++++++++++++ src/modules/sensors/Hx710/modinfo.json | 58 ++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 src/modules/sensors/Hx710/Hx710.cpp create mode 100644 src/modules/sensors/Hx710/modinfo.json diff --git a/src/modules/sensors/Hx710/Hx710.cpp b/src/modules/sensors/Hx710/Hx710.cpp new file mode 100644 index 00000000..210cef75 --- /dev/null +++ b/src/modules/sensors/Hx710/Hx710.cpp @@ -0,0 +1,48 @@ +#include "Global.h" +#include "classes/IoTItem.h" + +#include "HX710B.h" + + +class HX710b : public IoTItem { + + private: + HX710B pressure_sensor; + + public: + HX710b(String parameters) : IoTItem(parameters) { + int data, clock; + jsonRead(parameters, "data", data); + jsonRead(parameters, "clock", clock); + + pressure_sensor.begin(data, clock); + pressure_sensor.tare(); + } + + void doByInterval() { + if (!pressure_sensor.is_ready()) return; + value.valD = pressure_sensor.mmHg(); + + regEvent(value.valD, "Hx710"); + } + + IoTValue execute(String command, std::vector ¶m) { + if (command == "tare") { + pressure_sensor.tare(); + } else if (command == "read") { + value.valD = pressure_sensor.read(); + return value; + } + return {}; + } + + ~HX710b() {}; +}; + +void* getAPI_Hx710(String subtype, String param) { + if (subtype == F("Hx710")) { + return new HX710b(param); + } else { + return nullptr; + } +} diff --git a/src/modules/sensors/Hx710/modinfo.json b/src/modules/sensors/Hx710/modinfo.json new file mode 100644 index 00000000..985c4457 --- /dev/null +++ b/src/modules/sensors/Hx710/modinfo.json @@ -0,0 +1,58 @@ +{ + "menuSection": "Сенсоры", + + "configItem": [{ + "name": "HX710 Cенсор давления", + "type": "Reading", + "subtype": "Hx710", + "id": "hxp", + "widget": "anydataDef", + "page": "Давление", + "descr": "HX press", + "int": 15, + "plus": 0, + "multiply": 1, + "round": 1, + "data": 14, + "clock": 15 + }], + + "about": { + "authorName": "Serghei Crasnicov", + "authorContact": "https://t.me/Serghei63", + "authorGit": "https://github.com/Serghei63", + "specialThanks": "", + "moduleName": "Hx710", + "moduleVersion": "1.0", + "usedRam": { + "esp32_4mb": 15, + "esp8266_4mb": 15 + }, + "title": "HX710 Cенсор давления", + "moduleDesc": "Позволяет получить давление с датчика Hx710", + "propInfo": { + "clock": "GPIO шины данных", + "data": "GPIO шины данных", + "int": "Количество секунд между опросами датчика." + }, + "retInfo": "Содержит mmHg значение датчика, необходима калибровка", + "funcInfo": [ + { + "name": "read", + "descr": "Прочитать текущее значение. Полезно использовать при Int=0 и считывать RAW-data по событию.", + "params": [] + } + ] + }, + + "defActive": false, + + "usedLibs": { + "esp32_4mb": [ + "https://github.com/kurimawxx00/hx710B_pressure_sensor" + ], + "esp8266_4mb": [ + "https://github.com/kurimawxx00/hx710B_pressure_sensor" + ] + } +} \ No newline at end of file