Reworking checkEvents()
creating code to allow for multiple characteristics to be updated within event() call. To Do: define anogther sensor that supports multiple characteristics. also need to check that "new SpanEvent" works as expected from within a defined service.
This commit is contained in:
parent
3a4be161e7
commit
8d6db796cb
|
|
@ -47,7 +47,7 @@ void setup() {
|
||||||
new SpanAccessory();
|
new SpanAccessory();
|
||||||
new DEV_Identify("Temp Sensor","HomeSpan","123-ABC","Celsius","0.9",0);
|
new DEV_Identify("Temp Sensor","HomeSpan","123-ABC","Celsius","0.9",0);
|
||||||
new DEV_TempSensor(); // Create a Temperature Sensor
|
new DEV_TempSensor(); // Create a Temperature Sensor
|
||||||
new SpanEvent(60000);
|
new SpanEvent(5000);
|
||||||
|
|
||||||
} // end of setup()
|
} // end of setup()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,27 +6,19 @@
|
||||||
struct DEV_TempSensor : Service::TemperatureSensor { // A standalone temperature sensor
|
struct DEV_TempSensor : Service::TemperatureSensor { // A standalone temperature sensor
|
||||||
|
|
||||||
SpanCharacteristic *temp; // reference to the Current Temperature Characteristic
|
SpanCharacteristic *temp; // reference to the Current Temperature Characteristic
|
||||||
float step=0.5;
|
|
||||||
|
|
||||||
DEV_TempSensor(ServiceType sType=ServiceType::Regular) : Service::TemperatureSensor(sType){ // constructor() method
|
DEV_TempSensor(ServiceType sType=ServiceType::Regular) : Service::TemperatureSensor(sType){ // constructor() method
|
||||||
|
|
||||||
temp=new Characteristic::CurrentTemperature();
|
temp=new Characteristic::CurrentTemperature();
|
||||||
temp->value.FLOAT=22.0;
|
|
||||||
|
|
||||||
Serial.print("Configuring Temperature Sensor"); // initialization message
|
Serial.print("Configuring Temperature Sensor"); // initialization message
|
||||||
Serial.print("\n");
|
Serial.print("\n");
|
||||||
|
|
||||||
} // end constructor
|
} // end constructor
|
||||||
|
|
||||||
SpanCharacteristic *event(){
|
void event(){
|
||||||
|
|
||||||
temp->value.FLOAT+=step;
|
temp->setVal(22.0);
|
||||||
if(temp->value.FLOAT>28.0)
|
|
||||||
step=-step;
|
|
||||||
else if(temp->value.FLOAT<18.0)
|
|
||||||
step=-step;
|
|
||||||
|
|
||||||
return(temp);
|
|
||||||
|
|
||||||
} // event
|
} // event
|
||||||
};
|
};
|
||||||
|
|
|
||||||
23
src/HAP.cpp
23
src/HAP.cpp
|
|
@ -1098,8 +1098,27 @@ void HAPClient::checkEvents(){
|
||||||
|
|
||||||
for(int i=0;i<homeSpan.Events.size();i++){ // loop over all defined Events
|
for(int i=0;i<homeSpan.Events.size();i++){ // loop over all defined Events
|
||||||
if(cTime>homeSpan.Events[i]->alarmTime){ // if alarm time has passed
|
if(cTime>homeSpan.Events[i]->alarmTime){ // if alarm time has passed
|
||||||
|
|
||||||
homeSpan.Events[i]->alarmTime=cTime+homeSpan.Events[i]->period; // set new alarm time to current time plus alarm period
|
homeSpan.Events[i]->alarmTime=cTime+homeSpan.Events[i]->period; // set new alarm time to current time plus alarm period
|
||||||
SpanCharacteristic *characteristic=homeSpan.Events[i]->service->event(); // check service for new EVENT
|
homeSpan.Events[i]->service->event(); // check service for new EVENTS
|
||||||
|
|
||||||
|
for(int j=0;j<homeSpan.Events[i]->service->Characteristics.size();j++){ // loop over all characteristics
|
||||||
|
if(homeSpan.Events[i]->service->Characteristics[j]->isUpdated){ // if characteristic is updated
|
||||||
|
|
||||||
|
Serial.print("Event for aid=");
|
||||||
|
Serial.print(homeSpan.Events[i]->service->Characteristics[j]->aid);
|
||||||
|
Serial.print(" iid=");
|
||||||
|
Serial.print(homeSpan.Events[i]->service->Characteristics[j]->iid);
|
||||||
|
Serial.print("\n");
|
||||||
|
|
||||||
|
homeSpan.Events[i]->service->Characteristics[j]->isUpdated=false; // reset isUpdated flag
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
if(characteristic){ // if the service has responded with a characteristic to update
|
if(characteristic){ // if the service has responded with a characteristic to update
|
||||||
pObj[nObj].status=StatusCode::OK; // populate pObj
|
pObj[nObj].status=StatusCode::OK; // populate pObj
|
||||||
pObj[nObj].characteristic=characteristic;
|
pObj[nObj].characteristic=characteristic;
|
||||||
|
|
@ -1114,6 +1133,8 @@ void HAPClient::checkEvents(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
|
|
||||||
void HAPClient::checkTimedResets(){
|
void HAPClient::checkTimedResets(){
|
||||||
|
|
|
||||||
|
|
@ -1054,6 +1054,49 @@ StatusCode SpanCharacteristic::loadUpdate(char *val, char *ev){
|
||||||
return(StatusCode::TBD);
|
return(StatusCode::TBD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////////////////
|
||||||
|
|
||||||
|
void SpanCharacteristic::setVal(int val){
|
||||||
|
|
||||||
|
switch(format){
|
||||||
|
|
||||||
|
case BOOL:
|
||||||
|
value.BOOL=(boolean)val;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case INT:
|
||||||
|
value.INT=(int)val;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case UINT8:
|
||||||
|
value.UINT8=(uint8_t)val;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case UINT16:
|
||||||
|
value.UINT16=(uint16_t)val;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case UINT32:
|
||||||
|
value.UINT32=(uint32_t)val;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case UINT64:
|
||||||
|
value.UINT64=(uint64_t)val;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
isUpdated=true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////
|
||||||
|
|
||||||
|
void SpanCharacteristic::setVal(double val){
|
||||||
|
|
||||||
|
value.FLOAT=(double)val;
|
||||||
|
isUpdated=true;
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
// SpanTimedReset //
|
// SpanTimedReset //
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,7 @@ struct SpanService{
|
||||||
|
|
||||||
int sprintfAttributes(char *cBuf); // prints Service JSON records into buf; return number of characters printed, excluding null terminator
|
int sprintfAttributes(char *cBuf); // prints Service JSON records into buf; return number of characters printed, excluding null terminator
|
||||||
virtual StatusCode update() {return(StatusCode::OK);} // update Service and return final statusCode based on updated Characteristics - should be overridden by DEVICE-SPECIFIC Services
|
virtual StatusCode update() {return(StatusCode::OK);} // update Service and return final statusCode based on updated Characteristics - should be overridden by DEVICE-SPECIFIC Services
|
||||||
virtual SpanCharacteristic* event(){return(NULL);} // event generation for Services that create their own events and need to notify HomeKit of a new Characteristic value
|
virtual void event(){} // event generation for Services that create their own events and need to notify HomeKit of a new Characteristic value(s)
|
||||||
};
|
};
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
|
|
@ -151,7 +151,7 @@ struct SpanCharacteristic{
|
||||||
boolean ev[MAX_CONNECTIONS]={false}; // Characteristic Event Notify Enable (per-connection)
|
boolean ev[MAX_CONNECTIONS]={false}; // Characteristic Event Notify Enable (per-connection)
|
||||||
|
|
||||||
int aid=0; // Accessory ID - passed through from Service containing this Characteristic
|
int aid=0; // Accessory ID - passed through from Service containing this Characteristic
|
||||||
boolean isUpdated=false; // set to true when new value has been requested by PUT /characteristic
|
boolean isUpdated=false; // set to true when new value has been requested by PUT /characteristic, or when value is updated with setVal()
|
||||||
UVal newValue; // the updated value requested by PUT /characteristic
|
UVal newValue; // the updated value requested by PUT /characteristic
|
||||||
SpanService *service=NULL; // pointer to Service containing this Characteristic
|
SpanService *service=NULL; // pointer to Service containing this Characteristic
|
||||||
|
|
||||||
|
|
@ -172,6 +172,9 @@ struct SpanCharacteristic{
|
||||||
template <class T=int> T getNewVal(){return(getValue<T>(newValue));} // returns UVal newValue
|
template <class T=int> T getNewVal(){return(getValue<T>(newValue));} // returns UVal newValue
|
||||||
template <class T> T getValue(UVal v); // returns UVal v
|
template <class T> T getValue(UVal v); // returns UVal v
|
||||||
|
|
||||||
|
void setVal(int value); // sets value of UVal value for all integer-based Characterstic types
|
||||||
|
void setVal(double value); // sets value of UVal value for FLOAT Characteristic type
|
||||||
|
|
||||||
boolean updated(){return(isUpdated);} // returns isUpdated
|
boolean updated(){return(isUpdated);} // returns isUpdated
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue