From 9f7e9a51e5417d28216495a757b9555b5eb5ef07 Mon Sep 17 00:00:00 2001 From: Gregg Date: Sun, 23 Aug 2020 08:21:56 -0500 Subject: [PATCH] Created Zephyr Vent Hood Example --- examples/ZephyrHood/DEV_Identify.h | 42 ++++++++ examples/ZephyrHood/DEV_Led.h | 58 +++++++++++ examples/ZephyrHood/DEV_Zephyr.h | 160 +++++++++++++++++++++++++++++ examples/ZephyrHood/ZephyrHood.ino | 74 +++++++++++++ 4 files changed, 334 insertions(+) create mode 100644 examples/ZephyrHood/DEV_Identify.h create mode 100644 examples/ZephyrHood/DEV_Led.h create mode 100644 examples/ZephyrHood/DEV_Zephyr.h create mode 100644 examples/ZephyrHood/ZephyrHood.ino diff --git a/examples/ZephyrHood/DEV_Identify.h b/examples/ZephyrHood/DEV_Identify.h new file mode 100644 index 0000000..6037d1e --- /dev/null +++ b/examples/ZephyrHood/DEV_Identify.h @@ -0,0 +1,42 @@ + +////////////////////////////////// +// DEVICE-SPECIFIC SERVICES // +////////////////////////////////// + +struct DEV_Identify : Service::AccessoryInformation { + + int nBlinks; // number of times to blink built-in LED in identify routine + SpanCharacteristic *identify; + + DEV_Identify(int nBlinks, char *name, char *model, char *manu, char *sn, char *firm, ServiceType mod=ServiceType::Regular) : Service::AccessoryInformation(mod){ + + new Characteristic::FirmwareRevision(firm); + new Characteristic::Manufacturer(manu); + new Characteristic::Model(model); + new Characteristic::Name(name); + new Characteristic::SerialNumber(sn); + identify=new Characteristic::Identify(); + + this->nBlinks=nBlinks; + + pinMode(LED_BUILTIN,OUTPUT); + } + + + StatusCode update(){ + + if(identify->newValue.BOOL){ + + for(int i=0;i + +struct DEV_DimmableLED : Service::LightBulb { + + // Controls a Dimmable LED connect to pin 'ledPin' + + int ledPin; + SpanCharacteristic *power; + SpanCharacteristic *brightness; + + DEV_DimmableLED(int ledPin, ServiceType mod=ServiceType::Regular) : Service::LightBulb(mod){ + + power=new Characteristic::On(); + brightness=new Characteristic::Brightness(50); + + brightness->range = new SpanRange(20,100,1); + + this->ledPin=ledPin; + + Serial.print("Configuring Dimmable LED on Pin: "); + Serial.println(ledPin); + pinMode(ledPin,OUTPUT); + } + + StatusCode update(){ + + LOG1("Updating Dimmable LED on pin="); + LOG1(ledPin); + LOG1(": Power="); + LOG1(power->value.BOOL?"true":"false"); + LOG1(" Brightness="); + LOG1(brightness->value.INT); + + if(power->isUpdated){ + LOG1(" New Power="); + LOG1(power->newValue.BOOL?"true":"false"); + } + + if(brightness->isUpdated){ + LOG1(" New Brightness="); + LOG1(brightness->newValue.INT); + } + + LOG1("\n"); + + analogWrite(ledPin,power->newValue.BOOL*brightness->newValue.INT,100); + + return(StatusCode::OK); + + } // update +}; + +////////////////////////////////// diff --git a/examples/ZephyrHood/DEV_Zephyr.h b/examples/ZephyrHood/DEV_Zephyr.h new file mode 100644 index 0000000..3ea024a --- /dev/null +++ b/examples/ZephyrHood/DEV_Zephyr.h @@ -0,0 +1,160 @@ + +//////////////////////////////////// +// DEVICE-SPECIFIC SERVICE // +//////////////////////////////////// + +#include "extras/RFControl.h" + +// Zephyr Vent Hood + +// Frequency: 433 MHz +// Encoding: Fixed pulse duration of 850 usec +// 0-Bit: 230 HIGH / 620 LOW +// 1-Bit: 620 HIGH / 230 LOW +// N-Bits: 20 +// N-Cycles: 8 +// Cycle Gap: 4000 usec + +void transmitZephyr(uint32_t code); + +////////////////////////////////// + +struct DEV_ZephyrLight : Service::LightBulb { + + uint32_t code; + SpanCharacteristic *power; + + DEV_ZephyrLight(uint32_t code, ServiceType mod=ServiceType::Regular) : Service::LightBulb(mod){ + + power=new Characteristic::On(); + new SpanTimedReset(500); + new Characteristic::Name("Vent Light"); + this->code=code; + + Serial.print("Configuring Zephyr Vent Hood Light 433MHz Transmitter with code: "); + Serial.print(code,HEX); + Serial.print("\n"); + } + + StatusCode update(){ + + LOG1("Updating Zephyr Vent Hood Light: Power="); + LOG1(power->value.BOOL?"true":"false"); + + if(power->isUpdated){ + LOG1(" New Power="); + LOG1(power->newValue.BOOL?"true":"false"); + } + + LOG1("\n"); + + if(power->newValue.BOOL) + transmitZephyr(code); + + return(StatusCode::OK); + + } // update +}; + +////////////////////////////////// + +struct DEV_ZephyrFan : Service::Fan { + + uint32_t code; + SpanCharacteristic *power; + + DEV_ZephyrFan(uint32_t code, ServiceType mod=ServiceType::Regular) : Service::Fan(mod){ + + power=new Characteristic::Active(); + new SpanTimedReset(500); + new Characteristic::Name("Vent Fan"); + this->code=code; + + Serial.print("Configuring Zephyr Vent Hood Fan 433MHz Transmitter with code: "); + Serial.print(code,HEX); + Serial.print("\n"); + } + + StatusCode update(){ + + LOG1("Updating Zephyr Vent Hood Fan: Power="); + LOG1(power->value.BOOL?"true":"false"); // power is actually a UINT8, but only 0 and 1 are defined so BOOL works as well + + if(power->isUpdated){ + LOG1(" New Power="); + LOG1(power->newValue.BOOL?"true":"false"); + } + + LOG1("\n"); + + if(power->newValue.BOOL) + transmitZephyr(code); + + return(StatusCode::OK); + + } // update +}; + +////////////////////////////////// + +struct DEV_ZephyrPower : Service::Switch { + + uint32_t code; + SpanCharacteristic *power; + + DEV_ZephyrPower(uint32_t code, ServiceType mod=ServiceType::Regular) : Service::Switch(mod){ + + power=new Characteristic::On(); + new SpanTimedReset(500); + new Characteristic::Name("Vent Power"); + this->code=code; + + Serial.print("Configuring Zephyr Vent Hood Power 433MHz Transmitter with code: "); + Serial.print(code,HEX); + Serial.print("\n"); + } + + StatusCode update(){ + + LOG1("Updating Zephyr Vent Hood Power: Power="); + LOG1(power->value.BOOL?"true":"false"); + + if(power->isUpdated){ + LOG1(" New Power="); + LOG1(power->newValue.BOOL?"true":"false"); + } + + LOG1("\n"); + + if(power->newValue.BOOL) + transmitZephyr(code); + + return(StatusCode::OK); + + } // update +}; + +////////////////////////////////// + +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<