-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from GoWired/dev
Dev
- Loading branch information
Showing
25 changed files
with
1,052 additions
and
375 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
Images/image.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* | ||
* All definitions in one file | ||
* | ||
*/ | ||
|
||
|
||
#ifndef Configuration_h | ||
#define Configuration_h | ||
|
||
/* ******************************************************************************************* | ||
* MySensors Definitions | ||
* *******************************************************************************************/ | ||
// Identification | ||
#define MY_NODE_ID 1 | ||
#define SN "RS485 8RelayDin 1" | ||
#define SV "1.0" | ||
|
||
// Selecting transmission settings | ||
#define MY_RS485 // Enable RS485 transport layer | ||
#define MY_RS485_DE_PIN 7 // DE Pin definition | ||
#define MY_RS485_BAUD_RATE 57600 // Set RS485 baud rate to use | ||
#define MY_RS485_HWSERIAL Serial // Enable for Hardware Serial | ||
#define MY_RS485_SOH_COUNT 3 // Collision avoidance | ||
|
||
// FOTA Feature | ||
#define MY_OTA_FIRMWARE_FEATURE | ||
|
||
// Other | ||
#define MY_TRANSPORT_WAIT_READY_MS 60000 // Time to wait for gateway to respond at startup | ||
|
||
/* ******************************************************************************************* | ||
* General Definitions | ||
* *******************************************************************************************/ | ||
// Relay states | ||
#define RELAY_ON LOW | ||
#define RELAY_OFF HIGH | ||
|
||
#define INTERVAL 300000 // Interval value (ms) for reporting readings of the sensors: temperature, power usage (default 300000) | ||
#define INIT_DELAY 200 // A value (ms) to be multiplied by node ID value to obtain the time to wait during the initialization process | ||
#define PRESENTATION_DELAY 10 // Time (ms) to wait between subsequent presentation messages (default 10) | ||
#define LOOP_TIME 100 // Main loop wait time (ms); (default 100) | ||
|
||
/* ******************************************************************************************* | ||
* IO Config | ||
* *******************************************************************************************/ | ||
#define FIRST_OUTPUT_ID 0 // default 0; should not be altered (expander pins for outputs: 0-7) | ||
#define TOTAL_NUMBER_OF_OUTPUTS 8 // Total number of outputs; value from 0-8 (default 8) | ||
|
||
// Inputs not bound to any outputs (expander pins for inputs: 8-15) | ||
#define INDEPENDENT_IO 0 // Number of independent inputs and outputs; value from 0 to 8 (default 0) | ||
#define INPUT_TYPE 0 // Define input type: 0 - INPUT_PULLUP, 1 - INPUT, 3 - Button | ||
|
||
#define NUMBER_OF_OUTPUTS TOTAL_NUMBER_OF_OUTPUTS-INDEPENDENT_IO | ||
|
||
#define SPECIAL_BUTTON // Enables long press functionality for all buttons | ||
|
||
/* ******************************************************************************************* | ||
* MCU Pin Definitions | ||
* *******************************************************************************************/ | ||
// OUTPUT [RELAY / RGBW] | ||
#define OUTPUT_PIN_1 5 | ||
#define OUTPUT_PIN_2 9 | ||
#define OUTPUT_PIN_3 6 | ||
#define OUTPUT_PIN_4 10 | ||
|
||
// INPUT [BUTTON / SENSOR] | ||
// General input | ||
#define INPUT_PIN_1 2 | ||
#define INPUT_PIN_2 3 | ||
#define INPUT_PIN_3 4 | ||
#define INPUT_PIN_4 A3 | ||
|
||
// Analog input | ||
#define INPUT_PIN_5 A1 | ||
#define INPUT_PIN_6 A2 | ||
#define INPUT_PIN_7 A6 | ||
#define INPUT_PIN_8 A7 | ||
|
||
// Protocols | ||
// 1-wire | ||
#define ONE_WIRE_PIN A0 | ||
|
||
// I2C | ||
#define I2C_PIN_1 A4 | ||
#define I2C_PIN_2 A5 | ||
|
||
/* ******************************************************************************************* | ||
* ERROR REPORTING | ||
* *******************************************************************************************/ | ||
//#define ERROR_REPORTING | ||
#ifdef ERROR_REPORTING | ||
#ifdef POWER_SENSOR | ||
#define ES_ID HYSTERESIS_ID+1 | ||
#endif | ||
#ifdef INTERNAL_TEMP | ||
#define TS_ID ES_ID+1 | ||
#endif | ||
#ifdef EXTERNAL_TEMP | ||
#define ETS_ID TS_ID+1 | ||
#endif | ||
#endif | ||
|
||
//#define RS485_DEBUG | ||
#ifdef RS485_DEBUG | ||
#define DEBUG_ID ETS_ID+1 | ||
#endif | ||
|
||
#endif | ||
/* | ||
* | ||
* EOF | ||
* | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
/* | ||
* PinShift - variable corresponding to arythmetical difference | ||
* between a sensor and its pin | ||
*/ | ||
|
||
#include "ExpanderIO.h" | ||
|
||
PCF8575 Expander; | ||
|
||
/* ******************************************************************************************* | ||
* Constructor | ||
* *******************************************************************************************/ | ||
ExpanderIO::ExpanderIO() { | ||
|
||
NewState = 0; | ||
State = 0; | ||
} | ||
|
||
/* ******************************************************************************************* | ||
* Expander Initialization | ||
* *******************************************************************************************/ | ||
void ExpanderIO::ExpanderInit(uint8_t Address) { | ||
|
||
Expander.begin(Address); | ||
} | ||
|
||
/* ******************************************************************************************* | ||
* Set Values | ||
* *******************************************************************************************/ | ||
void ExpanderIO::SetValues(bool RelayOFF, uint8_t Type, uint8_t Pin1, uint8_t Pin2) { | ||
|
||
_RelayOFF = RelayOFF; | ||
|
||
SensorType = Type; | ||
switch(SensorType) { | ||
// Door/window sensor | ||
case 0: | ||
_SensorPin = Pin1; | ||
Expander.pinMode(_SensorPin, INPUT_PULLUP); | ||
break; | ||
// Motion sensor // not used | ||
case 1: | ||
_SensorPin = Pin1; | ||
Expander.pinMode(_SensorPin, INPUT); | ||
break; | ||
// Relay output | ||
case 2: | ||
_RelayPin = Pin1; | ||
Expander.pinMode(_RelayPin, OUTPUT); | ||
Expander.digitalWrite(_RelayPin, _RelayOFF); | ||
break; | ||
// Button input | ||
case 3: | ||
_SensorPin = Pin1; | ||
Expander.pinMode(_SensorPin, INPUT_PULLUP); | ||
break; | ||
// Button + Relay | ||
case 4: | ||
_SensorPin = Pin1; | ||
_RelayPin = Pin2; | ||
Expander.pinMode(_SensorPin, INPUT_PULLUP); | ||
Expander.pinMode(_RelayPin, OUTPUT); | ||
Expander.digitalWrite(_RelayPin, _RelayOFF); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
/* ******************************************************************************************* | ||
* Input Check | ||
* *******************************************************************************************/ | ||
void ExpanderIO::CheckInput() { | ||
|
||
bool Reading; | ||
bool Shortpress = false; | ||
uint32_t StartTime = millis(); | ||
|
||
do { | ||
if(SensorType == 0 || SensorType == 3 || SensorType == 4) { | ||
// Hardcoded DebounceValue = 50 | ||
Reading = ReadDigital(50, false); | ||
} | ||
else { | ||
Reading = ReadDigital(50, true); | ||
} | ||
|
||
switch(SensorType) { | ||
case 0: | ||
case 1: | ||
if(Reading == true) { | ||
NewState = 1; | ||
} | ||
else { | ||
NewState = 0; | ||
} | ||
break; | ||
case 3: | ||
case 4: | ||
if(!Shortpress && Reading) { | ||
NewState = !State; | ||
Shortpress = true; | ||
} | ||
|
||
// Hardcoded LongpressDuration = 1000 | ||
if(millis() - StartTime > 1000) { | ||
NewState = 2; | ||
break; | ||
} | ||
|
||
if(millis() < StartTime) { | ||
StartTime = millis(); | ||
} | ||
break; | ||
default: | ||
break; | ||
} | ||
} while(Reading); | ||
} | ||
|
||
// Read digital input | ||
bool ExpanderIO::ReadDigital(uint8_t DebounceValue, bool Invert) { | ||
|
||
bool DigitalReading; | ||
bool PreviousReading = false; | ||
bool InputState = false; | ||
uint32_t Timeout = millis(); | ||
uint32_t StartTime = Timeout; | ||
|
||
do { | ||
DigitalReading = (Invert ? Expander.digitalRead(_SensorPin) : !Expander.digitalRead(_SensorPin)); | ||
|
||
if(DigitalReading && !PreviousReading) { | ||
StartTime = millis(); | ||
} | ||
|
||
if(millis() - StartTime > DebounceValue) { | ||
if(DigitalReading) { | ||
InputState = true; | ||
} | ||
} | ||
|
||
if(millis() - Timeout > 255 || millis() < StartTime) { | ||
break; | ||
} | ||
|
||
PreviousReading = DigitalReading; | ||
} while(DigitalReading); | ||
|
||
return InputState; | ||
} | ||
|
||
/* ******************************************************************************************* | ||
* Set Relay | ||
* *******************************************************************************************/ | ||
void ExpanderIO::SetRelay() { | ||
|
||
bool RelayValue = NewState == 1 ? !_RelayOFF : _RelayOFF; | ||
Expander.digitalWrite(_RelayPin, RelayValue); | ||
State = NewState; | ||
} | ||
/* | ||
* | ||
* EOF | ||
* | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* This is a code written for easy management of digital input/output sensors such as door/window/pir security sensors, | ||
* buttons and relays. It menages easy sensor initialization, holds sensor states, changes relays states and provides a quite smart | ||
* function for reading inputs (including special button functionality which change its state after one second of holding a button). | ||
* | ||
* | ||
* SensorType: | ||
* 0 - INPUT_PULLUP sensor | ||
* 1 - INPUT sensor | ||
* 2 - Relay output | ||
* 3 - Button input | ||
* 4 - Button input + Relay output | ||
* | ||
*/ | ||
|
||
#ifndef ExpanderIO_h | ||
#define ExpanderIO_h | ||
|
||
#include "Arduino.h" | ||
#include <Wire.h> | ||
#include <PCF8575.h> | ||
|
||
class ExpanderIO | ||
{ | ||
public: | ||
ExpanderIO(); | ||
|
||
uint8_t SensorType; | ||
uint8_t NewState; | ||
uint8_t State; | ||
|
||
void ExpanderInit(uint8_t Address=0x20); | ||
void SetValues(bool RelayOFF, uint8_t Type, uint8_t Pin1, uint8_t Pin2=0); | ||
void CheckInput(); | ||
void SetRelay(); | ||
bool ReadDigital(uint8_t DebounceValue, bool Invert); | ||
|
||
private: | ||
uint8_t _RelayPin; | ||
uint8_t _SensorPin; | ||
bool _LowStateDetection; | ||
bool _HighStateDetection; | ||
bool _Condition; | ||
bool _RelayOFF; | ||
|
||
}; | ||
|
||
#endif |
Oops, something went wrong.