Update src.ino

This commit is contained in:
Gregg 2023-04-08 17:17:47 -05:00
parent 97a69b4981
commit 5853989651
1 changed files with 47 additions and 26 deletions

View File

@ -25,47 +25,68 @@
* *
********************************************************************************/ ********************************************************************************/
// This is a placeholder .ino file that allows you to easily edit the contents of this library using the Arduino IDE,
// as well as compile and test from this point. This file is ignored when the library is included in other sketches.
#include "HomeSpan.h" #include "HomeSpan.h"
CUSTOM_CHAR(CharFloat, 00000001-0001-0001-0001-46637266EA00, PR+PW+EV, FLOAT, 0, 0, 100, false); struct LED_Service : Service::LightBulb {
CUSTOM_CHAR(CharUInt8, 00000009-0001-0001-0001-46637266EA00, PR+PW+EV, UINT8, 0, 0, 100, false);
CUSTOM_CHAR(CharUInt16, 00000016-0001-0001-0001-46637266EA00, PR+PW+EV, UINT16, 0, 0, 100, false);
CUSTOM_CHAR(CharUInt32, 00000032-0001-0001-0001-46637266EA00, PR+PW+EV, UINT32, 0, 0, 100, false);
CUSTOM_CHAR(CharInt, 00000002-0001-0001-0001-46637266EA00, PR+PW+EV, INT, 0, 0, 100, false);
////////////////////////////////////// int ledPin;
boolean oldPower=false;
SpanCharacteristic *power;
LED_Service(int ledPin) : Service::LightBulb(){
power=new Characteristic::On();
this->ledPin=ledPin;
pinMode(ledPin,OUTPUT);
}
boolean update(){
digitalWrite(ledPin,power->getNewVal());
oldPower=power->getNewVal();
return(true);
}
// void loop(){
// if(power->getVal()!=oldPower){
// oldPower=!oldPower;
// Serial.printf("Power was manually changed to %s\n",oldPower?"ON":"OFF");
// }
// }
};
//////////////////////////////////////
boolean oldPower=false;
LED_Service *pLed;
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
homeSpan.setLogLevel(1); homeSpan.setLogLevel(2);
homeSpan.begin(Category::Other,"HomeSpan Test"); homeSpan.begin(Category::Lighting,"HomeSpan LED");
new SpanAccessory();
new Service::AccessoryInformation();
new Characteristic::Identify();
new Service::LightBulb();
new Characteristic::On();
(new Characteristic::CharFloat())->setValidValues(5,0,1,2,6,7,8);
(new Characteristic::CharUInt8())->setValidValues(5,0,1,2,6,7,8);
(new Characteristic::CharUInt16())->setValidValues(5,0,1<<8,1<<16,0xFFFFFFFF,-1);
(new Characteristic::CharUInt32())->setValidValues(5,0,1<<8,1<<16,0xFFFFFFFF,-1);
(new Characteristic::CharInt())->setValidValues(5,0,255,2000000000,-2000000000,-1)->setValidValues(1,2);
} // end of setup() new SpanAccessory();
new Service::AccessoryInformation();
new Characteristic::Identify();
pLed=new LED_Service(13);
homeSpan.autoPoll(8192,10,1);
}
////////////////////////////////////// //////////////////////////////////////
void loop(){ void loop(){
homeSpan.poll(); // homeSpan.poll();
} // end of loop() while(pLed->power->getVal()!=oldPower){
oldPower=pLed->power->getVal();
Serial.printf("Power was manually changed to %s\n",oldPower?"ON":"OFF");
}
}
////////////////////////////////////// //////////////////////////////////////