MCP23017 changes

Changed MCP23017 plugin to scan inputs realtime instead of using the
system timer mechanism
Changed MCP23017 default pullup resistors on input pins
Moved MCP23017 output and generic GPIO and PWM to device plugins
Added simple pulse option for GPIO outputs (only for small pulses less
than a few seconds).
This commit is contained in:
mvdbro
2015-10-02 11:34:23 +02:00
parent 317b8a2d59
commit 11b306f681
19 changed files with 402 additions and 312 deletions
+14 -27
View File
@@ -76,6 +76,9 @@ boolean sendData(struct EventStruct *event)
PiDome_sendDataMQTT(event);
break;
}
PluginCall(PLUGIN_EVENT_OUT, event, dummyString);
if (Settings.MessageDelay != 0)
{
char log[30];
@@ -85,6 +88,7 @@ boolean sendData(struct EventStruct *event)
while (millis() < timer)
backgroundtasks();
}
}
//#endif
@@ -423,43 +427,26 @@ void MQTTMessage(String *topic, String *message)
{
String cmd = topicSplit[1];
int pin = topicSplit[2].toInt();
if (cmd == "gpio")
{
int value = message->toFloat();
char cmd[80];
sprintf_P(cmd, PSTR("gpio,%u,%u"), pin, value);
Serial.println(cmd);
#ifdef ESP_CONNEXIO
ExecuteLine(cmd, VALUE_SOURCE_SERIAL);
#endif
#ifdef ESP_EASY
ExecuteCommand(cmd);
#endif
}
int value = message->toFloat();
struct EventStruct TempEvent;
TempEvent.Par1 = pin;
TempEvent.Par2 = value;
PluginCall(PLUGIN_WRITE, &TempEvent, cmd);
break;
}
case PROTOCOL_PIDOME_MQTT:
{
String name = topicSplit[4];
String cmd = topicSplit[5];
int pin = topicSplit[6].toInt();
int value = (*message == "true");
struct EventStruct TempEvent;
TempEvent.Par1 = pin;
TempEvent.Par2 = value;
if (name == Settings.Name)
{
if (cmd == "gpio")
{
int value = (*message == "true");
char cmd[80];
sprintf_P(cmd, PSTR("gpio,%u,%u"), pin, value);
Serial.println(cmd);
#ifdef ESP_CONNEXIO
ExecuteLine(cmd, VALUE_SOURCE_SERIAL);
#endif
#ifdef ESP_EASY
ExecuteCommand(cmd);
#endif
}
PluginCall(PLUGIN_WRITE, &TempEvent, cmd);
}
break;
}
+1 -86
View File
@@ -1,86 +1 @@
// These are output devices that do not need a device plugin (yet).
// May change in the future if we decide that all IO should be done through plugins.
/*********************************************************************************************\
* Extender (Arduino Mini Pro connected through I2C)
* The Mini Pro needs a small sketch to support this
\*********************************************************************************************/
int extender(byte Cmd, byte Port, int Value)
{
uint8_t address = 0x7f;
Wire.beginTransmission(address);
Wire.write(Cmd);
Wire.write(Port);
Wire.write(Value & 0xff);
Wire.write((Value >> 8));
Wire.endTransmission();
if (Cmd == 2 || Cmd == 4)
{
delay(1); // remote unit needs some time to do the adc stuff
Wire.requestFrom(address, (uint8_t)0x1);
if (Wire.available())
{
int portvalue = Wire.read();
//portvalue += Wire.read()*256;
return portvalue;
}
}
return -1;
}
/*********************************************************************************************\
* MCP23017 OUTPUT
\*********************************************************************************************/
boolean mcp23017(byte Par1, byte Par2)
{
boolean success = false;
byte portvalue = 0;
byte unit = (Par1 - 1) / 16;
byte port = Par1 - (unit * 16);
uint8_t address = 0x20 + unit;
byte IOBankConfigReg = 0;
byte 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);
if (Wire.available())
{
portvalue = Wire.read();
portvalue &= ~(1 << (port - 1)); // change pin from (default) input to output
// write new IO config
Wire.beginTransmission(address);
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);
if (Wire.available())
{
portvalue = Wire.read();
if (Par2 == 1)
portvalue |= (1 << (port - 1));
else
portvalue &= ~(1 << (port - 1));
// write back new data
Wire.beginTransmission(address);
Wire.write(IOBankValueReg);
Wire.write(portvalue);
Wire.endTransmission();
success = true;
}
}
// obsolete, all code moved to plugins
+9 -3
View File
@@ -79,7 +79,7 @@
#define ESP_PROJECT_PID 2015050101L
#define ESP_EASY
#define VERSION 9
#define BUILD 26
#define BUILD 27
#define REBOOT_ON_MAX_CONNECTION_FAILURES 30
#define FEATURE_SPIFFS false
@@ -118,7 +118,7 @@
#define PLUGIN_INIT_ALL 1
#define PLUGIN_INIT 2
#define PLUGIN_COMMAND 3
#define PLUGIN_READ 3
#define PLUGIN_ONCE_A_SECOND 4
#define PLUGIN_TEN_PER_SECOND 5
#define PLUGIN_DEVICE_ADD 6
@@ -128,6 +128,8 @@
#define PLUGIN_WEBFORM_VALUES 10
#define PLUGIN_GET_DEVICENAME 11
#define PLUGIN_GET_DEVICEVALUENAMES 12
#define PLUGIN_WRITE 13
#define PLUGIN_EVENT_OUT 14
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
@@ -216,6 +218,10 @@ struct EventStruct
byte BaseVarIndex;
byte idx;
byte sensorType;
int Par1;
int Par2;
int Par3;
byte OriginTaskIndex;
};
struct LogStruct
@@ -461,7 +467,7 @@ void SensorSend()
for (byte varNr = 0; varNr < VARS_PER_TASK; varNr++)
preValue[varNr] = UserVar[varIndex + varNr];
success = PluginCall(PLUGIN_COMMAND, &TempEvent, dummyString);
success = PluginCall(PLUGIN_READ, &TempEvent, dummyString);
if (success)
{
+3 -77
View File
@@ -20,10 +20,9 @@ void ExecuteCommand(char *Line)
// commands for debugging
// ****************************************
if (strcasecmp_P(Command, PSTR("resetpid")) == 0)
if (strcasecmp_P(Command, PSTR("Pullup")) == 0)
{
Settings.PID = 123456789;
SaveSettings();
Plugin_009_Config(18, 1);
}
#if FEATURE_SPIFFS
@@ -41,82 +40,9 @@ void ExecuteCommand(char *Line)
}
// ****************************************
// commands to execute io tasks
// special commands for old nodo plugin
// ****************************************
if (strcasecmp_P(Command, PSTR("GPIO")) == 0)
{
if (Par1 >= 0 && Par1 <= 16)
{
pinMode(Par1, OUTPUT);
digitalWrite(Par1, Par2);
if (printToWeb)
{
printWebString += F("GPIO ");
printWebString += Par1;
printWebString += F(" Set to ");
printWebString += Par2;
printWebString += F("<BR>");
}
}
}
if (strcasecmp_P(Command, PSTR("PWM")) == 0)
{
if (Par1 >= 0 && Par1 <= 1023)
{
pinMode(Par1, OUTPUT);
analogWrite(Par1, Par2);
if (printToWeb)
{
printWebString += F("GPIO ");
printWebString += Par1;
printWebString += F(" Set PWM to ");
printWebString += Par2;
printWebString += F("<BR>");
}
}
}
if (strcasecmp_P(Command, PSTR("MCPGPIO")) == 0)
{
mcp23017(Par1, Par2);
if (printToWeb)
{
printWebString += F("MCPGPIO ");
printWebString += Par1;
printWebString += F(" Set to ");
printWebString += Par2;
printWebString += F("<BR>");
}
}
if (strcasecmp_P(Command, PSTR("ExtRead")) == 0)
{
uint8_t address = 0x7f;
Wire.requestFrom(address, (uint8_t)Par1);
if (Wire.available())
{
for (byte x = 0; x < Par1; x++)
Serial.println(Wire.read());
}
}
if (strcasecmp_P(Command, PSTR("ExtGPIO")) == 0)
extender(1, Par1, Par2);
if (strcasecmp_P(Command, PSTR("ExtPWM")) == 0)
extender(3, Par1, Par2);
if (strcasecmp_P(Command, PSTR("ExtGPIORead")) == 0)
{
byte value = extender(2, Par1, 0);
Serial.println(value);
}
if (strcasecmp_P(Command, PSTR("ExtADCRead")) == 0)
{
int value = extender(4, Par1, 0);
Serial.println(value);
}
if (strcasecmp_P(Command, PSTR("DomoticzSend")) == 0)
{
if (GetArgv(Line, TmpStr1, 4))
+12 -15
View File
@@ -1204,28 +1204,25 @@ void handle_control() {
urlDecode(command);
boolean validCmd = false;
struct EventStruct TempEvent;
char TmpStr1[80];
TmpStr1[0] = 0;
TempEvent.Par1 = 0;
TempEvent.Par2 = 0;
TempEvent.Par3 = 0;
char Cmd[40];
Cmd[0] = 0;
GetArgv(command, Cmd, 1);
if ((strcasecmp_P(Cmd, PSTR("gpio")) == 0) || (strcasecmp_P(Cmd, PSTR("pwm")) == 0) || (strcasecmp_P(Cmd, PSTR("mcpgpio")) == 0))
validCmd = true;
String reply = "";
if (GetArgv(command, TmpStr1, 2)) TempEvent.Par1 = str2int(TmpStr1);
if (GetArgv(command, TmpStr1, 3)) TempEvent.Par2 = str2int(TmpStr1);
if (GetArgv(command, TmpStr1, 4)) TempEvent.Par3 = str2int(TmpStr1);
printToWeb = true;
printWebString = "";
String reply = "";
if (validCmd)
{
#ifdef ESP_CONNEXIO
ExecuteLine(command, VALUE_SOURCE_SERIAL);
#endif
#ifdef ESP_EASY
ExecuteCommand(command);
#endif
}
else
if (!PluginCall(PLUGIN_WRITE, &TempEvent, webrequest))
reply += F("Unknown or restricted command!");
reply += printWebString;
+65 -2
View File
@@ -149,9 +149,9 @@ boolean Plugin_001(byte function, struct EventStruct *event, String& string)
outputstate[event->TaskIndex] = !outputstate[event->TaskIndex];
}
}
// send if output needs to be changed
if (currentOutputState!=outputstate[event->TaskIndex])
if (currentOutputState != outputstate[event->TaskIndex])
{
byte sendState = outputstate[event->TaskIndex];
if (Settings.TaskDevicePin1Inversed[event->TaskIndex])
@@ -170,6 +170,69 @@ boolean Plugin_001(byte function, struct EventStruct *event, String& string)
break;
}
case PLUGIN_WRITE:
{
String tmpString = string;
int argIndex = tmpString.indexOf(',');
if (argIndex)
tmpString = tmpString.substring(0, argIndex);
if (tmpString.equalsIgnoreCase("GPIO"))
{
success = true;
if (event->Par1 >= 0 && event->Par1 <= 16)
{
pinMode(event->Par1, OUTPUT);
digitalWrite(event->Par1, event->Par2);
if (printToWeb)
{
printWebString += F("GPIO ");
printWebString += event->Par1;
printWebString += F(" Set to ");
printWebString += event->Par2;
printWebString += F("<BR>");
}
}
}
if (tmpString.equalsIgnoreCase("PWM"))
{
success = true;
if (event->Par1 >= 0 && event->Par1 <= 1023)
{
pinMode(event->Par1, OUTPUT);
analogWrite(event->Par1, event->Par2);
if (printToWeb)
{
printWebString += F("GPIO ");
printWebString += event->Par1;
printWebString += F(" Set PWM to ");
printWebString += event->Par2;
printWebString += F("<BR>");
}
}
}
if (tmpString.equalsIgnoreCase("Pulse"))
{
success = true;
if (event->Par1 >= 0 && event->Par1 <= 1023)
{
pinMode(event->Par1, OUTPUT);
digitalWrite(event->Par1, event->Par2);
delay(event->Par3);
digitalWrite(event->Par1, !event->Par2);
if (printToWeb)
{
printWebString += F("GPIO ");
printWebString += event->Par1;
printWebString += F(" Pulsed for ");
printWebString += event->Par3;
printWebString += F(" mS<BR>");
}
}
}
break;
}
}
return success;
}
+1 -1
View File
@@ -38,7 +38,7 @@ boolean Plugin_002(byte function, struct EventStruct *event, String& string)
break;
}
case PLUGIN_COMMAND:
case PLUGIN_READ:
{
int value = analogRead(A0);
UserVar[event->BaseVarIndex] = (float)value;
+1 -1
View File
@@ -67,7 +67,7 @@ boolean Plugin_003(byte function, struct EventStruct *event, String& string)
break;
}
case PLUGIN_COMMAND:
case PLUGIN_READ:
{
UserVar[event->BaseVarIndex] = Plugin_003_pulseCounter[event->TaskIndex];
Plugin_003_pulseCounter[event->TaskIndex] = 0;
+1 -1
View File
@@ -91,7 +91,7 @@ boolean Plugin_004(byte function, struct EventStruct *event, String& string)
break;
}
case PLUGIN_COMMAND:
case PLUGIN_READ:
{
uint8_t addr[8];
// Load ROM address from tasksettings
+1 -1
View File
@@ -77,7 +77,7 @@ boolean Plugin_005(byte function, struct EventStruct *event, String& string)
break;
}
case PLUGIN_COMMAND:
case PLUGIN_READ:
{
byte dht_dat[5];
byte dht_in;
+1 -1
View File
@@ -42,7 +42,7 @@ boolean Plugin_006(byte function, struct EventStruct *event, String& string)
break;
}
case PLUGIN_COMMAND:
case PLUGIN_READ:
{
if (!Plugin_006_init)
{
+1 -1
View File
@@ -54,7 +54,7 @@ boolean Plugin_007(byte function, struct EventStruct *event, String& string)
break;
}
case PLUGIN_COMMAND:
case PLUGIN_READ:
{
byte unit = (Settings.TaskDevicePort[event->TaskIndex] - 1) / 4;
byte port = Settings.TaskDevicePort[event->TaskIndex] - (unit * 4);
+168 -23
View File
@@ -10,6 +10,7 @@
boolean Plugin_009(byte function, struct EventStruct *event, String& string)
{
boolean success = false;
static byte switchstate[TASKS_MAX];
switch (function)
{
@@ -39,36 +40,180 @@ boolean Plugin_009(byte function, struct EventStruct *event, String& string)
break;
}
case PLUGIN_COMMAND:
case PLUGIN_INIT:
{
byte Par1 = Settings.TaskDevicePort[event->TaskIndex];
byte portvalue = 0;
byte unit = (Par1 - 1) / 16;
byte port = Par1 - (unit * 16);
uint8_t address = 0x20 + unit;
byte IOBankConfigReg = 0;
byte IOBankValueReg = 0x12;
if (port > 8)
// read and store current state to prevent switching at boot time
switchstate[event->TaskIndex] = Plugin_009_Read(Settings.TaskDevicePort[event->TaskIndex]);
// Turn on Pullup resistor
Plugin_009_Config(Settings.TaskDevicePort[event->TaskIndex], 1);
success = true;
break;
}
case PLUGIN_TEN_PER_SECOND:
{
int state = Plugin_009_Read(Settings.TaskDevicePort[event->TaskIndex]);
if (state != -1)
{
port = port - 8;
IOBankConfigReg++;
IOBankValueReg++;
if (state != switchstate[event->TaskIndex])
{
Serial.print(F("MCP : State "));
Serial.println(state);
switchstate[event->TaskIndex] = state;
UserVar[event->BaseVarIndex] = state;
event->sensorType = SENSOR_TYPE_SWITCH;
sendData(event);
}
}
// 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())
success = true;
break;
}
case PLUGIN_WRITE:
{
String tmpString = string;
int argIndex = tmpString.indexOf(',');
if (argIndex)
tmpString = tmpString.substring(0, argIndex);
if (tmpString.equalsIgnoreCase("MCPGPIO"))
{
portvalue = ((Wire.read() & _BV(port - 1)) >> (port - 1));
UserVar[event->BaseVarIndex] = (float)portvalue;
Serial.print(F("MCP : Input Value : "));
Serial.println(UserVar[event->BaseVarIndex]);
success = true;
Plugin_009_Write(event->Par1, event->Par2);
if (printToWeb)
{
printWebString += F("MCPGPIO ");
printWebString += event->Par1;
printWebString += F(" Set to ");
printWebString += event->Par2;
printWebString += F("<BR>");
}
}
break;
}
}
return success;
}
}
//********************************************************************************
// MCP23017 read
//********************************************************************************
int Plugin_009_Read(byte Par1)
{
int8_t state = -1;
byte unit = (Par1 - 1) / 16;
byte port = Par1 - (unit * 16);
uint8_t address = 0x20 + unit;
byte 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);
if (Wire.available())
{
state = ((Wire.read() & _BV(port - 1)) >> (port - 1));
}
return state;
}
//********************************************************************************
// MCP23017 write
//********************************************************************************
boolean Plugin_009_Write(byte Par1, byte Par2)
{
boolean success = false;
byte portvalue = 0;
byte unit = (Par1 - 1) / 16;
byte port = Par1 - (unit * 16);
uint8_t address = 0x20 + unit;
byte IOBankConfigReg = 0;
byte 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);
if (Wire.available())
{
portvalue = Wire.read();
portvalue &= ~(1 << (port - 1)); // change pin from (default) input to output
// write new IO config
Wire.beginTransmission(address);
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);
if (Wire.available())
{
portvalue = Wire.read();
if (Par2 == 1)
portvalue |= (1 << (port - 1));
else
portvalue &= ~(1 << (port - 1));
// write back new data
Wire.beginTransmission(address);
Wire.write(IOBankValueReg);
Wire.write(portvalue);
Wire.endTransmission();
success = true;
}
}
//********************************************************************************
// MCP23017 config
//********************************************************************************
boolean Plugin_009_Config(byte Par1, byte Par2)
{
boolean success = false;
byte portvalue = 0;
byte unit = (Par1 - 1) / 16;
byte port = Par1 - (unit * 16);
uint8_t address = 0x20 + unit;
byte 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);
if (Wire.available())
{
portvalue = Wire.read();
if (Par2 == 1)
portvalue |= (1 << (port - 1));
else
portvalue &= ~(1 << (port - 1));
// write new IO config
Wire.beginTransmission(address);
Wire.write(IOBankConfigReg); // IO config register
Wire.write(portvalue);
Wire.endTransmission();
}
}
+1 -1
View File
@@ -41,7 +41,7 @@ boolean Plugin_010(byte function, struct EventStruct *event, String& string)
break;
}
case PLUGIN_COMMAND:
case PLUGIN_READ:
{
if (!Plugin_010_init)
{
+51 -23
View File
@@ -8,10 +8,10 @@
#define PLUGIN_VALUENAME1_011 "Switch"
boolean Plugin_011(byte function, struct EventStruct *event, String& string)
{
boolean success=false;
{
boolean success = false;
switch(function)
switch (function)
{
case PLUGIN_DEVICE_ADD:
@@ -37,25 +37,53 @@ boolean Plugin_011(byte function, struct EventStruct *event, String& string)
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_011));
break;
}
case PLUGIN_COMMAND:
{
uint8_t address = 0x7f;
Wire.beginTransmission(address);
Wire.write(2); // Digital Read
Wire.write(Settings.TaskDevicePort[event->TaskIndex]);
Wire.write(0);
Wire.write(0);
Wire.endTransmission();
delay(1); // remote unit needs some time ?
Wire.requestFrom(address, (uint8_t)0x1);
if (Wire.available())
UserVar[event->BaseVarIndex] = Wire.read();
Serial.print(F("PMD : Digital: "));
Serial.println(UserVar[event->BaseVarIndex]);
success=true;
break;
}
}
case PLUGIN_READ:
{
uint8_t address = 0x7f;
Wire.beginTransmission(address);
Wire.write(2); // Digital Read
Wire.write(Settings.TaskDevicePort[event->TaskIndex]);
Wire.write(0);
Wire.write(0);
Wire.endTransmission();
delay(1); // remote unit needs some time ?
Wire.requestFrom(address, (uint8_t)0x1);
if (Wire.available())
UserVar[event->BaseVarIndex] = Wire.read();
Serial.print(F("PMD : Digital: "));
Serial.println(UserVar[event->BaseVarIndex]);
success = true;
break;
}
case PLUGIN_WRITE:
{
String tmpString = string;
int argIndex = tmpString.indexOf(',');
if (argIndex)
tmpString = tmpString.substring(0, argIndex);
if (tmpString.equalsIgnoreCase("EXTGPIO"))
{
success = true;
uint8_t address = 0x7f;
Wire.beginTransmission(address);
Wire.write(1);
Wire.write(event->Par1);
Wire.write(event->Par2 & 0xff);
Wire.write((event->Par2 >> 8));
Wire.endTransmission();
if (printToWeb)
{
printWebString += F("EXTGPIO ");
printWebString += event->Par1;
printWebString += F(" Set to ");
printWebString += event->Par2;
printWebString += F("<BR>");
}
}
break;
}
}
return success;
}
+51 -23
View File
@@ -8,10 +8,10 @@
#define PLUGIN_VALUENAME1_012 "Analog"
boolean Plugin_012(byte function, struct EventStruct *event, String& string)
{
boolean success=false;
{
boolean success = false;
switch(function)
switch (function)
{
case PLUGIN_DEVICE_ADD:
@@ -38,25 +38,53 @@ boolean Plugin_012(byte function, struct EventStruct *event, String& string)
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_012));
break;
}
case PLUGIN_COMMAND:
{
uint8_t address = 0x7f;
Wire.beginTransmission(address);
Wire.write(4); // ADC Read
Wire.write(Settings.TaskDevicePort[event->TaskIndex]);
Wire.write(0);
Wire.write(0);
Wire.endTransmission();
delay(1); // remote unit needs some time to do the adc stuff
Wire.requestFrom(address, (uint8_t)0x1);
if (Wire.available())
UserVar[event->BaseVarIndex] = Wire.read();
Serial.print(F("PMADC: Analog: "));
Serial.println(UserVar[event->BaseVarIndex]);
success=true;
break;
}
}
case PLUGIN_READ:
{
uint8_t address = 0x7f;
Wire.beginTransmission(address);
Wire.write(4); // ADC Read
Wire.write(Settings.TaskDevicePort[event->TaskIndex]);
Wire.write(0);
Wire.write(0);
Wire.endTransmission();
delay(1); // remote unit needs some time to do the adc stuff
Wire.requestFrom(address, (uint8_t)0x1);
if (Wire.available())
UserVar[event->BaseVarIndex] = Wire.read();
Serial.print(F("PMADC: Analog: "));
Serial.println(UserVar[event->BaseVarIndex]);
success = true;
break;
}
case PLUGIN_WRITE:
{
String tmpString = string;
int argIndex = tmpString.indexOf(',');
if (argIndex)
tmpString = tmpString.substring(0, argIndex);
if (tmpString.equalsIgnoreCase("EXTPWM"))
{
success = true;
uint8_t address = 0x7f;
Wire.beginTransmission(address);
Wire.write(3);
Wire.write(event->Par1);
Wire.write(event->Par2 & 0xff);
Wire.write((event->Par2 >> 8));
Wire.endTransmission();
if (printToWeb)
{
printWebString += F("EXTPWM ");
printWebString += event->Par1;
printWebString += F(" Set to ");
printWebString += event->Par2;
printWebString += F("<BR>");
}
}
break;
}
}
return success;
}
+1 -1
View File
@@ -103,7 +103,7 @@ boolean Plugin_013(byte function, struct EventStruct *event, String& string)
break;
}
case PLUGIN_COMMAND: // If we select value mode, read and send the value based on global timer
case PLUGIN_READ: // If we select value mode, read and send the value based on global timer
{
if (Settings.TaskDevicePluginConfig[event->TaskIndex][0] == 1)
{
+14 -25
View File
@@ -448,31 +448,29 @@ void PluginInit(void)
/*********************************************************************************************\
* Function call to all or specific plugins
\*********************************************************************************************/
byte PluginCall(byte Function, struct EventStruct *Event, String& str)
byte PluginCall(byte Function, struct EventStruct *event, String& str)
{
int x;
struct EventStruct TempEvent;
if (Event == 0)
Event=&TempEvent;
if (event == 0)
event=&TempEvent;
switch (Function)
{
// Call to all plugins
//case PLUGIN_EVENT_IN:
//case PLUGIN_EVENT_OUT:
// Unconditional calls to all plugins
case PLUGIN_DEVICE_ADD:
for (x = 0; x < PLUGIN_MAX; x++)
if (Plugin_id[x] != 0)
Plugin_ptr[x](Function, Event, str);
Plugin_ptr[x](Function, event, str);
return true;
break;
// Call to all plugins. Return at first match
case PLUGIN_EVENTLIST_ADD:
case PLUGIN_WRITE:
for (x = 0; x < PLUGIN_MAX; x++)
if (Plugin_id[x] != 0)
if (Plugin_ptr[x](Function, Event, str))
if (Plugin_ptr[x](Function, event, str))
return true;
break;
@@ -480,6 +478,7 @@ byte PluginCall(byte Function, struct EventStruct *Event, String& str)
case PLUGIN_ONCE_A_SECOND:
case PLUGIN_TEN_PER_SECOND:
case PLUGIN_INIT_ALL:
case PLUGIN_EVENT_OUT:
{
if (Function == PLUGIN_INIT_ALL)
Function = PLUGIN_INIT;
@@ -492,17 +491,11 @@ byte PluginCall(byte Function, struct EventStruct *Event, String& str)
TempEvent.BaseVarIndex = y * VARS_PER_TASK;
TempEvent.idx = Settings.TaskDeviceID[y];
TempEvent.sensorType = Device[DeviceIndex].VType;
TempEvent.OriginTaskIndex=event->TaskIndex;
for (x = 0; x < PLUGIN_MAX; x++)
{
if (Plugin_id[x] == Settings.TaskDeviceNumber[y])
{
if ((Function != PLUGIN_ONCE_A_SECOND) && (Function != PLUGIN_TEN_PER_SECOND))
{
//Serial.print("All Used Plugin nr ");
//Serial.print(Plugin_id[x]);
//Serial.print(" tasknr ");
//Serial.println(y);
}
Plugin_ptr[x](Function, &TempEvent, str);
}
}
@@ -512,23 +505,19 @@ byte PluginCall(byte Function, struct EventStruct *Event, String& str)
break;
}
// Call to specific plugin that is used for this task
// Call to specific plugin that is used for current task
case PLUGIN_INIT:
case PLUGIN_WEBFORM_LOAD:
case PLUGIN_WEBFORM_SAVE:
case PLUGIN_WEBFORM_VALUES:
case PLUGIN_GET_DEVICEVALUENAMES:
case PLUGIN_COMMAND:
case PLUGIN_READ:
for (x = 0; x < PLUGIN_MAX; x++)
{
if ((Plugin_id[x] != 0 ) && (Plugin_id[x] == Settings.TaskDeviceNumber[Event->TaskIndex]))
if ((Plugin_id[x] != 0 ) && (Plugin_id[x] == Settings.TaskDeviceNumber[event->TaskIndex]))
{
Event->BaseVarIndex = Event->TaskIndex * VARS_PER_TASK;
//Serial.print("This Plugin nr ");
//Serial.print(Plugin_id[x]);
//Serial.print(" tasknr ");
//Serial.println(Event->TaskIndex);
return Plugin_ptr[x](Function, Event, str);
event->BaseVarIndex = event->TaskIndex * VARS_PER_TASK;
return Plugin_ptr[x](Function, event, str);
}
}
return false;
+6
View File
@@ -1,3 +1,9 @@
// R27 02-10-2015
// Changed MCP23017 plugin to scan inputs realtime instead of using the system timer mechanism
// Changed MCP23017 default pullup resistors on input pins
// Moved MCP23017 output and generic GPIO and PWM to device plugins
// Added simple pulse option for GPIO outputs (only for small pulses less than a few seconds).
// R26 01-10-2015
// Changed internal stylesheet to new skin
// Save configuration settings into SPIFFS reserved area without using SPIFFS