mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 14:12:16 +03:00
Расширитель портов Tca9555 добавлен
Но требуется проверка
This commit is contained in:
98
src/modules/exec/Tca9555/Tca9555.cpp
Normal file
98
src/modules/exec/Tca9555/Tca9555.cpp
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
#include "Global.h"
|
||||||
|
#include "classes/IoTItem.h"
|
||||||
|
#include "classes/IoTGpio.h"
|
||||||
|
#include "Wire.h"
|
||||||
|
#include "TCA9555.h"
|
||||||
|
|
||||||
|
|
||||||
|
class Tca9555Driver : public IoTGpio {
|
||||||
|
private:
|
||||||
|
TCA9555* _tca;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Tca9555Driver(int index, TCA9555* tca) : IoTGpio(index) {
|
||||||
|
_tca = tca;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pinMode(int pin, uint8_t mode) {
|
||||||
|
_tca->pinMode1(pin, mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
void digitalWrite(int pin, uint8_t val) {
|
||||||
|
_tca->write1(pin, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
int digitalRead(int pin) {
|
||||||
|
return _tca->read1(pin);
|
||||||
|
}
|
||||||
|
|
||||||
|
void digitalInvert(int pin) {
|
||||||
|
_tca->write1(pin, 1 - _tca->read1(pin));
|
||||||
|
}
|
||||||
|
|
||||||
|
~Tca9555Driver() {};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class Tca9555 : public IoTItem {
|
||||||
|
private:
|
||||||
|
String _addr;
|
||||||
|
Tca9555Driver* _driver;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Tca9555(String parameters) : IoTItem(parameters) {
|
||||||
|
_driver = nullptr;
|
||||||
|
Wire.begin();
|
||||||
|
|
||||||
|
jsonRead(parameters, "addr", _addr);
|
||||||
|
if (_addr == "") {
|
||||||
|
scanI2C();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int index;
|
||||||
|
jsonRead(parameters, "index", index);
|
||||||
|
if (index > 4) {
|
||||||
|
Serial.println(F("TCA9555 wrong index. Must be 0 - 4"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int mktype;
|
||||||
|
TCA9555* tca;
|
||||||
|
jsonRead(parameters, "mktype", mktype);
|
||||||
|
if (mktype == 35) {
|
||||||
|
tca = new TCA9535(hexStringToUint8(_addr));
|
||||||
|
} else if (mktype == 55) {
|
||||||
|
tca = new TCA9555(hexStringToUint8(_addr));
|
||||||
|
} else {
|
||||||
|
Serial.println(F("TCA9555 wrong type. Must be 35 or 55"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_driver = new Tca9555Driver(index, tca);
|
||||||
|
}
|
||||||
|
|
||||||
|
void doByInterval() {
|
||||||
|
if (_addr == "") {
|
||||||
|
scanI2C();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//возвращает ссылку на экземпляр класса Tca9555Driver
|
||||||
|
IoTGpio* getGpioDriver() {
|
||||||
|
return _driver;
|
||||||
|
}
|
||||||
|
|
||||||
|
~Tca9555() {
|
||||||
|
delete _driver;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
void* getAPI_Tca9555(String subtype, String param) {
|
||||||
|
if (subtype == F("Tca9555")) {
|
||||||
|
return new Tca9555(param);
|
||||||
|
} else {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
47
src/modules/exec/Tca9555/modinfo.json
Normal file
47
src/modules/exec/Tca9555/modinfo.json
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
{
|
||||||
|
"menuSection": "executive_devices",
|
||||||
|
"configItem": [
|
||||||
|
{
|
||||||
|
"global": 0,
|
||||||
|
"name": "Расширитель портов Tca9555",
|
||||||
|
"type": "Reading",
|
||||||
|
"subtype": "Tca9555",
|
||||||
|
"id": "Tca",
|
||||||
|
"widget": "",
|
||||||
|
"page": "",
|
||||||
|
"descr": "",
|
||||||
|
|
||||||
|
"mktype": 55,
|
||||||
|
"addr": "0x20",
|
||||||
|
"index": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"about": {
|
||||||
|
"authorName": "Ilya Belyakov",
|
||||||
|
"authorContact": "https://t.me/Biveraxe",
|
||||||
|
"authorGit": "https://github.com/biveraxe",
|
||||||
|
"specialThanks": "",
|
||||||
|
"moduleName": "Tca9555",
|
||||||
|
"moduleVersion": "1.0",
|
||||||
|
"usedRam": {
|
||||||
|
"esp32_4mb": 15,
|
||||||
|
"esp8266_4mb": 15
|
||||||
|
},
|
||||||
|
"title": "Расширитель портов Tca9555",
|
||||||
|
"moduleDesc": "Добавляет в систему дополнительные GPIO для элементов, которые поддерживают такую функцию.",
|
||||||
|
"propInfo": {
|
||||||
|
"mktype": "Тип устройства: 55 - TCA9555, 35 - TCA9535",
|
||||||
|
"addr": "Адрес устройства на шине, обычно 0x20",
|
||||||
|
"index": "Значения от 1 до 4, где при выборе 1 будет нумерация pin 100-115, при выборе 2 200-215 и т.д."
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"defActive": false,
|
||||||
|
"usedLibs": {
|
||||||
|
"esp32*": [
|
||||||
|
"https://github.com/RobTillaart/TCA9555"
|
||||||
|
],
|
||||||
|
"esp82*": [
|
||||||
|
"https://github.com/RobTillaart/TCA9555"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user