mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-07-28 04:07:47 +00:00
Merge pull request #3738 from tonhuisman/feature/p009-add-easier-address-and-port-selection
[P009] MCP23017 Add easier I2C Address and port selection options
This commit is contained in:
+101
-4
@@ -1,4 +1,4 @@
|
||||
.. include:: ../Plugin/_plugin_substitutions_p00x.repl
|
||||
.. include:: ../Plugin/_plugin_substitutions_p00x.repl
|
||||
.. _P009_page:
|
||||
|
||||
|P009_typename|
|
||||
@@ -21,15 +21,109 @@ Maintainer: |P009_maintainer|
|
||||
|
||||
Used libraries: |P009_usedlibraries|
|
||||
|
||||
Introduction
|
||||
------------
|
||||
|
||||
The number of GPIO pins on the ESP module can be expanded with a IO Expander. This plugin supports the MCP23017 that provides 16 more pins that can be used as input or output. This way it becomes possible to control a 16 channel relay board. Multiple of these boards can be connected, as there are 8 I2C addresses available via jumper pins.
|
||||
|
||||
Each individual pin can be used as either input or output.
|
||||
|
||||
As this plugin shares many attributes with the regular :ref:`P001_Switch_page` plugin, the description has many similarities.
|
||||
|
||||
Supported hardware
|
||||
------------------
|
||||
|
||||
.. image:: P009_MCP23017Module.png
|
||||
|
||||
The chip can be used on specifically designed hardware, or a generic module can be used. These are available from several sources.
|
||||
|
||||
|P009_usedby|
|
||||
|
||||
.. Commands available
|
||||
.. ^^^^^^^^^^^^^^^^^^
|
||||
Configuration
|
||||
-------------
|
||||
|
||||
.. .. include:: P009_commands.repl
|
||||
.. image:: P009_DeviceConfiguration.png
|
||||
|
||||
* **Name** A unique name should be entered here.
|
||||
|
||||
* **Enabled** The device can be disabled or enabled. When not enabled the device should not use any resources.
|
||||
|
||||
Sensor
|
||||
^^^^^^^
|
||||
|
||||
* **Inversed Logic** When enabled, inverts the input signal, so if the pin is logic high (3.3V), the Value will be 0, and if it is logic low (gnd), the Value will be 1.
|
||||
|
||||
I2C Options
|
||||
^^^^^^^^^^^^
|
||||
|
||||
The available settings here depend on the build used. At least the **Force Slow I2C speed** option is available, but selections for the I2C Multiplexer can also be shown. For details see the :ref:`Hardware_page`
|
||||
|
||||
* **I2C Address**: The address the device is using. As there are 8 possible I2C addresses, when the jumpers are configured, the selected value should match with that.
|
||||
|
||||
Available options:
|
||||
|
||||
.. image:: P009_I2CAddressOptions.png
|
||||
|
||||
* **Port** As there are multiple Ports available on each board, the desired Port can be selected here.
|
||||
|
||||
Available options:
|
||||
|
||||
.. image:: P009_PortOptions.png
|
||||
|
||||
Device Settings
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
* **Send boot state**: If checked the unit will publish the switch state when booting. If not checked you may find yourself
|
||||
with a latching switch caught in limbo. This means that the unit is registering a low/high value but the physical state of
|
||||
the switch might be the opposite. If you use a mechanical switch that may be physically set to a state you should check this
|
||||
option.
|
||||
|
||||
Advanced event management
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
* **De-bounce (ms)**: How long should the pulse (the time you press the button) be, if set to high you need to have it published
|
||||
for a longer time before the unit will register it as an state change. You could experiment with this setting to find a good
|
||||
behavior of the button if you feel that it's not responding according to your preferences.
|
||||
|
||||
* **Double click event**: If enabled the unit will detect double clicks which are within the set interval (see below). The double
|
||||
click event is identified as :code:`MCP23017#State=3`. There's three options for the double click:
|
||||
* Active only on low: the double clicks will be counted by how many low signals that is triggered within the set time.
|
||||
* Active only on high: the double clicks will be counted by how many high signals that is triggered within the set time.
|
||||
|
||||
* Active on high & low: the double clicks will be counted by how many high and low signals that is triggered within the set time.
|
||||
This means that a double click could be registered as a press and release of a button. So not actually double click.
|
||||
|
||||
* **Double click max. interval (ms)**: This is the interval that you need to perform the double click within.
|
||||
|
||||
* **Long press event**: If enabled the unit will detect a long press of a button. There's three different behaviors of the long press:
|
||||
|
||||
* Active only on low: this means that the unit will only be triggering the long press event if the signal is low. Two different event
|
||||
values are used, :code:`10` if the state goes from 0 to 1 (:code:`MCP23017#State=10`), and :code:`11` if the state goes
|
||||
from 1 to 0 (:code:`MCP23017#State=11`).
|
||||
|
||||
* Active only on high: same as above but only triggered on high signal.
|
||||
* Active on high & low: the long press will be triggered both on high and low signals.
|
||||
|
||||
* **Long press min interval (ms)**: This is the interval that you need to press the button before the long press event is triggered.
|
||||
|
||||
* **Use safe button (slower)**: This effectively adds an extra De-bounce delay and sends event value ``4`` when reached.
|
||||
|
||||
Data Acquisition
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
This group of settings, **Single event with all values**, **Send to Controller** and **Interval** settings are standard available configuration items. Send to Controller is only visible when one or more Controllers are configured.
|
||||
|
||||
* **Interval** By default, Interval will be set to 60 sec. It is the frequency used to read sensor values and send these to any Controllers configured for this device.
|
||||
|
||||
Values
|
||||
^^^^^^
|
||||
|
||||
The name for the value is initially set to a default name, but can be changed if desired.
|
||||
|
||||
Commands available
|
||||
^^^^^^^^^^^^^^^^^^
|
||||
|
||||
.. include:: P009_commands.repl
|
||||
|
||||
.. Events
|
||||
.. ~~~~~~
|
||||
@@ -42,6 +136,9 @@ Change log
|
||||
.. versionchanged:: 2.0
|
||||
...
|
||||
|
||||
|added|
|
||||
2021-08-04 Replaced single Port inputfield with separate I2CAddress and Port selections.
|
||||
|
||||
|added|
|
||||
Major overhaul for 2.0 release.
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 50 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 34 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 182 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 66 KiB |
+161
-127
@@ -2,9 +2,9 @@
|
||||
#ifdef USES_P009
|
||||
|
||||
|
||||
#include "src/DataStructs/PinMode.h"
|
||||
#include "src/Commands/GPIO.h"
|
||||
#include "src/ESPEasyCore/ESPEasyGPIO.h"
|
||||
# include "src/DataStructs/PinMode.h"
|
||||
# include "src/Commands/GPIO.h"
|
||||
# include "src/ESPEasyCore/ESPEasyGPIO.h"
|
||||
|
||||
// #######################################################################################################
|
||||
// #################################### Plugin 009: MCP23017 input #######################################
|
||||
@@ -35,22 +35,22 @@
|
||||
3: safebutton counter (=0,1)
|
||||
\**************************************************/
|
||||
|
||||
#define PLUGIN_009
|
||||
#define PLUGIN_ID_009 9
|
||||
#define PLUGIN_NAME_009 "Switch input - MCP23017"
|
||||
#define PLUGIN_VALUENAME1_009 "State"
|
||||
#define PLUGIN_009_DOUBLECLICK_MIN_INTERVAL 1000
|
||||
#define PLUGIN_009_DOUBLECLICK_MAX_INTERVAL 3000
|
||||
#define PLUGIN_009_LONGPRESS_MIN_INTERVAL 1000
|
||||
#define PLUGIN_009_LONGPRESS_MAX_INTERVAL 5000
|
||||
#define PLUGIN_009_DC_DISABLED 0
|
||||
#define PLUGIN_009_DC_LOW 1
|
||||
#define PLUGIN_009_DC_HIGH 2
|
||||
#define PLUGIN_009_DC_BOTH 3
|
||||
#define PLUGIN_009_LONGPRESS_DISABLED 0
|
||||
#define PLUGIN_009_LONGPRESS_LOW 1
|
||||
#define PLUGIN_009_LONGPRESS_HIGH 2
|
||||
#define PLUGIN_009_LONGPRESS_BOTH 3
|
||||
# define PLUGIN_009
|
||||
# define PLUGIN_ID_009 9
|
||||
# define PLUGIN_NAME_009 "Switch input - MCP23017"
|
||||
# define PLUGIN_VALUENAME1_009 "State"
|
||||
# define PLUGIN_009_DOUBLECLICK_MIN_INTERVAL 1000
|
||||
# define PLUGIN_009_DOUBLECLICK_MAX_INTERVAL 3000
|
||||
# define PLUGIN_009_LONGPRESS_MIN_INTERVAL 1000
|
||||
# define PLUGIN_009_LONGPRESS_MAX_INTERVAL 5000
|
||||
# define PLUGIN_009_DC_DISABLED 0
|
||||
# define PLUGIN_009_DC_LOW 1
|
||||
# define PLUGIN_009_DC_HIGH 2
|
||||
# define PLUGIN_009_DC_BOTH 3
|
||||
# define PLUGIN_009_LONGPRESS_DISABLED 0
|
||||
# define PLUGIN_009_LONGPRESS_LOW 1
|
||||
# define PLUGIN_009_LONGPRESS_HIGH 2
|
||||
# define PLUGIN_009_LONGPRESS_BOTH 3
|
||||
|
||||
boolean Plugin_009(uint8_t function, struct EventStruct *event, String& string)
|
||||
{
|
||||
@@ -65,7 +65,7 @@ boolean Plugin_009(uint8_t function, struct EventStruct *event, String& string)
|
||||
Device[++deviceCount].Number = PLUGIN_ID_009;
|
||||
Device[deviceCount].Type = DEVICE_TYPE_I2C;
|
||||
Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_SWITCH;
|
||||
Device[deviceCount].Ports = 16;
|
||||
Device[deviceCount].Ports = 0;
|
||||
Device[deviceCount].PullUpOption = false;
|
||||
Device[deviceCount].InverseLogicOption = true;
|
||||
Device[deviceCount].FormulaOption = false;
|
||||
@@ -90,9 +90,28 @@ boolean Plugin_009(uint8_t function, struct EventStruct *event, String& string)
|
||||
}
|
||||
|
||||
case PLUGIN_I2C_HAS_ADDRESS:
|
||||
case PLUGIN_WEBFORM_SHOW_I2C_PARAMS:
|
||||
{
|
||||
const int i2cAddressValues[] = { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27 };
|
||||
success = intArrayContains(8, i2cAddressValues, event->Par1);
|
||||
const uint8_t i2cAddressValues[] = { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27 };
|
||||
|
||||
if (function == PLUGIN_WEBFORM_SHOW_I2C_PARAMS) {
|
||||
String portNames[16];
|
||||
int portValues[16];
|
||||
uint8_t unit = (CONFIG_PORT - 1) / 16;
|
||||
uint8_t port = CONFIG_PORT - (unit * 16);
|
||||
uint8_t address = 0x20 + unit;
|
||||
|
||||
for (uint8_t x = 0; x < 16; x++) {
|
||||
portValues[x] = x + 1;
|
||||
portNames[x] = 'P';
|
||||
portNames[x] += (x < 8 ? 'A' : 'B');
|
||||
portNames[x] += (x < 8 ? x : x - 8);
|
||||
}
|
||||
addFormSelectorI2C(F("p009_i2c"), 8, i2cAddressValues, address);
|
||||
addFormSelector(F("Port"), F("p009_port"), 16, portNames, portValues, port);
|
||||
} else {
|
||||
success = intArrayContains(8, i2cAddressValues, event->Par1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -102,6 +121,7 @@ boolean Plugin_009(uint8_t function, struct EventStruct *event, String& string)
|
||||
const uint32_t key = createKey(PLUGIN_ID_009, CONFIG_PORT);
|
||||
|
||||
auto it = globalMapPortStatus.find(key);
|
||||
|
||||
if (it != globalMapPortStatus.end()) {
|
||||
it->second.previousTask = event->TaskIndex;
|
||||
}
|
||||
@@ -118,15 +138,14 @@ boolean Plugin_009(uint8_t function, struct EventStruct *event, String& string)
|
||||
PCONFIG_FLOAT(1) = PLUGIN_009_DOUBLECLICK_MIN_INTERVAL;
|
||||
}
|
||||
|
||||
uint8_t choiceDC = PCONFIG(4);
|
||||
{
|
||||
const __FlashStringHelper * buttonDC[4];
|
||||
const __FlashStringHelper *buttonDC[4];
|
||||
buttonDC[0] = F("Disabled");
|
||||
buttonDC[1] = F("Active only on LOW (EVENT=3)");
|
||||
buttonDC[2] = F("Active only on HIGH (EVENT=3)");
|
||||
buttonDC[3] = F("Active on LOW & HIGH (EVENT=3)");
|
||||
int buttonDCValues[4] = { PLUGIN_009_DC_DISABLED, PLUGIN_009_DC_LOW, PLUGIN_009_DC_HIGH, PLUGIN_009_DC_BOTH };
|
||||
addFormSelector(F("Doubleclick event"), F("p009_dc"), 4, buttonDC, buttonDCValues, choiceDC);
|
||||
addFormSelector(F("Doubleclick event"), F("p009_dc"), 4, buttonDC, buttonDCValues, PCONFIG(4));
|
||||
}
|
||||
|
||||
addFormNumericBox(F("Doubleclick max. interval (ms)"),
|
||||
@@ -140,10 +159,9 @@ boolean Plugin_009(uint8_t function, struct EventStruct *event, String& string)
|
||||
PCONFIG_FLOAT(2) = PLUGIN_009_LONGPRESS_MIN_INTERVAL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
{
|
||||
uint8_t choiceLP = PCONFIG(5);
|
||||
const __FlashStringHelper * buttonLP[4];
|
||||
const __FlashStringHelper *buttonLP[4];
|
||||
buttonLP[0] = F("Disabled");
|
||||
buttonLP[1] = F("Active only on LOW (EVENT= 10 [NORMAL] or 11 [INVERSED])");
|
||||
buttonLP[2] = F("Active only on HIGH (EVENT= 11 [NORMAL] or 10 [INVERSED])");
|
||||
@@ -151,7 +169,7 @@ boolean Plugin_009(uint8_t function, struct EventStruct *event, String& string)
|
||||
|
||||
int buttonLPValues[4] =
|
||||
{ PLUGIN_009_LONGPRESS_DISABLED, PLUGIN_009_LONGPRESS_LOW, PLUGIN_009_LONGPRESS_HIGH, PLUGIN_009_LONGPRESS_BOTH };
|
||||
addFormSelector(F("Longpress event"), F("p009_lp"), 4, buttonLP, buttonLPValues, choiceLP);
|
||||
addFormSelector(F("Longpress event"), F("p009_lp"), 4, buttonLP, buttonLPValues, PCONFIG(5));
|
||||
}
|
||||
|
||||
addFormNumericBox(F("Longpress min. interval (ms)"),
|
||||
@@ -168,6 +186,10 @@ boolean Plugin_009(uint8_t function, struct EventStruct *event, String& string)
|
||||
|
||||
case PLUGIN_WEBFORM_SAVE:
|
||||
{
|
||||
uint8_t i2c = getFormItemInt(F("p009_i2c"));
|
||||
uint8_t port = getFormItemInt(F("p009_port"));
|
||||
CONFIG_PORT = (((i2c - 0x20) << 4) + port);
|
||||
|
||||
PCONFIG(0) = isFormItemChecked(F("p009_boot"));
|
||||
|
||||
// @giig1967-20181022
|
||||
@@ -209,11 +231,12 @@ boolean Plugin_009(uint8_t function, struct EventStruct *event, String& string)
|
||||
|
||||
// read and store current state to prevent switching at boot time
|
||||
// "state" could be -1, 0 or 1
|
||||
newStatus.state = GPIO_MCP_Read(CONFIG_PORT);
|
||||
newStatus.state = GPIO_MCP_Read(CONFIG_PORT);
|
||||
|
||||
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
|
||||
String log = F("MCP INIT=");
|
||||
log += newStatus.state;
|
||||
addLog(LOG_LEVEL_INFO,log);
|
||||
addLog(LOG_LEVEL_INFO, log);
|
||||
}
|
||||
newStatus.output = newStatus.state;
|
||||
(newStatus.state == -1) ? newStatus.mode = PIN_MODE_OFFLINE : newStatus.mode = PIN_MODE_INPUT_PULLUP; // @giig1967g: if it is in the
|
||||
@@ -265,12 +288,13 @@ boolean Plugin_009(uint8_t function, struct EventStruct *event, String& string)
|
||||
}
|
||||
|
||||
case PLUGIN_TEN_PER_SECOND:
|
||||
{
|
||||
const int8_t state = GPIO_MCP_Read(CONFIG_PORT);
|
||||
const String monitorEventString = F("MCP");
|
||||
/**************************************************************************\
|
||||
20181022 - @giig1967g: new doubleclick logic is:
|
||||
if there is a 'state' change, check debounce period.
|
||||
{
|
||||
const int8_t state = GPIO_MCP_Read(CONFIG_PORT);
|
||||
const String monitorEventString = F("MCP");
|
||||
|
||||
/**************************************************************************\
|
||||
20181022 - @giig1967g: new doubleclick logic is:
|
||||
if there is a 'state' change, check debounce period.
|
||||
Then if doubleclick interval exceeded, reset PCONFIG(7) to 0
|
||||
PCONFIG(7) contains the current status for doubleclick:
|
||||
0: start counting
|
||||
@@ -321,15 +345,15 @@ boolean Plugin_009(uint8_t function, struct EventStruct *event, String& string)
|
||||
}
|
||||
|
||||
// just to simplify the reading of the code
|
||||
#define COUNTER PCONFIG(7)
|
||||
#define DC PCONFIG(4)
|
||||
# define COUNTER PCONFIG(7)
|
||||
# define DC PCONFIG(4)
|
||||
|
||||
// check settings for doubleclick according to the settings
|
||||
if ((COUNTER != 0) || ((COUNTER == 0) && ((DC == 3) || ((DC == 1) && (state == 0)) || ((DC == 2) && (state == 1))))) {
|
||||
PCONFIG(7)++;
|
||||
}
|
||||
#undef DC
|
||||
#undef COUNTER
|
||||
# undef DC
|
||||
# undef COUNTER
|
||||
|
||||
// switchstate[event->TaskIndex] = state;
|
||||
if ((currentStatus.mode == PIN_MODE_OFFLINE) ||
|
||||
@@ -364,10 +388,12 @@ boolean Plugin_009(uint8_t function, struct EventStruct *event, String& string)
|
||||
log += output_value;
|
||||
addLog(LOG_LEVEL_INFO, log);
|
||||
}
|
||||
|
||||
// send task event
|
||||
sendData(event);
|
||||
|
||||
// send monitor event
|
||||
if (currentStatus.monitor) sendMonitorEvent(monitorEventString.c_str(), CONFIG_PORT, output_value);
|
||||
if (currentStatus.monitor) { sendMonitorEvent(monitorEventString.c_str(), CONFIG_PORT, output_value); }
|
||||
|
||||
// Reset forceEvent
|
||||
currentStatus.forceEvent = 0;
|
||||
@@ -378,13 +404,13 @@ boolean Plugin_009(uint8_t function, struct EventStruct *event, String& string)
|
||||
}
|
||||
|
||||
// just to simplify the reading of the code
|
||||
#define LP PCONFIG(5)
|
||||
#define FIRED PCONFIG(6)
|
||||
# define LP PCONFIG(5)
|
||||
# define FIRED PCONFIG(6)
|
||||
|
||||
// check if LP is enabled and if LP has not fired yet
|
||||
else if (!FIRED && ((LP == 3) || ((LP == 1) && (state == 0)) || ((LP == 2) && (state == 1)))) {
|
||||
#undef LP
|
||||
#undef FIRED
|
||||
# undef LP
|
||||
# undef FIRED
|
||||
|
||||
/**************************************************************************\
|
||||
20181022 - @giig1967g: new longpress logic is:
|
||||
@@ -429,10 +455,12 @@ boolean Plugin_009(uint8_t function, struct EventStruct *event, String& string)
|
||||
log += output_value;
|
||||
addLog(LOG_LEVEL_INFO, log);
|
||||
}
|
||||
|
||||
// send task event
|
||||
sendData(event);
|
||||
|
||||
// send monitor event
|
||||
if (currentStatus.monitor) sendMonitorEvent(monitorEventString.c_str(), CONFIG_PORT, output_value);
|
||||
if (currentStatus.monitor) { sendMonitorEvent(monitorEventString.c_str(), CONFIG_PORT, output_value); }
|
||||
|
||||
// reset Userdata so it displays the correct state value in the web page
|
||||
UserVar[event->BaseVarIndex] = sendState ? 1 : 0;
|
||||
@@ -456,7 +484,7 @@ boolean Plugin_009(uint8_t function, struct EventStruct *event, String& string)
|
||||
// send task event: DO NOT SEND TASK EVENT
|
||||
//sendData(event);
|
||||
// send monitor event
|
||||
if (currentStatus.monitor) sendMonitorEvent(monitorEventString.c_str(), CONFIG_PORT, 4);
|
||||
if (currentStatus.monitor) { sendMonitorEvent(monitorEventString.c_str(), CONFIG_PORT, 4); }
|
||||
|
||||
// reset Userdata so it displays the correct state value in the web page
|
||||
UserVar[event->BaseVarIndex] = tempUserVar;
|
||||
@@ -474,10 +502,12 @@ boolean Plugin_009(uint8_t function, struct EventStruct *event, String& string)
|
||||
log += F(" is offline (EVENT= -1)");
|
||||
addLog(LOG_LEVEL_INFO, log);
|
||||
}
|
||||
|
||||
// send task event
|
||||
sendData(event);
|
||||
|
||||
// send monitor event
|
||||
if (currentStatus.monitor) sendMonitorEvent(monitorEventString.c_str(), CONFIG_PORT, -1);
|
||||
if (currentStatus.monitor) { sendMonitorEvent(monitorEventString.c_str(), CONFIG_PORT, -1); }
|
||||
|
||||
savePortStatus(key, currentStatus);
|
||||
}
|
||||
@@ -528,8 +558,8 @@ boolean Plugin_009(uint8_t function, struct EventStruct *event, String& string)
|
||||
|
||||
case PLUGIN_WRITE:
|
||||
{
|
||||
//String log;
|
||||
//String command = parseString(string, 1);
|
||||
// String log;
|
||||
// String command = parseString(string, 1);
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -576,64 +606,66 @@ boolean Plugin_009(uint8_t function, struct EventStruct *event, String& string)
|
||||
// ********************************************************************************
|
||||
// MCP23017 read
|
||||
// ********************************************************************************
|
||||
/*
|
||||
int8_t Plugin_009_Read(uint8_t Par1)
|
||||
{
|
||||
int8_t state = -1;
|
||||
uint8_t unit = (Par1 - 1) / 16;
|
||||
uint8_t port = Par1 - (unit * 16);
|
||||
uint8_t address = 0x20 + unit;
|
||||
uint8_t IOBankValueReg = 0x12;
|
||||
|
||||
if (port > 8)
|
||||
{
|
||||
/*
|
||||
int8_t Plugin_009_Read(uint8_t Par1)
|
||||
{
|
||||
int8_t state = -1;
|
||||
uint8_t unit = (Par1 - 1) / 16;
|
||||
uint8_t port = Par1 - (unit * 16);
|
||||
uint8_t address = 0x20 + unit;
|
||||
uint8_t IOBankValueReg = 0x12;
|
||||
|
||||
if (port > 8)
|
||||
{
|
||||
port = port - 8;
|
||||
IOBankValueReg++;
|
||||
}
|
||||
}
|
||||
|
||||
// get the current pin status
|
||||
Wire.beginTransmission(address);
|
||||
Wire.write(IOBankValueReg); // IO data register
|
||||
Wire.endTransmission();
|
||||
Wire.requestFrom(address, (uint8_t)0x1);
|
||||
// get the current pin status
|
||||
Wire.beginTransmission(address);
|
||||
Wire.write(IOBankValueReg); // IO data register
|
||||
Wire.endTransmission();
|
||||
Wire.requestFrom(address, (uint8_t)0x1);
|
||||
|
||||
if (Wire.available())
|
||||
{
|
||||
if (Wire.available())
|
||||
{
|
||||
state = ((Wire.read() & _BV(port - 1)) >> (port - 1));
|
||||
}
|
||||
return state;
|
||||
}
|
||||
*/
|
||||
}
|
||||
return state;
|
||||
}
|
||||
*/
|
||||
|
||||
// ********************************************************************************
|
||||
// MCP23017 write
|
||||
// ********************************************************************************
|
||||
/*
|
||||
boolean Plugin_009_Write(uint8_t Par1, uint8_t Par2)
|
||||
{
|
||||
boolean success = false;
|
||||
uint8_t portvalue = 0;
|
||||
uint8_t unit = (Par1 - 1) / 16;
|
||||
uint8_t port = Par1 - (unit * 16);
|
||||
uint8_t address = 0x20 + unit;
|
||||
uint8_t IOBankConfigReg = 0;
|
||||
uint8_t IOBankValueReg = 0x12;
|
||||
|
||||
if (port > 8)
|
||||
{
|
||||
/*
|
||||
boolean Plugin_009_Write(uint8_t Par1, uint8_t Par2)
|
||||
{
|
||||
boolean success = false;
|
||||
uint8_t portvalue = 0;
|
||||
uint8_t unit = (Par1 - 1) / 16;
|
||||
uint8_t port = Par1 - (unit * 16);
|
||||
uint8_t address = 0x20 + unit;
|
||||
uint8_t IOBankConfigReg = 0;
|
||||
uint8_t IOBankValueReg = 0x12;
|
||||
|
||||
if (port > 8)
|
||||
{
|
||||
port = port - 8;
|
||||
IOBankConfigReg++;
|
||||
IOBankValueReg++;
|
||||
}
|
||||
}
|
||||
|
||||
// turn this port into output, first read current config
|
||||
Wire.beginTransmission(address);
|
||||
Wire.write(IOBankConfigReg); // IO config register
|
||||
Wire.endTransmission();
|
||||
Wire.requestFrom(address, (uint8_t)0x1);
|
||||
// turn this port into output, first read current config
|
||||
Wire.beginTransmission(address);
|
||||
Wire.write(IOBankConfigReg); // IO config register
|
||||
Wire.endTransmission();
|
||||
Wire.requestFrom(address, (uint8_t)0x1);
|
||||
|
||||
if (Wire.available())
|
||||
{
|
||||
if (Wire.available())
|
||||
{
|
||||
portvalue = Wire.read();
|
||||
portvalue &= ~(1 << (port - 1)); // change pin from (default) input to output
|
||||
|
||||
@@ -642,16 +674,16 @@ boolean Plugin_009_Write(uint8_t Par1, uint8_t Par2)
|
||||
Wire.write(IOBankConfigReg); // IO config register
|
||||
Wire.write(portvalue);
|
||||
Wire.endTransmission();
|
||||
}
|
||||
}
|
||||
|
||||
// get the current pin status
|
||||
Wire.beginTransmission(address);
|
||||
Wire.write(IOBankValueReg); // IO data register
|
||||
Wire.endTransmission();
|
||||
Wire.requestFrom(address, (uint8_t)0x1);
|
||||
// get the current pin status
|
||||
Wire.beginTransmission(address);
|
||||
Wire.write(IOBankValueReg); // IO data register
|
||||
Wire.endTransmission();
|
||||
Wire.requestFrom(address, (uint8_t)0x1);
|
||||
|
||||
if (Wire.available())
|
||||
{
|
||||
if (Wire.available())
|
||||
{
|
||||
portvalue = Wire.read();
|
||||
|
||||
if (Par2 == 1) {
|
||||
@@ -667,37 +699,39 @@ boolean Plugin_009_Write(uint8_t Par1, uint8_t Par2)
|
||||
Wire.write(portvalue);
|
||||
Wire.endTransmission();
|
||||
success = true;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
*/
|
||||
}
|
||||
return success;
|
||||
}
|
||||
*/
|
||||
|
||||
// ********************************************************************************
|
||||
// MCP23017 config
|
||||
// ********************************************************************************
|
||||
/*
|
||||
void Plugin_009_Config(uint8_t Par1, uint8_t Par2)
|
||||
{
|
||||
// boolean success = false;
|
||||
uint8_t portvalue = 0;
|
||||
uint8_t unit = (Par1 - 1) / 16;
|
||||
uint8_t port = Par1 - (unit * 16);
|
||||
uint8_t address = 0x20 + unit;
|
||||
uint8_t IOBankConfigReg = 0xC;
|
||||
|
||||
if (port > 8)
|
||||
{
|
||||
/*
|
||||
void Plugin_009_Config(uint8_t Par1, uint8_t Par2)
|
||||
{
|
||||
// boolean success = false;
|
||||
uint8_t portvalue = 0;
|
||||
uint8_t unit = (Par1 - 1) / 16;
|
||||
uint8_t port = Par1 - (unit * 16);
|
||||
uint8_t address = 0x20 + unit;
|
||||
uint8_t IOBankConfigReg = 0xC;
|
||||
|
||||
if (port > 8)
|
||||
{
|
||||
port = port - 8;
|
||||
IOBankConfigReg++;
|
||||
}
|
||||
}
|
||||
|
||||
// turn this port pullup on
|
||||
Wire.beginTransmission(address);
|
||||
Wire.write(IOBankConfigReg);
|
||||
Wire.endTransmission();
|
||||
Wire.requestFrom(address, (uint8_t)0x1);
|
||||
// turn this port pullup on
|
||||
Wire.beginTransmission(address);
|
||||
Wire.write(IOBankConfigReg);
|
||||
Wire.endTransmission();
|
||||
Wire.requestFrom(address, (uint8_t)0x1);
|
||||
|
||||
if (Wire.available())
|
||||
{
|
||||
if (Wire.available())
|
||||
{
|
||||
portvalue = Wire.read();
|
||||
|
||||
if (Par2 == 1) {
|
||||
@@ -712,7 +746,7 @@ void Plugin_009_Config(uint8_t Par1, uint8_t Par2)
|
||||
Wire.write(IOBankConfigReg); // IO config register
|
||||
Wire.write(portvalue);
|
||||
Wire.endTransmission();
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
*/
|
||||
#endif // USES_P009
|
||||
|
||||
Reference in New Issue
Block a user