Добавляем модуль Pwm8266

This commit is contained in:
2022-08-10 23:02:39 +03:00
parent 39ff16512e
commit 2028564c63
5 changed files with 179 additions and 55 deletions

View File

@@ -96,7 +96,22 @@
"num": 6 "num": 6
}, },
{ {
"name": "7. Таймер", "name": "7. PWM ESP8266",
"type": "Writing",
"subtype": "Pwm8266",
"id": "pwm",
"widget": "range",
"page": "Кнопки",
"descr": "PWM",
"int": 0,
"pin": 15,
"freq": 5000,
"val": 0,
"apin": -1,
"num": 7
},
{
"name": "8. Таймер",
"type": "Writing", "type": "Writing",
"subtype": "Timer", "subtype": "Timer",
"id": "timer", "id": "timer",
@@ -108,13 +123,13 @@
"ticker": 0, "ticker": 0,
"repeat": 0, "repeat": 0,
"needSave": 0, "needSave": 0,
"num": 7 "num": 8
}, },
{ {
"header": "Сенсоры" "header": "Сенсоры"
}, },
{ {
"name": "8. Cенсор температуры AHT20", "name": "9. Cенсор температуры AHT20",
"type": "Reading", "type": "Reading",
"subtype": "Aht20t", "subtype": "Aht20t",
"id": "Temp20", "id": "Temp20",
@@ -124,10 +139,10 @@
"int": 15, "int": 15,
"addr": "0x38", "addr": "0x38",
"round": 1, "round": 1,
"num": 8 "num": 9
}, },
{ {
"name": "9. Cенсор влажности AHT20", "name": "10. Cенсор влажности AHT20",
"type": "Reading", "type": "Reading",
"subtype": "Aht20h", "subtype": "Aht20h",
"id": "Hum20", "id": "Hum20",
@@ -137,10 +152,10 @@
"int": 15, "int": 15,
"addr": "0x38", "addr": "0x38",
"round": 1, "round": 1,
"num": 9 "num": 10
}, },
{ {
"name": "10. Аналоговый сенсор", "name": "11. Аналоговый сенсор",
"type": "Reading", "type": "Reading",
"subtype": "AnalogAdc", "subtype": "AnalogAdc",
"id": "t", "id": "t",
@@ -154,10 +169,10 @@
"pin": 0, "pin": 0,
"int": 15, "int": 15,
"avgSteps": 1, "avgSteps": 1,
"num": 10 "num": 11
}, },
{ {
"name": "11. Cенсор температуры Bme280", "name": "12. Cенсор температуры Bme280",
"type": "Reading", "type": "Reading",
"subtype": "Bme280t", "subtype": "Bme280t",
"id": "tmp3", "id": "tmp3",
@@ -167,10 +182,10 @@
"int": 15, "int": 15,
"addr": "0x77", "addr": "0x77",
"round": 1, "round": 1,
"num": 11 "num": 12
}, },
{ {
"name": "12. Cенсор давления Bme280", "name": "13. Cенсор давления Bme280",
"type": "Reading", "type": "Reading",
"subtype": "Bme280p", "subtype": "Bme280p",
"id": "Press3", "id": "Press3",
@@ -180,10 +195,10 @@
"int": 15, "int": 15,
"addr": "0x77", "addr": "0x77",
"round": 1, "round": 1,
"num": 12 "num": 13
}, },
{ {
"name": "13. Cенсор влажности Bme280", "name": "14. Cенсор влажности Bme280",
"type": "Reading", "type": "Reading",
"subtype": "Bme280h", "subtype": "Bme280h",
"id": "Hum3", "id": "Hum3",
@@ -193,10 +208,10 @@
"int": 15, "int": 15,
"addr": "0x77", "addr": "0x77",
"round": 1, "round": 1,
"num": 13 "num": 14
}, },
{ {
"name": "14. Cенсор температуры Bmp280", "name": "15. Cенсор температуры Bmp280",
"type": "Reading", "type": "Reading",
"subtype": "Bmp280t", "subtype": "Bmp280t",
"id": "tmp3", "id": "tmp3",
@@ -206,10 +221,10 @@
"int": 15, "int": 15,
"addr": "0x77", "addr": "0x77",
"round": 1, "round": 1,
"num": 14 "num": 15
}, },
{ {
"name": "15. Cенсор давления Bmp280", "name": "16. Cенсор давления Bmp280",
"type": "Reading", "type": "Reading",
"subtype": "Bmp280p", "subtype": "Bmp280p",
"id": "Press3", "id": "Press3",
@@ -219,10 +234,10 @@
"int": 15, "int": 15,
"addr": "0x77", "addr": "0x77",
"round": 1, "round": 1,
"num": 15 "num": 16
}, },
{ {
"name": "16. Cенсор температуры dht11", "name": "17. Cенсор температуры dht11",
"type": "Reading", "type": "Reading",
"subtype": "Dht1122t", "subtype": "Dht1122t",
"id": "tmp3", "id": "tmp3",
@@ -232,10 +247,10 @@
"int": 15, "int": 15,
"pin": 0, "pin": 0,
"senstype": "dht11", "senstype": "dht11",
"num": 16 "num": 17
}, },
{ {
"name": "17. Cенсор влажности dht11", "name": "18. Cенсор влажности dht11",
"type": "Reading", "type": "Reading",
"subtype": "Dht1122h", "subtype": "Dht1122h",
"id": "Hum3", "id": "Hum3",
@@ -245,10 +260,10 @@
"int": 15, "int": 15,
"pin": 0, "pin": 0,
"senstype": "dht11", "senstype": "dht11",
"num": 17 "num": 18
}, },
{ {
"name": "18. Cенсор температуры ds18b20", "name": "19. Cенсор температуры ds18b20",
"type": "Reading", "type": "Reading",
"subtype": "Ds18b20", "subtype": "Ds18b20",
"id": "dstmp", "id": "dstmp",
@@ -260,10 +275,10 @@
"index": 0, "index": 0,
"addr": "", "addr": "",
"round": 1, "round": 1,
"num": 18 "num": 19
}, },
{ {
"name": "19. Cенсор температуры GY21", "name": "20. Cенсор температуры GY21",
"type": "Reading", "type": "Reading",
"subtype": "GY21t", "subtype": "GY21t",
"id": "tmp4", "id": "tmp4",
@@ -272,10 +287,10 @@
"descr": "Температура", "descr": "Температура",
"round": 1, "round": 1,
"int": 15, "int": 15,
"num": 19 "num": 20
}, },
{ {
"name": "20. Cенсор влажности GY21", "name": "21. Cенсор влажности GY21",
"type": "Reading", "type": "Reading",
"subtype": "GY21h", "subtype": "GY21h",
"id": "Hum4", "id": "Hum4",
@@ -284,10 +299,10 @@
"descr": "Влажность", "descr": "Влажность",
"round": 1, "round": 1,
"int": 15, "int": 15,
"num": 20 "num": 21
}, },
{ {
"name": "21. Cенсор температуры HDC1080", "name": "22. Cенсор температуры HDC1080",
"type": "Reading", "type": "Reading",
"subtype": "Hdc1080t", "subtype": "Hdc1080t",
"id": "Temp1080", "id": "Temp1080",
@@ -297,10 +312,10 @@
"int": 15, "int": 15,
"addr": "0x40", "addr": "0x40",
"round": 1, "round": 1,
"num": 21 "num": 22
}, },
{ {
"name": "22. Cенсор влажности HDC1080", "name": "23. Cенсор влажности HDC1080",
"type": "Reading", "type": "Reading",
"subtype": "Hdc1080h", "subtype": "Hdc1080h",
"id": "Hum1080", "id": "Hum1080",
@@ -310,10 +325,10 @@
"int": 15, "int": 15,
"addr": "0x40", "addr": "0x40",
"round": 1, "round": 1,
"num": 22 "num": 23
}, },
{ {
"name": "23. Cенсор температуры MAX6675", "name": "24. Cенсор температуры MAX6675",
"type": "Reading", "type": "Reading",
"subtype": "Max6675t", "subtype": "Max6675t",
"id": "maxtmp", "id": "maxtmp",
@@ -324,11 +339,11 @@
"DO": 12, "DO": 12,
"CS": 13, "CS": 13,
"CLK": 14, "CLK": 14,
"num": 23 "num": 24
}, },
{ {
"name": "24. Сканер кнопок 433 MHz", "name": "25. Сканер кнопок 433 MHz",
"num": 24, "num": 25,
"type": "Reading", "type": "Reading",
"subtype": "RCswitch", "subtype": "RCswitch",
"id": "rsw", "id": "rsw",
@@ -337,7 +352,7 @@
"pinTx": 12 "pinTx": 12
}, },
{ {
"name": "25. Cенсор температуры Sht20", "name": "26. Cенсор температуры Sht20",
"type": "Reading", "type": "Reading",
"subtype": "Sht20t", "subtype": "Sht20t",
"id": "tmp2", "id": "tmp2",
@@ -346,10 +361,10 @@
"descr": "Температура", "descr": "Температура",
"int": 15, "int": 15,
"round": 1, "round": 1,
"num": 25 "num": 26
}, },
{ {
"name": "26. Cенсор влажности Sht20", "name": "27. Cенсор влажности Sht20",
"type": "Reading", "type": "Reading",
"subtype": "Sht20h", "subtype": "Sht20h",
"id": "Hum2", "id": "Hum2",
@@ -358,10 +373,10 @@
"descr": "Влажность", "descr": "Влажность",
"int": 15, "int": 15,
"round": 1, "round": 1,
"num": 26 "num": 27
}, },
{ {
"name": "27. Cенсор температуры Sht30", "name": "28. Cенсор температуры Sht30",
"type": "Reading", "type": "Reading",
"subtype": "Sht30t", "subtype": "Sht30t",
"id": "tmp30", "id": "tmp30",
@@ -370,10 +385,10 @@
"descr": "SHT30 Температура", "descr": "SHT30 Температура",
"int": 15, "int": 15,
"round": 1, "round": 1,
"num": 27 "num": 28
}, },
{ {
"name": "28. Cенсор влажности Sht30", "name": "29. Cенсор влажности Sht30",
"type": "Reading", "type": "Reading",
"subtype": "Sht30h", "subtype": "Sht30h",
"id": "Hum30", "id": "Hum30",
@@ -382,11 +397,11 @@
"descr": "SHT30 Влажность", "descr": "SHT30 Влажность",
"int": 15, "int": 15,
"round": 1, "round": 1,
"num": 28 "num": 29
}, },
{ {
"name": "29. Сонар HC-SR04", "name": "30. Сонар HC-SR04",
"num": 29, "num": 30,
"type": "Reading", "type": "Reading",
"subtype": "Sonar", "subtype": "Sonar",
"id": "sonar", "id": "sonar",
@@ -401,7 +416,7 @@
"header": "Расширения" "header": "Расширения"
}, },
{ {
"name": "30. Поддержка DS1302(1), DS1307(2), DS3231(3), RX8025(4)", "name": "31. Поддержка DS1302(1), DS1307(2), DS3231(3), RX8025(4)",
"type": "Reading", "type": "Reading",
"subtype": "IarduinoRTC", "subtype": "IarduinoRTC",
"id": "RTC", "id": "RTC",
@@ -415,10 +430,10 @@
"dat": 4, "dat": 4,
"defFormat": "d-m-Y", "defFormat": "d-m-Y",
"ticker": 0, "ticker": 0,
"num": 30 "num": 31
}, },
{ {
"name": "31. Расширитель портов Mcp23017", "name": "32. Расширитель портов Mcp23017",
"type": "Reading", "type": "Reading",
"subtype": "Mcp23017", "subtype": "Mcp23017",
"id": "Mcp", "id": "Mcp",
@@ -428,10 +443,10 @@
"int": "0", "int": "0",
"addr": "0x20", "addr": "0x20",
"index": 1, "index": 1,
"num": 31 "num": 32
}, },
{ {
"name": "32. Доп. функции системы", "name": "33. Доп. функции системы",
"type": "Reading", "type": "Reading",
"subtype": "SysExt", "subtype": "SysExt",
"id": "SysExt", "id": "SysExt",
@@ -439,10 +454,10 @@
"page": "", "page": "",
"descr": "", "descr": "",
"int": 15, "int": 15,
"num": 32 "num": 33
}, },
{ {
"name": "33. Переменная", "name": "34. Переменная",
"type": "Reading", "type": "Reading",
"subtype": "Variable", "subtype": "Variable",
"id": "var", "id": "var",
@@ -451,6 +466,6 @@
"descr": "", "descr": "",
"int": "0", "int": "0",
"val": "0", "val": "0",
"num": 33 "num": 34
} }
] ]

