IP Configuration
This commit is contained in:
116
lib/ST_Anything_RCSwitch/EX_RCSwitch.cpp
Normal file
116
lib/ST_Anything_RCSwitch/EX_RCSwitch.cpp
Normal file
@@ -0,0 +1,116 @@
|
||||
//******************************************************************************************
|
||||
// File: EX_RCSwitch.cpp
|
||||
// Author: Dan G Ogorchock
|
||||
//
|
||||
// Summary: EX_RCSwitch is a class which implements the SmartThings "Switch" device capability.
|
||||
// It inherits from the st::Executor class.
|
||||
//
|
||||
// Create an instance of this class in your sketch's global variable section
|
||||
// For Example: st::EX_RCSwitch executor1("switch1", PIN_RCSWITCH, 35754004, 26, 18976788, 26, 174, 1, 15, LOW);
|
||||
//
|
||||
// st::EX_RCSwitch() constructor requires the following arguments
|
||||
// - String &name - REQUIRED - the name of the object - must match the Groovy ST_Anything DeviceType tile name
|
||||
// - byte transmitterPin - REQUIRED - the Arduino Pin to be used as a digital output for the RCSwitch object's transmitter pin
|
||||
// - unsigned long onCode - REQUIRED - the "on" code for RCSwitch send() command
|
||||
// - unsigned int onLength - REQUIRED - the "on" code's length for RCSwitch send() command
|
||||
// - unsigned long offCode - REQUIRED - the "off" code for RCSwitch send() command
|
||||
// - unsigned int offLength - REQUIRED - the "off" code's length for RCSwitch send() command
|
||||
// - unsigned int pulseLength - REQUIRED - the length of the RF pulse for RCSwitch send() command
|
||||
// - byte protocol - OPTIONAL - defaults to "1" - the protocol for RCSwitch send() command
|
||||
// - byte repeatTransmits - OPTIONAL - defaults to "15" - the number of repeated transmits for RCSwitch send() command
|
||||
// - bool startingState - OPTIONAL - the value desired for the initial state of the switch. LOW = "off", HIGH = "on"
|
||||
//
|
||||
// Change History:
|
||||
//
|
||||
// Date Who What
|
||||
// ---- --- ----
|
||||
// 2015-01-26 Dan Ogorchock Original Creation
|
||||
// 2015-05-20 Dan Ogorchock Improved to work with Etekcity ZAP 3F 433Mhz RF Outlets
|
||||
// 2018-08-30 Dan Ogorchock Modified comment section above to comply with new Parent/Child Device Handler requirements
|
||||
//
|
||||
//******************************************************************************************
|
||||
|
||||
#include "EX_RCSwitch.h"
|
||||
|
||||
#include "Constants.h"
|
||||
#include "Everything.h"
|
||||
|
||||
namespace st
|
||||
{
|
||||
//private
|
||||
void EX_RCSwitch::writeStateToPin()
|
||||
{
|
||||
if (m_bCurrentState)
|
||||
{
|
||||
m_myRCSwitch.send(m_onCode, m_onLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_myRCSwitch.send(m_offCode, m_offLength);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//public
|
||||
//constructor
|
||||
EX_RCSwitch::EX_RCSwitch(const __FlashStringHelper *name, byte transmitterPin, unsigned long onCode, unsigned int onLength, unsigned long offCode, unsigned int offLength, unsigned int pulseLength, byte protocol, byte repeatTransmits, bool startingState) :
|
||||
Executor(name),
|
||||
m_bCurrentState(startingState),
|
||||
m_myRCSwitch(RCSwitch()),
|
||||
m_onCode(onCode),
|
||||
m_onLength(onLength),
|
||||
m_offCode(offCode),
|
||||
m_offLength(offLength)
|
||||
{
|
||||
setPin(transmitterPin);
|
||||
m_myRCSwitch.setProtocol(protocol); // set protocol (default is 1, will work for most outlets)
|
||||
m_myRCSwitch.setRepeatTransmit(repeatTransmits); // set number of transmission repetitions.
|
||||
m_myRCSwitch.setPulseLength(pulseLength); // Set pulse length.
|
||||
|
||||
}
|
||||
|
||||
//destructor
|
||||
EX_RCSwitch::~EX_RCSwitch()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void EX_RCSwitch::init()
|
||||
{
|
||||
writeStateToPin();
|
||||
Everything::sendSmartString(getName() + " " + (m_bCurrentState == HIGH ? F("on") : F("off")));
|
||||
}
|
||||
|
||||
void EX_RCSwitch::beSmart(const String &str)
|
||||
{
|
||||
String s=str.substring(str.indexOf(' ')+1);
|
||||
if (st::Executor::debug) {
|
||||
Serial.print(F("EX_RCSwitch::beSmart s = "));
|
||||
Serial.println(s);
|
||||
}
|
||||
if(s==F("on"))
|
||||
{
|
||||
m_bCurrentState=HIGH;
|
||||
}
|
||||
else if(s==F("off"))
|
||||
{
|
||||
m_bCurrentState=LOW;
|
||||
}
|
||||
|
||||
writeStateToPin();
|
||||
|
||||
Everything::sendSmartString(getName() + " " + (m_bCurrentState == HIGH?F("on"):F("off")));
|
||||
}
|
||||
|
||||
void EX_RCSwitch::refresh()
|
||||
{
|
||||
Everything::sendSmartString(getName() + " " + (m_bCurrentState == HIGH?F("on"):F("off")));
|
||||
}
|
||||
|
||||
void EX_RCSwitch::setPin(byte pin)
|
||||
{
|
||||
m_nPin = pin;
|
||||
m_myRCSwitch.enableTransmit((int)m_nPin);
|
||||
}
|
||||
}
|
||||
78
lib/ST_Anything_RCSwitch/EX_RCSwitch.h
Normal file
78
lib/ST_Anything_RCSwitch/EX_RCSwitch.h
Normal file
@@ -0,0 +1,78 @@
|
||||
//******************************************************************************************
|
||||
// File: EX_RCSwitch.h
|
||||
// Author: Dan G Ogorchock
|
||||
//
|
||||
// Summary: EX_RCSwitch is a class which implements the SmartThings "Switch" device capability.
|
||||
// It inherits from the st::Executor class.
|
||||
//
|
||||
// Create an instance of this class in your sketch's global variable section
|
||||
// For Example: st::EX_RCSwitch executor1("switch1", PIN_RCSWITCH, 35754004, 26, 18976788, 26, 174, 1, 15, LOW);
|
||||
//
|
||||
// st::EX_RCSwitch() constructor requires the following arguments
|
||||
// - String &name - REQUIRED - the name of the object - must match the Groovy ST_Anything DeviceType tile name
|
||||
// - byte transmitterPin - REQUIRED - the Arduino Pin to be used as a digital output for the RCSwitch object's transmitter pin
|
||||
// - unsigned long onCode - REQUIRED - the "on" code for RCSwitch send() command
|
||||
// - unsigned int onLength - REQUIRED - the "on" code's length for RCSwitch send() command
|
||||
// - unsigned long offCode - REQUIRED - the "off" code for RCSwitch send() command
|
||||
// - unsigned int offLength - REQUIRED - the "off" code's length for RCSwitch send() command
|
||||
// - unsigned int pulseLength - REQUIRED - the length of the RF pulse for RCSwitch send() command
|
||||
// - byte protocol - OPTIONAL - defaults to "1" - the protocol for RCSwitch send() command
|
||||
// - byte repeatTransmits - OPTIONAL - defaults to "15" - the number of repeated transmits for RCSwitch send() command
|
||||
// - bool startingState - OPTIONAL - the value desired for the initial state of the switch. LOW = "off", HIGH = "on"
|
||||
//
|
||||
// Change History:
|
||||
//
|
||||
// Date Who What
|
||||
// ---- --- ----
|
||||
// 2015-01-26 Dan Ogorchock Original Creation
|
||||
// 2015-05-20 Dan Ogorchock Improved to work with Etekcity ZAP 3F 433Mhz RF Outlets
|
||||
// 2018-08-30 Dan Ogorchock Modified comment section above to comply with new Parent/Child Device Handler requirements
|
||||
//
|
||||
//******************************************************************************************
|
||||
#ifndef ST_EX_RCSWITCH
|
||||
#define ST_EX_RCSWITCH
|
||||
|
||||
#include "RCSwitch.h"
|
||||
#include "Executor.h"
|
||||
|
||||
namespace st
|
||||
{
|
||||
class EX_RCSwitch: public Executor
|
||||
{
|
||||
private:
|
||||
bool m_bCurrentState; //HIGH or LOW
|
||||
byte m_nPin; //Arduino Pin used as a RC Transmitter
|
||||
RCSwitch m_myRCSwitch; //RCSwitch Object
|
||||
unsigned long m_onCode; //RCSwitch On Code
|
||||
unsigned int m_onLength; //RCSwitch On Length
|
||||
unsigned long m_offCode; //RCSwitch Off Code
|
||||
unsigned int m_offLength; //RCSwitch Off Length
|
||||
|
||||
void writeStateToPin(); //function to update the Arduino digital output pin via RCSwitch switchOn and switchOff commands
|
||||
|
||||
public:
|
||||
//constructor - called in your sketch's global variable declaration section
|
||||
EX_RCSwitch(const __FlashStringHelper *name, byte transmitterPin, unsigned long onCode, unsigned int onLength, unsigned long offCode, unsigned int offLength, unsigned int pulseLength, byte protocol = 1, byte repeatTransmits = 15, bool startingState = LOW);
|
||||
|
||||
//destructor
|
||||
virtual ~EX_RCSwitch();
|
||||
|
||||
//initialization routine
|
||||
virtual void init();
|
||||
|
||||
//SmartThings Shield data handler (receives command to turn "on" or "off" the switch (digital output)
|
||||
virtual void beSmart(const String &str);
|
||||
|
||||
//called periodically to ensure state of the switch is up to date in the SmartThings Cloud (in case an event is missed)
|
||||
virtual void refresh();
|
||||
|
||||
//gets
|
||||
virtual byte getPin() const {return m_nPin;}
|
||||
|
||||
//sets
|
||||
virtual void setPin(byte pin);
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user