Updated Examples 14-17

This commit is contained in:
Gregg 2022-04-10 16:04:36 -05:00
parent 02184fe005
commit f322f2b0f1
6 changed files with 29 additions and 109 deletions

View File

@ -1,7 +1,7 @@
/********************************************************************************* /*********************************************************************************
* MIT License * MIT License
* *
* Copyright (c) 2020 Gregg E. Berman * Copyright (c) 2020-2022 Gregg E. Berman
* *
* https://github.com/HomeSpan/HomeSpan * https://github.com/HomeSpan/HomeSpan
* *
@ -90,7 +90,7 @@ void setup() {
new Service::AccessoryInformation(); new Service::AccessoryInformation();
new Characteristic::Identify(); new Characteristic::Identify();
new Characteristic::Name("LED Blinker"); new Characteristic::Name("LED Blinker");
new DEV_Blinker(13,3); // DEV_Blinker takes two arguments - pin, and number of times to blink new DEV_Blinker(16,3); // DEV_Blinker takes two arguments - pin, and number of times to blink
} // end of setup() } // end of setup()

View File

@ -1,7 +1,7 @@
/********************************************************************************* /*********************************************************************************
* MIT License * MIT License
* *
* Copyright (c) 2020 Gregg E. Berman * Copyright (c) 2020-2022 Gregg E. Berman
* *
* https://github.com/HomeSpan/HomeSpan * https://github.com/HomeSpan/HomeSpan
* *
@ -38,7 +38,6 @@
#include "HomeSpan.h" #include "HomeSpan.h"
#include "DEV_LED.h" #include "DEV_LED.h"
#include "DEV_Identify.h"
void setup() { void setup() {
@ -132,12 +131,13 @@ void setup() {
homeSpan.begin(Category::Bridges,"HomeSpan Bridge"); homeSpan.begin(Category::Bridges,"HomeSpan Bridge");
new SpanAccessory(); new SpanAccessory();
new DEV_Identify("Bridge #1","HomeSpan","123-ABC","HS Bridge","0.9",3); new Service::AccessoryInformation();
new Service::HAPProtocolInformation(); new Characteristic::Identify();
new Characteristic::Version("1.1.0");
new SpanAccessory(); new SpanAccessory();
new DEV_Identify("PushButton LED","HomeSpan","123-ABC","20mA LED","0.9",0); new Service::AccessoryInformation();
new Characteristic::Identify();
new Characteristic::Name("PushButton LED");
new DEV_DimmableLED(17,23,5,18); // NEW! added three extra arguments to specify the pin numbers for three SpanButtons() - see DEV_LED.h new DEV_DimmableLED(17,23,5,18); // NEW! added three extra arguments to specify the pin numbers for three SpanButtons() - see DEV_LED.h

View File

@ -1,38 +0,0 @@
//////////////////////////////////
// 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(const char *name, const char *manu, const char *sn, const char *model, const char *version, int nBlinks) : Service::AccessoryInformation(){
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 LED
pinMode(homeSpan.getStatusPin(),OUTPUT); // make sure LED is set for output
}
boolean update(){
for(int i=0;i<nBlinks;i++){
digitalWrite(homeSpan.getStatusPin(),LOW);
delay(250);
digitalWrite(homeSpan.getStatusPin(),HIGH);
delay(250);
}
return(true); // return true
} // update
};

View File

@ -1,7 +1,7 @@
/********************************************************************************* /*********************************************************************************
* MIT License * MIT License
* *
* Copyright (c) 2020 Gregg E. Berman * Copyright (c) 2020-2022 Gregg E. Berman
* *
* https://github.com/HomeSpan/HomeSpan * https://github.com/HomeSpan/HomeSpan
* *
@ -36,7 +36,6 @@
#include "HomeSpan.h" #include "HomeSpan.h"
#include "DEV_ProgButton.h" #include "DEV_ProgButton.h"
#include "DEV_Identify.h"
void setup() { void setup() {
@ -66,12 +65,13 @@ void setup() {
homeSpan.begin(Category::Bridges,"HomeSpan Bridge"); homeSpan.begin(Category::Bridges,"HomeSpan Bridge");
new SpanAccessory(); new SpanAccessory();
new DEV_Identify("Bridge #1","HomeSpan","123-ABC","HS Bridge","0.9",3); new Service::AccessoryInformation();
new Service::HAPProtocolInformation(); new Characteristic::Identify();
new Characteristic::Version("1.1.0");
new SpanAccessory(); new SpanAccessory();
new DEV_Identify("PushButton Switches","HomeSpan","123-ABC","Prog Switches","0.9",0); new Service::AccessoryInformation();
new Characteristic::Identify();
new Characteristic::Name("PushButton Switches");
// We've written DEV_ProgButton to take two arguments. The first is a pin number that DEV_ProgButton.h uses to create a SpanButton. The second is an index number // We've written DEV_ProgButton to take two arguments. The first is a pin number that DEV_ProgButton.h uses to create a SpanButton. The second is an index number
// that HomeKit uses as a label when you program the actions of each button in the Home App. The numbers do not have to be sequential, nor start with 1. They just need // that HomeKit uses as a label when you program the actions of each button in the Home App. The numbers do not have to be sequential, nor start with 1. They just need

View File

@ -1,38 +0,0 @@
//////////////////////////////////
// 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(const char *name, const char *manu, const char *sn, const char *model, const char *version, int nBlinks) : Service::AccessoryInformation(){
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 LED
pinMode(homeSpan.getStatusPin(),OUTPUT); // make sure LED is set for output
}
boolean update(){
for(int i=0;i<nBlinks;i++){
digitalWrite(homeSpan.getStatusPin(),LOW);
delay(250);
digitalWrite(homeSpan.getStatusPin(),HIGH);
delay(250);
}
return(true); // return true
} // update
};

View File

@ -1,7 +1,7 @@
/********************************************************************************* /*********************************************************************************
* MIT License * MIT License
* *
* Copyright (c) 2020-2021 Gregg E. Berman * Copyright (c) 2020-2022 Gregg E. Berman
* *
* https://github.com/HomeSpan/HomeSpan * https://github.com/HomeSpan/HomeSpan
* *
@ -102,23 +102,25 @@
// Note that the Shower Service only monitors the InUse Characteristics of its Linked Valves. It does not monitor the Active Characteristics of the Linked Valves. Also, turning // Note that the Shower Service only monitors the InUse Characteristics of its Linked Valves. It does not monitor the Active Characteristics of the Linked Valves. Also, turning
// on and off the Shower Switch should NOT change the Active Characteristic of any Valve. Below is the code that implements all of this HAP-required logic: // on and off the Shower Switch should NOT change the Active Characteristic of any Valve. Below is the code that implements all of this HAP-required logic:
struct Shower:Service::Faucet{ // this is our Shower structure, which we define as a child class of the HomeSpan Faucet structure struct Shower : Service::Faucet { // this is our Shower structure, which we define as a child class of the HomeSpan Faucet structure
SpanCharacteristic *active=new Characteristic::Active(); // our implementation only requires the Active Characteristic SpanCharacteristic *active=new Characteristic::Active(); // our implementation only requires the Active Characteristic
Shower(int nHeads){ // this is the constructor for Shower. It takes a single argument that specifies the number of spray heads (WaterValves) Shower(int nHeads){ // this is the constructor for Shower. It takes a single argument that specifies the number of spray heads (WaterValves)
for(int i=0;i<nHeads;i++) // for each spray head needed --- for(int i=0;i<nHeads;i++) // for each spray head needed ---
addLink(new WaterValve(this)); // --- instantiate a new WaterValve AND link it to the Shower. Also, pass the Shower object's pointer to WaterValve constructor. We'll see why below. addLink(new WaterValve(this,i+1)); // --- instantiate a new WaterValve AND link it to the Shower. Also, pass the Shower object's pointer to WaterValve constructor. We'll see why below.
} }
struct WaterValve:Service::Valve{ // here we define our WaterValve structure as a child class of the HomeSpan Valve Service struct WaterValve : Service::Valve { // here we define our WaterValve structure as a child class of the HomeSpan Valve Service
SpanCharacteristic *active=new Characteristic::Active();; // the Active Characteristic is used to specify whether the Valve is Active (open) or Inactive (closed) SpanCharacteristic *active=new Characteristic::Active(1);; // the Active Characteristic is used to specify whether the Valve is Active (open) or Inactive (closed)
SpanCharacteristic *inUse=new Characteristic::InUse(); // the InUser Characteristic is used to specify whether water is actually flowing through value SpanCharacteristic *inUse=new Characteristic::InUse(); // the InUser Characteristic is used to specify whether water is actually flowing through value
Shower *shower; // storage for the pointer to the "controlling" Shower Service Shower *shower; // storage for the pointer to the "controlling" Shower Service
WaterValve(Shower *s){ // this is constructor for WaterValve. It takes a single argument that points to the "controlling" Shower Service WaterValve(Shower *s, int i){ // this is constructor for WaterValve. It takes a single argument that points to the "controlling" Shower Service
shower=s; // store the pointer to the Shower Service shower=s; // store the pointer to the Shower Service
new Characteristic::ValveType(2); // specify the Value Type (2=Shower Head; see HAP R2 for other choices) new Characteristic::ValveType(2); // specify the Value Type (2=Shower Head; see HAP R2 for other choices)
new Characteristic::ServiceLabelIndex(i);
new Characteristic::IsConfigured(1); // Source included in the Settings Screen...
} }
boolean update() override { // HomeSpan calls this whenever the Home App requests a change in a Valve's Active Characteristic boolean update() override { // HomeSpan calls this whenever the Home App requests a change in a Valve's Active Characteristic
@ -145,21 +147,15 @@ void setup() {
homeSpan.begin(Category::ShowerSystems,"HomeSpan Shower"); homeSpan.begin(Category::ShowerSystems,"HomeSpan Shower");
new SpanAccessory(); new SpanAccessory();
new Service::AccessoryInformation();
new Service::AccessoryInformation(); // HAP requires every Accessory to implement an AccessoryInformation Service, which has 6 required Characteristics new Characteristic::Identify();
new Characteristic::Name("Spa Shower");
new Characteristic::Manufacturer("HomeSpan");
new Characteristic::SerialNumber("HSL-123");
new Characteristic::Model("HSL Test");
new Characteristic::FirmwareRevision(HOMESPAN_VERSION);
new Characteristic::Identify();
new Service::HAPProtocolInformation(); // Create the HAP Protcol Information Service
new Characteristic::Version("1.1.0");
new Shower(4); // Create a Spa Shower with 4 spray heads new Shower(4); // Create a Spa Shower with 4 spray heads
new Service::ServiceLabel();
new Characteristic::ServiceLabelNamespace(1);
} // end of setup() } // end of setup()
////////////////////////////////////// //////////////////////////////////////