View File

@@ -39,7 +39,7 @@ build_src_filter =
${env:esp32_4mb_fromitems.build_src_filter} ${env:esp32_4mb_fromitems.build_src_filter}
[platformio] [platformio]
default_envs = esp32_4mb default_envs = esp8266_4mb
data_dir = data_svelte data_dir = data_svelte
[common_env_data] [common_env_data]
@@ -62,6 +62,7 @@ lib_deps =
adafruit/MAX6675 library adafruit/MAX6675 library
rc-switch @ ^2.6.4 rc-switch @ ^2.6.4
robtillaart/SHT2x@^0.1.1 robtillaart/SHT2x@^0.1.1
WEMOS SHT3x@1.0.0
adafruit/Adafruit MCP23017 Arduino Library@^2.0.2 adafruit/Adafruit MCP23017 Arduino Library@^2.0.2
adafruit/Adafruit BusIO @ ^1.13.0 adafruit/Adafruit BusIO @ ^1.13.0
build_src_filter = build_src_filter =
@@ -70,6 +71,7 @@ build_src_filter =
+<modules\exec\ButtonOut> +<modules\exec\ButtonOut>
+<modules\exec\IoTServo> +<modules\exec\IoTServo>
+<modules\exec\Mp3> +<modules\exec\Mp3>
+<modules\exec\Pwm8266>
+<modules\exec\Timer> +<modules\exec\Timer>
+<modules\sensors\Aht20> +<modules\sensors\Aht20>
+<modules\sensors\AnalogAdc> +<modules\sensors\AnalogAdc>
@@ -82,6 +84,7 @@ build_src_filter =
+<modules\sensors\Max6675> +<modules\sensors\Max6675>
+<modules\sensors\RCswitch> +<modules\sensors\RCswitch>
+<modules\sensors\Sht20> +<modules\sensors\Sht20>
+<modules\sensors\Sht30>
+<modules\sensors\Sonar> +<modules\sensors\Sonar>
+<modules\system\IarduinoRTC> +<modules\system\IarduinoRTC>
+<modules\system\Mcp23017> +<modules\system\Mcp23017>

