mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 22:52:19 +03:00
Аналоговый счетчик импульсов. Multitouch V2
This commit is contained in:
@@ -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": []
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user