From 35280ccf53916fc6c6a93cdf337ee2de0bf60a35 Mon Sep 17 00:00:00 2001 From: Gregg Date: Sun, 23 Aug 2020 18:57:11 -0500 Subject: [PATCH] Created Zephyr2 Create logic to track whether fan and light is on, withouth needing to rely on emulated pushbuttons. --- examples/ZephyrHood2/DEV_Identify.h | 38 +++++ examples/ZephyrHood2/DEV_Zephyr.h | 219 +++++++++++++++++++++++++++ examples/ZephyrHood2/ZephyrHood2.ino | 36 +++++ 3 files changed, 293 insertions(+) create mode 100644 examples/ZephyrHood2/DEV_Identify.h create mode 100644 examples/ZephyrHood2/DEV_Zephyr.h create mode 100644 examples/ZephyrHood2/ZephyrHood2.ino diff --git a/examples/ZephyrHood2/DEV_Identify.h b/examples/ZephyrHood2/DEV_Identify.h new file mode 100644 index 0000000..17f7638 --- /dev/null +++ b/examples/ZephyrHood2/DEV_Identify.h @@ -0,0 +1,38 @@ + +////////////////////////////////// +// DEVICE-SPECIFIC SERVICES // +////////////////////////////////// + +struct DEV_Identify : Service::AccessoryInformation { + + int nBlinks; // number of times to blink built-in LED in identify routine + SpanCharacteristic *identify; // reference to the Identify Characteristic + + DEV_Identify(char *name, char *manu, char *sn, char *model, char *version, int nBlinks, ServiceType sType=ServiceType::Regular) : Service::AccessoryInformation(sType){ + + new Characteristic::Name(name); // create all the required Characteristics with values set based on above arguments + new Characteristic::Manufacturer(manu); + new Characteristic::SerialNumber(sn); + new Characteristic::Model(model); + new Characteristic::FirmwareRevision(version); + identify=new Characteristic::Identify(); // store a reference to the Identify Characteristic for use below + + this->nBlinks=nBlinks; // store the number of times to blink the built-in LED + + pinMode(LED_BUILTIN,OUTPUT); // make sure built-in LED is set for output + } + + StatusCode update(){ + + for(int i=0;icode=code; + this->buttonPin=buttonPin; + + Serial.print("Configuring Zephyr Vent Hood Light 433MHz Transmitter with code: "); + Serial.print(code,HEX); + Serial.print("\n"); + + new SpanButton(buttonPin); + } + + StatusCode update(){ + + if(power->getNewVal()){ + LOG1("Activating Zephyr Vent Hood Light\n"); + transmitZephyr(code); + } + + return(StatusCode::OK); + + } // update + + void loop(){ + + if(power->getVal() && power->timeVal()>500){ // check that power is true, and that time since last modification is greater than 3 seconds + LOG1("Resetting Zephyr Vent Hood Light Control\n"); // log message + power->setVal(false); // set power to false + } + + } // loop + + void button(int pin, boolean isLong) override { + + LOG1("Activating Zephyr Vent Hood Light\n"); + transmitZephyr(code); + power->setVal(true); + + } // button + +}; + +////////////////////////////////// + +struct DEV_ZephyrFan : Service::Fan { + + uint32_t fanCode; + uint32_t powerCode; + SpanCharacteristic *power; + int fanPin; + + DEV_ZephyrFan(uint32_t fanCode, uint32_t powerCode, int fanPin, ServiceType mod=ServiceType::Regular) : Service::Fan(mod){ + + power=new Characteristic::Active(); + new Characteristic::Name("Vent Fan"); + this->fanCode=fanCode; + this->powerCode=powerCode; + this->fanPin=fanPin; + + Serial.print("Configuring Zephyr Vent Hood Fan 433MHz Transmitter with fan code: "); + Serial.print(fanCode,HEX); + Serial.print(" power code: "); + Serial.print(powerCode,HEX); + Serial.print("\n"); + + new SpanButton(fanPin); + } + + StatusCode update(){ + + if(power->getNewVal()){ + LOG1("Zephyr Vent Hood Fan: Power On\n"); + transmitZephyr(fanCode); + } else + if(power->getVal()){ // only transmit power code if we know power is really on + LOG1("Zephyr Vent Hood Fan: Power Off\n"); + transmitZephyr(powerCode); + } + + return(StatusCode::OK); + + } // update + + void loop(){ + +// if(power->getVal() && power->timeVal()>500){ // check that power is true, and that time since last modification is greater than 3 seconds +// LOG1("Resetting Zephyr Vent Hood Fan Control\n"); // log message +// power->setVal(false); // set power to false +// } + + } // loop + + void button(int pin, boolean isLong) override { + + if(!isLong){ + LOG1("Zephyr Vent Hood Fan Short Button Press: Speed Change\n"); + transmitZephyr(fanCode); + if(!power->getVal()) + power->setVal(true); + } else + if(power->getVal()){ + LOG1("Zephyr Vent Hood Fan Long Button Press: Power Off\n"); + transmitZephyr(powerCode); + power->setVal(false); + } else { + LOG1("Zephyr Vent Hood Fan Long Button Press: Power is already off!\n"); + } + + } // button + +}; + +////////////////////////////////// + +struct DEV_ZephyrPower : Service::Switch { + + uint32_t code; + SpanCharacteristic *power; + int buttonPin; + + DEV_ZephyrPower(uint32_t code, int buttonPin, ServiceType mod=ServiceType::Regular) : Service::Switch(mod){ + + power=new Characteristic::On(); + new Characteristic::Name("Vent Power"); + this->code=code; + this->buttonPin=buttonPin; + + Serial.print("Configuring Zephyr Vent Hood Power 433MHz Transmitter with code: "); + Serial.print(code,HEX); + Serial.print("\n"); + new SpanButton(buttonPin); + + } + + StatusCode update(){ + + if(power->getNewVal()){ + LOG1("Activating Zephyr Vent Hood Power\n"); + transmitZephyr(code); + } + + return(StatusCode::OK); + + } // update + + void loop(){ + + if(power->getVal() && power->timeVal()>500){ // check that power is true, and that time since last modification is greater than 3 seconds + LOG1("Resetting Zephyr Vent Hood Power Control\n"); // log message + power->setVal(false); // set power to false + } + + } // loop + + void button(int pin, boolean isLong) override { + + LOG1("Activating Zephyr Vent Hood Power\n"); + transmitZephyr(code); + power->setVal(true); + + } // button + +}; + +////////////////////////////////// + +void transmitZephyr(uint32_t code){ + char c[32]; + sprintf(c,"Transmitting code: %lx\n",code); + LOG1(c); + + RF433.clear(); + + for(int b=19;b>0;b--){ + if(code&(1<