View File

@@ -5,6 +5,7 @@ void* getAPI_ButtonIn(String subtype, String params);
void* getAPI_ButtonOut(String subtype, String params); void* getAPI_ButtonOut(String subtype, String params);
void* getAPI_IoTServo(String subtype, String params); void* getAPI_IoTServo(String subtype, String params);
void* getAPI_Mp3(String subtype, String params); void* getAPI_Mp3(String subtype, String params);
void* getAPI_Pwm8266(String subtype, String params);
void* getAPI_Timer(String subtype, String params); void* getAPI_Timer(String subtype, String params);
void* getAPI_Aht20(String subtype, String params); void* getAPI_Aht20(String subtype, String params);
void* getAPI_AnalogAdc(String subtype, String params); void* getAPI_AnalogAdc(String subtype, String params);
@@ -31,6 +32,7 @@ if ((tmpAPI = getAPI_ButtonIn(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_ButtonOut(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_ButtonOut(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_IoTServo(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_IoTServo(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Mp3(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Mp3(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Pwm8266(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Timer(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Timer(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Aht20(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Aht20(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_AnalogAdc(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_AnalogAdc(subtype, params)) != nullptr) return tmpAPI;

View File

@@ -0,0 +1,64 @@
#include "Global.h"
#include "classes/IoTItem.h"
#include "Arduino.h"
extern IoTGpio IoTgpio;
class Pwm8266 : public IoTItem {
private:
int _pin;
int _freq;
int _apin, _oldValue;
bool _freezVal = true;
public:
Pwm8266(String parameters): IoTItem(parameters) {
_interval = _interval / 1000; // корректируем величину интервала int, теперь он в миллисекундах
jsonRead(parameters, "pin", _pin);
jsonRead(parameters, "freq", _freq);
IoTgpio.pinMode(_pin, OUTPUT);
analogWriteFreq(_freq);
IoTgpio.analogWrite(_pin, value.valD);
jsonRead(parameters, "apin", _apin);
if (_apin >= 0) IoTgpio.pinMode(_apin, INPUT);
}
void doByInterval() {
if (_apin >= 0) {
value.valD = IoTgpio.analogRead(_apin);
if (value.valD > 1018) value.valD = 1024; // нивелируем погрешность установки мин и макс
else if (value.valD < 9) value.valD = 0; // из-за смягчения значений
if (abs(_oldValue - value.valD) > 5) {
_oldValue = value.valD;
analogWrite(_pin,value.valD);
_freezVal = false;
} else {
if (!_freezVal) { // отправляем событие только раз после серии изменений, чтоб не спамить события
regEvent(value.valD, "Pwm8266");
_freezVal = true;
}
}
}
}
void setValue(IoTValue Value) {
value = Value;
IoTgpio.analogWrite(_pin, value.valD);
regEvent(value.valD, "Pwm8266");
}
//=======================================================================================================
~Pwm8266() {};
};
void* getAPI_Pwm8266(String subtype, String param) {
if (subtype == F("Pwm8266")) {
return new Pwm8266(param);
} else {
return nullptr;
}
}

View File

@@ -0,0 +1,40 @@
{
"menuSection": "Модули управления",
"configItem": [{
"name": "PWM ESP8266",
"type": "Writing",
"subtype": "Pwm8266",
"id": "pwm",
"widget": "range",
"page": "Кнопки",
"descr": "PWM",
"int": 0,
"pin": 15,
"freq": 5000,
"val": 0,
"apin": -1
}],
"about": {
"authorName": "Avaks",
"authorContact": "https://t.me/Avaks",
"authorGit": "https://github.com/avaksru",
"specialThanks": "Serghei Crasnicov @Serghei63",
"moduleName": "Pwm8266",
"moduleVersion": "1.0",
"moduleDesc": "Позволяет управлять Широтно-Импульсной Модуляцией на конкретном пине платы.",
"propInfo": {
"int": "Количество миллисекунд между опросами аналога. 0 - выключено.",
"pin": "Управляемый пин",
"apin": "Номер GPIO аналогового пина. Если -1, то функция отключена.",
"freq": "Частота"
}
},
"defActive": true,
"devices": {
"esp8266_4mb": []
}
}