mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-28 07:02:17 +03:00
Добавляем расширитель портов MCP23017
This commit is contained in:
@@ -14,6 +14,7 @@ void* getAPI_GY21(String subtype, String params);
|
||||
void* getAPI_Lcd2004(String subtype, String params);
|
||||
void* getAPI_SysExt(String subtype, String params);
|
||||
void* getAPI_Ads1115(String subtype, String params);
|
||||
void* getAPI_Mcp23017(String subtype, String params);
|
||||
//============================================================================================
|
||||
|
||||
void* getAPI(String subtype, String params) {
|
||||
@@ -32,6 +33,7 @@ void* getAPI(String subtype, String params) {
|
||||
if ((tmpAPI = getAPI_Lcd2004(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_SysExt(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Ads1115(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Mcp23017(subtype, params)) != nullptr) return tmpAPI;
|
||||
//================================================================================================================
|
||||
|
||||
return nullptr;
|
||||
|
||||
69
src/modules/Mcp23017.cpp
Normal file
69
src/modules/Mcp23017.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
#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);
|
||||
}
|
||||
|
||||
~Mcp23017() {};
|
||||
};
|
||||
|
||||
|
||||
void* getAPI_Mcp23017(String subtype, String param) {
|
||||
if (subtype == F("Mcp23017")) {
|
||||
String addr;
|
||||
uint8_t deviceAddress[1];
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user