Completed Zephyr Vent Hood Example

This commit is contained in:
Gregg 2020-08-23 13:03:14 -05:00
parent 9f7e9a51e5
commit 054d4dbf64
4 changed files with 101 additions and 162 deletions

View File

@ -6,33 +6,29 @@
struct DEV_Identify : Service::AccessoryInformation { struct DEV_Identify : Service::AccessoryInformation {
int nBlinks; // number of times to blink built-in LED in identify routine int nBlinks; // number of times to blink built-in LED in identify routine
SpanCharacteristic *identify; SpanCharacteristic *identify; // reference to the Identify Characteristic
DEV_Identify(int nBlinks, char *name, char *model, char *manu, char *sn, char *firm, ServiceType mod=ServiceType::Regular) : Service::AccessoryInformation(mod){ DEV_Identify(char *name, char *manu, char *sn, char *model, char *version, int nBlinks, ServiceType sType=ServiceType::Regular) : Service::AccessoryInformation(sType){
new Characteristic::FirmwareRevision(firm); new Characteristic::Name(name); // create all the required Characteristics with values set based on above arguments
new Characteristic::Manufacturer(manu); new Characteristic::Manufacturer(manu);
new Characteristic::Model(model);
new Characteristic::Name(name);
new Characteristic::SerialNumber(sn); new Characteristic::SerialNumber(sn);
identify=new Characteristic::Identify(); 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; this->nBlinks=nBlinks; // store the number of times to blink the built-in LED
pinMode(LED_BUILTIN,OUTPUT); pinMode(LED_BUILTIN,OUTPUT); // make sure built-in LED is set for output
} }
StatusCode update(){ StatusCode update(){
if(identify->newValue.BOOL){ for(int i=0;i<nBlinks;i++){
digitalWrite(LED_BUILTIN,LOW);
for(int i=0;i<nBlinks;i++){ delay(250);
digitalWrite(LED_BUILTIN,LOW); digitalWrite(LED_BUILTIN,HIGH);
delay(250); delay(250);
digitalWrite(LED_BUILTIN,HIGH);
delay(250);
}
} }
return(StatusCode::OK); return(StatusCode::OK);

View File

@ -1,58 +0,0 @@
////////////////////////////////////
// DEVICE-SPECIFIC LED SERVICES //
////////////////////////////////////
#include <analogWrite.h>
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
};
//////////////////////////////////

View File

@ -23,37 +23,50 @@ struct DEV_ZephyrLight : Service::LightBulb {
uint32_t code; uint32_t code;
SpanCharacteristic *power; SpanCharacteristic *power;
int buttonPin;
DEV_ZephyrLight(uint32_t code, ServiceType mod=ServiceType::Regular) : Service::LightBulb(mod){ DEV_ZephyrLight(uint32_t code, int buttonPin, ServiceType mod=ServiceType::Regular) : Service::LightBulb(mod){
power=new Characteristic::On(); power=new Characteristic::On();
new SpanTimedReset(500);
new Characteristic::Name("Vent Light"); new Characteristic::Name("Vent Light");
this->code=code; this->code=code;
this->buttonPin=buttonPin;
Serial.print("Configuring Zephyr Vent Hood Light 433MHz Transmitter with code: "); Serial.print("Configuring Zephyr Vent Hood Light 433MHz Transmitter with code: ");
Serial.print(code,HEX); Serial.print(code,HEX);
Serial.print("\n"); Serial.print("\n");
new SpanButton(buttonPin);
} }
StatusCode update(){ StatusCode update(){
LOG1("Updating Zephyr Vent Hood Light: Power=");
LOG1(power->value.BOOL?"true":"false");
if(power->isUpdated){ if(power->getNewVal()){
LOG1(" New Power="); LOG1("Activating Zephyr Vent Hood Light\n");
LOG1(power->newValue.BOOL?"true":"false");
}
LOG1("\n");
if(power->newValue.BOOL)
transmitZephyr(code); transmitZephyr(code);
}
return(StatusCode::OK); return(StatusCode::OK);
} // update } // 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
}; };
////////////////////////////////// //////////////////////////////////
@ -62,37 +75,50 @@ struct DEV_ZephyrFan : Service::Fan {
uint32_t code; uint32_t code;
SpanCharacteristic *power; SpanCharacteristic *power;
int buttonPin;
DEV_ZephyrFan(uint32_t code, ServiceType mod=ServiceType::Regular) : Service::Fan(mod){ DEV_ZephyrFan(uint32_t code, int buttonPin, ServiceType mod=ServiceType::Regular) : Service::Fan(mod){
power=new Characteristic::Active(); power=new Characteristic::Active();
new SpanTimedReset(500);
new Characteristic::Name("Vent Fan"); new Characteristic::Name("Vent Fan");
this->code=code; this->code=code;
this->buttonPin=buttonPin;
Serial.print("Configuring Zephyr Vent Hood Fan 433MHz Transmitter with code: "); Serial.print("Configuring Zephyr Vent Hood Fan 433MHz Transmitter with code: ");
Serial.print(code,HEX); Serial.print(code,HEX);
Serial.print("\n"); Serial.print("\n");
new SpanButton(buttonPin);
} }
StatusCode update(){ StatusCode update(){
LOG1("Updating Zephyr Vent Hood Fan: Power="); if(power->getNewVal()){
LOG1(power->value.BOOL?"true":"false"); // power is actually a UINT8, but only 0 and 1 are defined so BOOL works as well LOG1("Activating Zephyr Vent Hood Fan\n");
transmitZephyr(code);
if(power->isUpdated){
LOG1(" New Power=");
LOG1(power->newValue.BOOL?"true":"false");
} }
LOG1("\n");
if(power->newValue.BOOL)
transmitZephyr(code);
return(StatusCode::OK); return(StatusCode::OK);
} // update } // 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 {
LOG1("Activating Zephyr Vent Hood Fan\n");
transmitZephyr(code);
power->setVal(true);
} // button
}; };
////////////////////////////////// //////////////////////////////////
@ -101,37 +127,50 @@ struct DEV_ZephyrPower : Service::Switch {
uint32_t code; uint32_t code;
SpanCharacteristic *power; SpanCharacteristic *power;
int buttonPin;
DEV_ZephyrPower(uint32_t code, ServiceType mod=ServiceType::Regular) : Service::Switch(mod){ DEV_ZephyrPower(uint32_t code, int buttonPin, ServiceType mod=ServiceType::Regular) : Service::Switch(mod){
power=new Characteristic::On(); power=new Characteristic::On();
new SpanTimedReset(500);
new Characteristic::Name("Vent Power"); new Characteristic::Name("Vent Power");
this->code=code; this->code=code;
this->buttonPin=buttonPin;
Serial.print("Configuring Zephyr Vent Hood Power 433MHz Transmitter with code: "); Serial.print("Configuring Zephyr Vent Hood Power 433MHz Transmitter with code: ");
Serial.print(code,HEX); Serial.print(code,HEX);
Serial.print("\n"); Serial.print("\n");
new SpanButton(buttonPin);
} }
StatusCode update(){ StatusCode update(){
LOG1("Updating Zephyr Vent Hood Power: Power="); if(power->getNewVal()){
LOG1(power->value.BOOL?"true":"false"); LOG1("Activating Zephyr Vent Hood Power\n");
if(power->isUpdated){
LOG1(" New Power=");
LOG1(power->newValue.BOOL?"true":"false");
}
LOG1("\n");
if(power->newValue.BOOL)
transmitZephyr(code); transmitZephyr(code);
}
return(StatusCode::OK); return(StatusCode::OK);
} // update } // 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
}; };
////////////////////////////////// //////////////////////////////////

View File

@ -2,68 +2,30 @@
#include "HomeSpan.h" #include "HomeSpan.h"
#include "DEV_Identify.h" #include "DEV_Identify.h"
#include "DEV_Led.h"
#include "DEV_Zephyr.h" #include "DEV_Zephyr.h"
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
homeSpan.begin(Category::Bridges,"Example HomeSpan Server"); homeSpan.begin(Category::Bridges,"ZephyrVH Bridge");
new SpanAccessory(); new SpanAccessory();
new DEV_Identify(3,"HomeSpan Bridge","ProRF-32","HomeSpan","ESP32-WROOM","1.0"); new DEV_Identify("Zephyr VH Bridge","HomeSpan","ZVH-1","HS Bridge","1.0",3);
new Service::HAPProtocolInformation(); new Service::HAPProtocolInformation();
new Characteristic::Version("1.1.0"); new Characteristic::Version("1.1.0");
new SpanAccessory(); new SpanAccessory();
new DEV_Identify(0,"Test LED1","ON/OFF Only","HomeSpan","LED-12345","1.9"); new DEV_Identify("Zephyr Light","HomeSpan","ZVH-1","RF-Control","1.0",0);
new Service::LightBulb(); new DEV_ZephyrLight(0x51390,17);
new Characteristic::On();
new SpanAccessory(); new SpanAccessory();
new DEV_Identify(0,"Test LED2","ON/OFF Only","HomeSpan","LED-12345","1.9"); new DEV_Identify("Zephyr Fan","HomeSpan","ZVH-1","RF-Control","1.0",0);
new Service::LightBulb(); new DEV_ZephyrFan(0x51388,16);
new Characteristic::On();
new SpanAccessory(); new SpanAccessory();
new DEV_Identify(0,"Test LED3","ON/OFF Only","HomeSpan","LED-12345","1.9"); new DEV_Identify("Zephyr Power","HomeSpan","ZVH-1","RF-Control","1.0",0);
new Service::LightBulb(); new DEV_ZephyrPower(0x61398,19);
new Characteristic::On();
new SpanTimedReset(5000);
new SpanAccessory();
new DEV_Identify(0,"Test FAN","Dimmable","HomeSpan","FAN-12345","2.9");
new Service::Fan();
new Characteristic::Active();
new DEV_DimmableLED(15);
new SpanAccessory();
new DEV_Identify(0,"Dimmable LED 1","Dimmable","HomeSpan","LED-7890","4.9");
new DEV_DimmableLED(16);
new SpanAccessory();
new DEV_Identify(0,"Dimmable LED 2","Dimmable","HomeSpan","LED-7890","4.9");
new DEV_DimmableLED(17);
new SpanAccessory();
new DEV_Identify(0,"Simple FAN","On/Off Light","HomeSpan","FAN-LAMP","2.9");
new Service::Fan();
new Characteristic::Active();
new DEV_DimmableLED(14,ServiceType::Primary);
new SpanAccessory();
new DEV_Identify(0,"Zephyr Vent Hood","433 MHz","HomeSpan","ZephyrVH","1.0");
new DEV_ZephyrLight(0x51390);
new DEV_ZephyrFan(0x51388);
new DEV_ZephyrPower(0x61398,ServiceType::Primary);
new SpanAccessory();
new DEV_Identify(0,"Zephyr Vent Hood 2","433 MHz","HomeSpan","ZephyrVH","1.0");
new DEV_ZephyrLight(0x51390,ServiceType::Primary);
new DEV_ZephyrFan(0x51388);
new DEV_ZephyrPower(0x61398);
} }