Created Zephyr Vent Hood Example
This commit is contained in:
parent
b42dd9dfba
commit
9f7e9a51e5
|
|
@ -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<nBlinks;i++){
|
||||
digitalWrite(LED_BUILTIN,LOW);
|
||||
delay(250);
|
||||
digitalWrite(LED_BUILTIN,HIGH);
|
||||
delay(250);
|
||||
}
|
||||
}
|
||||
|
||||
return(StatusCode::OK);
|
||||
|
||||
} // update
|
||||
|
||||
};
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
|
||||
////////////////////////////////////
|
||||
// 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
|
||||
};
|
||||
|
||||
//////////////////////////////////
|
||||
|
|
@ -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<<b))
|
||||
RF433.add(620,230);
|
||||
else
|
||||
RF433.add(230,620);
|
||||
}
|
||||
|
||||
if(code&1)
|
||||
RF433.add(620,4230);
|
||||
else
|
||||
RF433.add(230,4620);
|
||||
|
||||
RF433.start(8,1);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
|
||||
#include "HomeSpan.h"
|
||||
|
||||
#include "DEV_Identify.h"
|
||||
#include "DEV_Led.h"
|
||||
#include "DEV_Zephyr.h"
|
||||
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(115200);
|
||||
|
||||
homeSpan.begin(Category::Bridges,"Example HomeSpan Server");
|
||||
|
||||
new SpanAccessory();
|
||||
new DEV_Identify(3,"HomeSpan Bridge","ProRF-32","HomeSpan","ESP32-WROOM","1.0");
|
||||
new Service::HAPProtocolInformation();
|
||||
new Characteristic::Version("1.1.0");
|
||||
|
||||
new SpanAccessory();
|
||||
new DEV_Identify(0,"Test LED1","ON/OFF Only","HomeSpan","LED-12345","1.9");
|
||||
new Service::LightBulb();
|
||||
new Characteristic::On();
|
||||
|
||||
new SpanAccessory();
|
||||
new DEV_Identify(0,"Test LED2","ON/OFF Only","HomeSpan","LED-12345","1.9");
|
||||
new Service::LightBulb();
|
||||
new Characteristic::On();
|
||||
|
||||
new SpanAccessory();
|
||||
new DEV_Identify(0,"Test LED3","ON/OFF Only","HomeSpan","LED-12345","1.9");
|
||||
new Service::LightBulb();
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
void loop(){
|
||||
homeSpan.poll();
|
||||
}
|
||||
Loading…
Reference in New Issue