mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-31 12:29:14 +03:00
Меняем структуру FS для хранения модулей и добавляем скрипт сборки модулей для интеграции в меню и библиотеки
This commit is contained in:
72
src/modules/system/Mcp23017/Mcp23017.cpp
Normal file
72
src/modules/system/Mcp23017/Mcp23017.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#include "Global.h"
|
||||
#include "classes/IoTItem.h"
|
||||
#include "classes/IoTGpio.h"
|
||||
#include <Adafruit_MCP23X17.h>
|
||||
|
||||
|
||||
class Mcp23017 : public IoTItem, IoTGpio {
|
||||
private:
|
||||
|
||||
public:
|
||||
Adafruit_MCP23X17 mcp;
|
||||
|
||||
Mcp23017(String parameters, int index): IoTItem(parameters), IoTGpio(index) {
|
||||
|
||||
}
|
||||
|
||||
void doByInterval() {
|
||||
|
||||
|
||||
//regEvent(value.valD, "Mcp23017");
|
||||
}
|
||||
|
||||
IoTGpio* getGpioDriver() {
|
||||
return this;
|
||||
}
|
||||
|
||||
void pinMode(uint8_t pin, uint8_t mode) {
|
||||
mcp.pinMode(pin, mode);
|
||||
}
|
||||
|
||||
void digitalWrite(uint8_t pin, uint8_t val) {
|
||||
mcp.digitalWrite(pin, val);
|
||||
}
|
||||
|
||||
int digitalRead(uint8_t pin) {
|
||||
return mcp.digitalRead(pin);
|
||||
}
|
||||
|
||||
void digitalInvert(uint8_t pin) {
|
||||
mcp.digitalWrite(pin, 1 - mcp.digitalRead(pin));
|
||||
}
|
||||
|
||||
~Mcp23017() {};
|
||||
};
|
||||
|
||||
|
||||
void* getAPI_Mcp23017(String subtype, String param) {
|
||||
if (subtype == F("Mcp23017")) {
|
||||
String addr;
|
||||
jsonRead(param, "addr", addr);
|
||||
Serial.printf("deviceAddress %s = %02x \n", addr.c_str(), hexStringToUint8(addr));
|
||||
|
||||
String index_str;
|
||||
jsonRead(param, "index", index_str);
|
||||
int index = index_str.toInt();
|
||||
if (index > 4) {
|
||||
Serial.println("MCP23X17 wrong index. Must be 0 - 4");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Mcp23017* newItem = new Mcp23017(param, index);
|
||||
if (!newItem->mcp.begin_I2C(hexStringToUint8(addr))) {
|
||||
Serial.println("MCP23X17 Init Error.");
|
||||
delete newItem;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return newItem;
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
16
src/modules/system/Mcp23017/items.json
Normal file
16
src/modules/system/Mcp23017/items.json
Normal file
@@ -0,0 +1,16 @@
|
||||
[
|
||||
{
|
||||
"name": "Расширитель портов Mcp23017",
|
||||
"num": 29,
|
||||
"type": "Reading",
|
||||
"subtype": "Mcp23017",
|
||||
"id": "Mcp",
|
||||
"widget": "",
|
||||
"page": "",
|
||||
"descr": "",
|
||||
|
||||
"int": "0",
|
||||
"addr": "0x20",
|
||||
"index": 1
|
||||
}
|
||||
]
|
||||
8
src/modules/system/Mcp23017/platformio.ini
Normal file
8
src/modules/system/Mcp23017/platformio.ini
Normal file
@@ -0,0 +1,8 @@
|
||||
[env:esp8266_4mb]
|
||||
lib_deps =
|
||||
adafruit/Adafruit MCP23017 Arduino Library@^2.0.2
|
||||
|
||||
[env:esp32_4mb]
|
||||
lib_deps =
|
||||
adafruit/Adafruit MCP23017 Arduino Library@^2.0.2
|
||||
|
||||
Reference in New Issue
Block a user