mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 06:32:19 +03:00
Аналоговый счетчик импульсов. Multitouch V2
This commit is contained in:
@@ -14,6 +14,7 @@ void* getAPI_Bme280(String subtype, String params);
|
||||
void* getAPI_Bmp280(String subtype, String params);
|
||||
void* getAPI_Dht1122(String subtype, String params);
|
||||
void* getAPI_Ds18b20(String subtype, String params);
|
||||
void* getAPI_Impulse(String subtype, String params);
|
||||
void* getAPI_Pzem004(String subtype, String params);
|
||||
void* getAPI_RTC(String subtype, String params);
|
||||
void* getAPI_Sht20(String subtype, String params);
|
||||
@@ -47,6 +48,7 @@ if ((tmpAPI = getAPI_Bme280(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Bmp280(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Dht1122(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Ds18b20(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Impulse(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Pzem004(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_RTC(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Sht20(subtype, params)) != nullptr) return tmpAPI;
|
||||
|
||||
@@ -6,23 +6,22 @@ extern IoTGpio IoTgpio;
|
||||
class Multitouch : public IoTItem
|
||||
{
|
||||
private:
|
||||
int _pin;
|
||||
int _int;
|
||||
int _inv;
|
||||
String _pinMode;
|
||||
int _lastButtonState = LOW;
|
||||
unsigned long _lastDebounceTime = 0;
|
||||
unsigned long timing;
|
||||
long _debounceDelay = 50;
|
||||
long _PWMDelay = 500;
|
||||
int _buttonState;
|
||||
int _reading;
|
||||
int _count = 0;
|
||||
int duration = 0;
|
||||
|
||||
int _pin;
|
||||
bool _execLevel, _fixState, _inv, _buttonState, _reading;
|
||||
bool _lastButtonState = LOW;
|
||||
unsigned long _lastDebounceTime = 0;
|
||||
int _debounceDelay = 50;
|
||||
|
||||
public:
|
||||
Multitouch(String parameters) : IoTItem(parameters)
|
||||
{
|
||||
String _pinMode;
|
||||
jsonRead(parameters, "pin", _pin);
|
||||
jsonRead(parameters, "pinMode", _pinMode);
|
||||
jsonRead(parameters, "debounceDelay", _debounceDelay);
|
||||
@@ -31,15 +30,20 @@ public:
|
||||
jsonRead(parameters, "inv", _inv);
|
||||
_round = 0;
|
||||
|
||||
IoTgpio.pinMode(_pin, INPUT);
|
||||
if (_pinMode == "INPUT_PULLUP")
|
||||
IoTgpio.digitalWrite(_pin, HIGH);
|
||||
else if (_pinMode == "INPUT_PULLDOWN")
|
||||
if (_pinMode == F("INPUT"))
|
||||
IoTgpio.pinMode(_pin, INPUT);
|
||||
else if (_pinMode == F("INPUT_PULLUP"))
|
||||
IoTgpio.pinMode(_pin, INPUT_PULLUP);
|
||||
else if (_pinMode == F("INPUT_PULLDOWN"))
|
||||
{
|
||||
IoTgpio.pinMode(_pin, INPUT);
|
||||
IoTgpio.digitalWrite(_pin, LOW);
|
||||
}
|
||||
|
||||
value.valD = _buttonState = IoTgpio.digitalRead(_pin);
|
||||
// сообщаем всем о стартовом статусе без генерации события
|
||||
regEvent(_buttonState, "", false, false);
|
||||
SerialPrint("I", F("Multitouch"), "_buttonState " + String(_buttonState));
|
||||
}
|
||||
|
||||
void loop()
|
||||
@@ -49,35 +53,34 @@ public:
|
||||
{
|
||||
_lastDebounceTime = millis();
|
||||
}
|
||||
|
||||
if ((millis() - _lastDebounceTime) > _debounceDelay)
|
||||
{
|
||||
if (millis() - timing > _int && _reading == _inv && millis() - _lastDebounceTime > _PWMDelay)
|
||||
{
|
||||
timing = millis();
|
||||
duration = millis() - _lastDebounceTime - _PWMDelay;
|
||||
value.valD = duration / 50;
|
||||
regEvent(value.valD, "Multitouch");
|
||||
_count = -1;
|
||||
}
|
||||
|
||||
if (_reading != _buttonState)
|
||||
{
|
||||
_buttonState = _reading;
|
||||
_count++;
|
||||
duration = 0;
|
||||
_buttonState = _reading;
|
||||
}
|
||||
|
||||
if (1 < _count && millis() > _lastDebounceTime + _PWMDelay)
|
||||
{
|
||||
value.valD = _count / 2;
|
||||
regEvent(value.valD, "Multitouch");
|
||||
regEvent(value.valD, F("Multitouch"));
|
||||
_count = 0;
|
||||
}
|
||||
|
||||
if (millis() - timing > _int && _reading == _inv && millis() - _lastDebounceTime > _PWMDelay)
|
||||
{
|
||||
SerialPrint("I", F("Multitouch"), "Считаем задержку");
|
||||
timing = millis();
|
||||
duration = millis() - _lastDebounceTime - _PWMDelay;
|
||||
value.valD = duration / _int + 1;
|
||||
regEvent(value.valD, F("Multitouch"));
|
||||
_count = -1;
|
||||
}
|
||||
}
|
||||
|
||||
_lastButtonState = _reading;
|
||||
}
|
||||
|
||||
~Multitouch(){};
|
||||
};
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
"authorGit": "https://github.com/avaksru",
|
||||
"specialThanks": "",
|
||||
"moduleName": "Multitouch",
|
||||
"moduleVersion": "1.0",
|
||||
"moduleVersion": "2.0",
|
||||
"usedRam": {
|
||||
"esp32_4mb": 15,
|
||||
"esp8266_4mb": 15
|
||||
@@ -48,8 +48,6 @@
|
||||
"esp8266_1mb": [],
|
||||
"esp8266_1mb_ota": [],
|
||||
"esp8285_1mb": [],
|
||||
"esp8285_1mb_ota": [],
|
||||
"esp8266_2mb": [],
|
||||
"esp8266_2mb_ota": []
|
||||
"esp8285_1mb_ota": []
|
||||
}
|
||||
}
|
||||
|
||||
87
src/modules/sensors/Impulse/Impulse.cpp
Normal file
87
src/modules/sensors/Impulse/Impulse.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
#include "Global.h"
|
||||
#include "classes/IoTItem.h"
|
||||
|
||||
extern IoTGpio IoTgpio;
|
||||
|
||||
class Impulse : public IoTItem
|
||||
{
|
||||
private:
|
||||
int _int;
|
||||
int _pin;
|
||||
bool _buttonState, _reading;
|
||||
bool _lastButtonState = LOW;
|
||||
unsigned long _lastDebounceTime = 0;
|
||||
int _debounceDelay = 50;
|
||||
int _count = 0;
|
||||
unsigned long timing;
|
||||
|
||||
public:
|
||||
Impulse(String parameters) : IoTItem(parameters)
|
||||
{
|
||||
String _pinMode;
|
||||
jsonRead(parameters, F("pin"), _pin);
|
||||
jsonRead(parameters, F("pinMode"), _pinMode);
|
||||
jsonRead(parameters, F("debounceDelay"), _debounceDelay);
|
||||
jsonRead(parameters, "int", _int);
|
||||
_round = 0;
|
||||
|
||||
if (_pinMode == F("INPUT"))
|
||||
IoTgpio.pinMode(_pin, INPUT);
|
||||
else if (_pinMode == F("INPUT_PULLUP"))
|
||||
IoTgpio.pinMode(_pin, INPUT_PULLUP);
|
||||
else if (_pinMode == F("INPUT_PULLDOWN"))
|
||||
{
|
||||
IoTgpio.pinMode(_pin, INPUT);
|
||||
IoTgpio.digitalWrite(_pin, LOW);
|
||||
}
|
||||
|
||||
value.valD = _buttonState = IoTgpio.digitalRead(_pin);
|
||||
regEvent(_buttonState, "", false, false);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
_reading = IoTgpio.digitalRead(_pin);
|
||||
if (_reading != _lastButtonState)
|
||||
{
|
||||
|
||||
_lastDebounceTime = millis();
|
||||
}
|
||||
|
||||
if ((millis() - _lastDebounceTime) > _debounceDelay)
|
||||
{
|
||||
if (_reading != _buttonState)
|
||||
{
|
||||
_buttonState = _reading;
|
||||
_count++;
|
||||
}
|
||||
if (_count == 1)
|
||||
{
|
||||
timing = millis();
|
||||
}
|
||||
if (millis() - timing > _int * 1000 && _count > 1)
|
||||
{
|
||||
timing = millis();
|
||||
value.valD = _count;
|
||||
regEvent(value.valD, F("Impulse"));
|
||||
_count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
_lastButtonState = _reading;
|
||||
}
|
||||
|
||||
~Impulse(){};
|
||||
};
|
||||
|
||||
void *getAPI_Impulse(String subtype, String param)
|
||||
{
|
||||
if (subtype == F("Impulse"))
|
||||
{
|
||||
return new Impulse(param);
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
49
src/modules/sensors/Impulse/modinfo.json
Normal file
49
src/modules/sensors/Impulse/modinfo.json
Normal file
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"menuSection": "Сенсоры",
|
||||
"configItem": [
|
||||
{
|
||||
"global": 0,
|
||||
"name": "Аналоговый счетчик импульсов",
|
||||
"type": "Writing",
|
||||
"subtype": "Impulse",
|
||||
"id": "impulse",
|
||||
"widget": "anydataDef",
|
||||
"page": "Счетчики",
|
||||
"descr": "Импульсов",
|
||||
"needSave": 0,
|
||||
"int": 1,
|
||||
"pin": 16,
|
||||
"pinMode": "INPUT",
|
||||
"debounceDelay": 3
|
||||
}
|
||||
],
|
||||
"about": {
|
||||
"authorName": "AVAKS",
|
||||
"authorContact": "https://t.me/@avaks_dev",
|
||||
"authorGit": "https://github.com/avaksru",
|
||||
"specialThanks": "",
|
||||
"moduleName": "Impulse",
|
||||
"moduleVersion": "2.0",
|
||||
"usedRam": {
|
||||
"esp32_4mb": 15,
|
||||
"esp8266_4mb": 15
|
||||
},
|
||||
"title": "Аналоговый счетчик импульсов. Датчик Холла ",
|
||||
"moduleDesc": "Считает количество импульсов за период времени",
|
||||
"propInfo": {
|
||||
"int": "Период сбора импульсов в секундах",
|
||||
"pin": "Укажите GPIO номер пина для чтения импульсов",
|
||||
"pinMode": "Может быть INPUT_PULLUP INPUT_PULLDOWN INPUT",
|
||||
"debounceDelay": "Время обработки дребезга (миллисекунд)"
|
||||
}
|
||||
},
|
||||
"defActive": true,
|
||||
"usedLibs": {
|
||||
"esp32_4mb": [],
|
||||
"esp8266_4mb": [],
|
||||
"esp8266_1mb": [],
|
||||
"esp8266_1mb_ota": [],
|
||||
"esp8285_1mb": [],
|
||||
"esp8285_1mb_ota": []
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user