From fd5120aaf24ef8062c36ef378da653ae797cbd3f Mon Sep 17 00:00:00 2001 From: esp8266nu Date: Tue, 8 Sep 2015 15:01:11 +0000 Subject: [PATCH] fix commit --- _P001_Switch.ino | 67 ++++++ _P002_ADC.ino | 41 ++++ _P003_Pulse.ino | 140 ++++++++++++ _P004_Dallas.ino | 143 ++++++++++++ _P005_DHT.ino | 194 +++++++++++++++++ _P006_BMP085.ino | 235 ++++++++++++++++++++ _P007_PCF8591.ino | 67 ++++++ _P008_RFID.ino | 103 +++++++++ _P009_MCP.ino | 63 ++++++ _P010_BH1750.ino | 56 +++++ _P011_PMD.ino | 49 +++++ _P012_PMA.ino | 50 +++++ __Plugin.ino | 532 +++++++++++++++++++++++++++++++++++++++++++++ __ReleaseNotes.ino | 134 ++++++++++++ 14 files changed, 1874 insertions(+) create mode 100644 _P001_Switch.ino create mode 100644 _P002_ADC.ino create mode 100644 _P003_Pulse.ino create mode 100644 _P004_Dallas.ino create mode 100644 _P005_DHT.ino create mode 100644 _P006_BMP085.ino create mode 100644 _P007_PCF8591.ino create mode 100644 _P008_RFID.ino create mode 100644 _P009_MCP.ino create mode 100644 _P010_BH1750.ino create mode 100644 _P011_PMD.ino create mode 100644 _P012_PMA.ino create mode 100644 __Plugin.ino create mode 100644 __ReleaseNotes.ino diff --git a/_P001_Switch.ino b/_P001_Switch.ino new file mode 100644 index 000000000..5fcbf7d31 --- /dev/null +++ b/_P001_Switch.ino @@ -0,0 +1,67 @@ +//####################################################################################################### +//#################################### Plugin 001: Input Switch ######################################### +//####################################################################################################### + +#define PLUGIN_001 +#define PLUGIN_ID_001 1 + +boolean Plugin_001(byte function, struct EventStruct *event, String& string) +{ + boolean success = false; + static byte switchstate[TASKS_MAX]; + + switch (function) + { + + case PLUGIN_DEVICE_ADD: + { + Device[++deviceCount].Number = PLUGIN_ID_001; + strcpy(Device[deviceCount].Name, "Switch input"); + Device[deviceCount].Type = DEVICE_TYPE_SINGLE; + Device[deviceCount].VType = 10; + Device[deviceCount].Ports = 0; + Device[deviceCount].PullUpOption = true; + Device[deviceCount].InverseLogicOption = true; + Device[deviceCount].FormulaOption = false; + Device[deviceCount].ValueCount = 1; + strcpy(Device[deviceCount].ValueNames[0], "Switch"); + break; + } + + case PLUGIN_INIT: + { + if (Settings.TaskDevicePin1PullUp[event->TaskIndex]) + { + Serial.print(F("INIT : InputPullup ")); + pinMode(Settings.TaskDevicePin1[event->TaskIndex], INPUT_PULLUP); + } + else + { + Serial.print(F("INIT : Input ")); + pinMode(Settings.TaskDevicePin1[event->TaskIndex], INPUT); + } + switchstate[event->TaskIndex] = digitalRead(Settings.TaskDevicePin1[event->TaskIndex]); + success = true; + break; + } + + case PLUGIN_TEN_PER_SECOND: + { + byte state = digitalRead(Settings.TaskDevicePin1[event->TaskIndex]); + if (state != switchstate[event->TaskIndex]) + { + Serial.print(F("SW : State ")); + Serial.println(state); + switchstate[event->TaskIndex] = state; + if (Settings.TaskDevicePin1Inversed[event->TaskIndex]) + state = !state; + UserVar[event->BaseVarIndex] = state; + sendData(event->TaskIndex, 10, Settings.TaskDeviceID[event->TaskIndex], event->BaseVarIndex); + } + success = true; + break; + } + + } + return success; +} diff --git a/_P002_ADC.ino b/_P002_ADC.ino new file mode 100644 index 000000000..2c2cff636 --- /dev/null +++ b/_P002_ADC.ino @@ -0,0 +1,41 @@ +//####################################################################################################### +//#################################### Plugin 002: Analog ############################################### +//####################################################################################################### + +#define PLUGIN_002 +#define PLUGIN_ID_002 2 + +boolean Plugin_002(byte function, struct EventStruct *event, String& string) +{ + boolean success = false; + + switch (function) + { + + case PLUGIN_DEVICE_ADD: + { + Device[++deviceCount].Number = PLUGIN_ID_002; + strcpy(Device[deviceCount].Name, "Analog input"); + Device[deviceCount].Type = DEVICE_TYPE_ANALOG; + Device[deviceCount].VType = 1; + Device[deviceCount].Ports = 0; + Device[deviceCount].PullUpOption = false; + Device[deviceCount].InverseLogicOption = false; + Device[deviceCount].FormulaOption = true; + Device[deviceCount].ValueCount = 1; + strcpy(Device[deviceCount].ValueNames[0], "Analog"); + break; + } + + case PLUGIN_COMMAND: + { + int value = analogRead(A0); + UserVar[event->BaseVarIndex] = (float)value; + Serial.print("ADC : Analog value: "); + Serial.println(value); + success = true; + break; + } + } + return success; +} diff --git a/_P003_Pulse.ino b/_P003_Pulse.ino new file mode 100644 index 000000000..1be4ba15f --- /dev/null +++ b/_P003_Pulse.ino @@ -0,0 +1,140 @@ +//####################################################################################################### +//#################################### Plugin 003: Pulse ############################################### +//####################################################################################################### + +#define PLUGIN_003 +#define PLUGIN_ID_003 3 + +unsigned long Plugin_003_pulseCounter[TASKS_MAX]; +unsigned long Plugin_003_pulseTotalCounter[TASKS_MAX]; + +boolean Plugin_003(byte function, struct EventStruct *event, String& string) +{ + boolean success = false; + + switch (function) + { + + case PLUGIN_DEVICE_ADD: + { + Device[++deviceCount].Number = PLUGIN_ID_003; + strcpy(Device[deviceCount].Name, "Pulse Counter"); + Device[deviceCount].Type = DEVICE_TYPE_SINGLE; + Device[deviceCount].VType = 1; + Device[deviceCount].Ports = 0; + Device[deviceCount].PullUpOption = false; + Device[deviceCount].InverseLogicOption = false; + Device[deviceCount].FormulaOption = true; + Device[deviceCount].ValueCount = 1; + strcpy(Device[deviceCount].ValueNames[0], "Count"); + break; + } + + case PLUGIN_WEBFORM_VALUES: + { + string += F(""); + string += Plugin_003_pulseCounter[event->TaskIndex]; + string += F(""); + string += Plugin_003_pulseTotalCounter[event->TaskIndex]; + success = true; + break; + } + + case PLUGIN_INIT: + { + Serial.print(F("INIT : Pulse ")); + Serial.println(Settings.TaskDevicePin1[event->TaskIndex]); + pinMode(Settings.TaskDevicePin1[event->TaskIndex], INPUT_PULLUP); + Plugin_003_pulseinit(Settings.TaskDevicePin1[event->TaskIndex], event->TaskIndex); + success = true; + break; + } + + case PLUGIN_COMMAND: + { + UserVar[event->BaseVarIndex] = Plugin_003_pulseCounter[event->TaskIndex]; + Plugin_003_pulseCounter[event->TaskIndex] = 0; + success = true; + break; + } + } + return success; +} + +/*********************************************************************************************\ + * Pulse Counters +\*********************************************************************************************/ +void Plugin_003_pulse_interrupt1() +{ + Plugin_003_pulseCounter[0]++; + Plugin_003_pulseTotalCounter[0]++; +} +void Plugin_003_pulse_interrupt2() +{ + Plugin_003_pulseCounter[1]++; + Plugin_003_pulseTotalCounter[1]++; +} +void Plugin_003_pulse_interrupt3() +{ + Plugin_003_pulseCounter[2]++; + Plugin_003_pulseTotalCounter[2]++; +} +void Plugin_003_pulse_interrupt4() +{ + Plugin_003_pulseCounter[3]++; + Plugin_003_pulseTotalCounter[3]++; +} +void Plugin_003_pulse_interrupt5() +{ + Plugin_003_pulseCounter[4]++; + Plugin_003_pulseTotalCounter[4]++; +} +void Plugin_003_pulse_interrupt6() +{ + Plugin_003_pulseCounter[5]++; + Plugin_003_pulseTotalCounter[5]++; +} +void Plugin_003_pulse_interrupt7() +{ + Plugin_003_pulseCounter[6]++; + Plugin_003_pulseTotalCounter[6]++; +} +void Plugin_003_pulse_interrupt8() +{ + Plugin_003_pulseCounter[7]++; + Plugin_003_pulseTotalCounter[7]++; +} + +void Plugin_003_pulseinit(byte Par1, byte Index) +{ + // Init IO pins + Serial.println("PULSE: Init"); + switch (Index) + { + case 0: + attachInterrupt(Par1, Plugin_003_pulse_interrupt1, FALLING); + break; + case 1: + attachInterrupt(Par1, Plugin_003_pulse_interrupt2, FALLING); + break; + case 2: + attachInterrupt(Par1, Plugin_003_pulse_interrupt3, FALLING); + break; + case 3: + attachInterrupt(Par1, Plugin_003_pulse_interrupt4, FALLING); + break; + case 4: + attachInterrupt(Par1, Plugin_003_pulse_interrupt5, FALLING); + break; + case 5: + attachInterrupt(Par1, Plugin_003_pulse_interrupt6, FALLING); + break; + case 6: + attachInterrupt(Par1, Plugin_003_pulse_interrupt7, FALLING); + break; + case 7: + attachInterrupt(Par1, Plugin_003_pulse_interrupt8, FALLING); + break; + } +} + diff --git a/_P004_Dallas.ino b/_P004_Dallas.ino new file mode 100644 index 000000000..d348928e3 --- /dev/null +++ b/_P004_Dallas.ino @@ -0,0 +1,143 @@ +//####################################################################################################### +//#################################### Plugin 004: TempSensor Dallas DS18B20 ########################### +//####################################################################################################### + +#define PLUGIN_004 +#define PLUGIN_ID_004 4 + +uint8_t Plugin_004_DallasPin; + +boolean Plugin_004(byte function, struct EventStruct *event, String& string) +{ + boolean success = false; + static unsigned int Call_Status = 0x00; // Each bit represents one relative port. 0=not called before, 1=already called before. + + switch (function) + { + + case PLUGIN_DEVICE_ADD: + { + Device[++deviceCount].Number = PLUGIN_ID_004; + strcpy(Device[deviceCount].Name, "Temperature DS18b20"); + Device[deviceCount].Type = DEVICE_TYPE_SINGLE; + Device[deviceCount].VType = 1; + Device[deviceCount].Ports = 0; + Device[deviceCount].PullUpOption = false; + Device[deviceCount].InverseLogicOption = false; + Device[deviceCount].FormulaOption = true; + Device[deviceCount].ValueCount = 1; + strcpy(Device[deviceCount].ValueNames[0], "Temperature"); + break; + } + + case PLUGIN_COMMAND: + { + int DSTemp; // Temperature in 16-bit Dallas format. + byte ScratchPad[12]; // Scratchpad buffer Dallas sensor. + byte RelativePort = Settings.TaskDevicePin1[event->TaskIndex]; + + Plugin_004_DallasPin = Settings.TaskDevicePin1[event->TaskIndex]; + + noInterrupts(); + while (!(bitRead(Call_Status, RelativePort))) + { + // if this is the very first call to the sensor on this port, reset it to wake it up + boolean present = Plugin_004_DS_reset(); + bitSet(Call_Status, RelativePort); + } + boolean present = Plugin_004_DS_reset(); Plugin_004_DS_write(0xCC /* rom skip */); Plugin_004_DS_write(0x44 /* start conversion */); + interrupts(); + + if (present) + { + delay(800); // neccesary delay + + noInterrupts(); + Plugin_004_DS_reset(); Plugin_004_DS_write(0xCC /* rom skip */); Plugin_004_DS_write(0xBE /* Read Scratchpad */); + + digitalWrite(Plugin_004_DallasPin, LOW); + pinMode(Plugin_004_DallasPin, INPUT); + + for (byte i = 0; i < 9; i++) // copy 8 bytes + ScratchPad[i] = Plugin_004_DS_read(); + interrupts(); + + DSTemp = (ScratchPad[1] << 8) + ScratchPad[0]; + UserVar[event->BaseVarIndex] = (float(DSTemp) * 0.0625); + Serial.print("DS : Temperature: "); + Serial.println(UserVar[event->BaseVarIndex]); + success = true; + } + break; + } + + } + return success; +} + +uint8_t Plugin_004_DS_read(void) +{ + uint8_t bitMask; + uint8_t r = 0; + uint8_t BitRead; + + for (bitMask = 0x01; bitMask; bitMask <<= 1) + { + pinMode(Plugin_004_DallasPin, OUTPUT); + digitalWrite(Plugin_004_DallasPin, LOW); + delayMicroseconds(3); + + pinMode(Plugin_004_DallasPin, INPUT); // let pin float, pull up will raise + delayMicroseconds(10); + BitRead = digitalRead(Plugin_004_DallasPin); + delayMicroseconds(53); + + if (BitRead) + r |= bitMask; + } + return r; +} + +void Plugin_004_DS_write(uint8_t ByteToWrite) +{ + uint8_t bitMask; + + pinMode(Plugin_004_DallasPin, OUTPUT); + for (bitMask = 0x01; bitMask; bitMask <<= 1) + { // BitWrite + digitalWrite(Plugin_004_DallasPin, LOW); + if (((bitMask & ByteToWrite) ? 1 : 0) & 1) + { + delayMicroseconds(5);// Dallas spec.= 5..15 uSec. + digitalWrite(Plugin_004_DallasPin, HIGH); + delayMicroseconds(55);// Dallas spec.= 60uSec. + } + else + { + delayMicroseconds(55);// Dallas spec.= 60uSec. + digitalWrite(Plugin_004_DallasPin, HIGH); + delayMicroseconds(5);// Dallas spec.= 5..15 uSec. + } + } +} + +uint8_t Plugin_004_DS_reset() +{ + uint8_t r; + uint8_t retries = 125; + + pinMode(Plugin_004_DallasPin, INPUT); + do { // wait until the wire is high... just in case + if (--retries == 0) return 0; + delayMicroseconds(2); + } while ( !digitalRead(Plugin_004_DallasPin)); + + pinMode(Plugin_004_DallasPin, OUTPUT); digitalWrite(Plugin_004_DallasPin, LOW); + delayMicroseconds(492); // Dallas spec. = Min. 480uSec. Arduino 500uSec. + pinMode(Plugin_004_DallasPin, INPUT); //Float + delayMicroseconds(40); + r = !digitalRead(Plugin_004_DallasPin); + delayMicroseconds(420); + return r; +} + diff --git a/_P005_DHT.ino b/_P005_DHT.ino new file mode 100644 index 000000000..5f5619fdf --- /dev/null +++ b/_P005_DHT.ino @@ -0,0 +1,194 @@ +//####################################################################################################### +//######################## Plugin 006: Temperature and Humidity sensor DHT 11/22 ######################## +//####################################################################################################### + +#define PLUGIN_005 +#define PLUGIN_ID_005 5 + +uint8_t Plugin_005_DHT_Pin; + +boolean Plugin_005(byte function, struct EventStruct *event, String& string) +{ + boolean success = false; + + switch (function) + { + case PLUGIN_DEVICE_ADD: + { + Device[++deviceCount].Number = PLUGIN_ID_005; + strcpy(Device[deviceCount].Name, "Temp + Hum DHT"); + Device[deviceCount].Type = DEVICE_TYPE_SINGLE; + Device[deviceCount].VType = 2; + Device[deviceCount].Ports = 0; + Device[deviceCount].PullUpOption = false; + Device[deviceCount].InverseLogicOption = false; + Device[deviceCount].FormulaOption = true; + Device[deviceCount].ValueCount = 2; + strcpy(Device[deviceCount].ValueNames[0], "Temperature"); + strcpy(Device[deviceCount].ValueNames[1], "Humidity"); + break; + } + + case PLUGIN_WEBFORM_LOAD: + { + byte choice = Settings.TaskDevicePluginConfig[event->TaskIndex][0]; + String options[2]; + options[0] = F("DHT 11"); + options[1] = F("DHT 22"); + int optionValues[2]; + optionValues[0] = 11; + optionValues[1] = 22; + string += F("DHT Type: