Created
December 3, 2014 15:58
-
-
Save gb160/9d16f13b56e7d27c76cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This accessory.cpp is configurated for light accessory + fan accessory | |
*/ | |
#include "Accessory.h" | |
#include "PHKAccessory.h" | |
//Global Level of light strength | |
int lightStength = 0; | |
int fanSpeedVal = 0; | |
void lightIdentify(bool oldValue, bool newValue) { | |
printf("Start Identify Light\n"); | |
} | |
void fanIdentify(bool oldValue, bool newValue) { | |
printf("Start Identify Fan\n"); | |
} | |
void changeLightIntensity(int oldValue, int newValue) { | |
printf("New Intensity\n"); | |
} | |
void changeLightPowerState(bool oldValue, bool newValue) { | |
if (newValue == true) | |
{ | |
printf("Switching on Lamps...\n"); | |
system("curl -s \"http://gb160:password@127.0.0.1:8080/json.htm?type=command¶m=switchlight&idx=8&switchcmd=On&level=0\" &"); | |
} else { | |
printf("Switching off Lamps..a.\n"); | |
system("curl -s \"http://gb160:password@127.0.0.1:8080/json.htm?type=command¶m=switchlight&idx=8&switchcmd=Off&level=0\" &"); | |
} | |
} | |
void changelight2PowerState(bool oldValue, bool newValue) { | |
if (newValue == true) | |
{ | |
printf("Switching on Main Light...\n"); | |
system("curl -s \"http://gb160:password@127.0.0.1:8080/json.htm?type=command¶m=switchlight&idx=7&switchcmd=On&level=0\" &"); | |
} else { | |
printf("Switching off Main Light...\n"); | |
system("curl -s \"http://gb160:password@127.0.0.1:8080/json.htm?type=command¶m=switchlight&idx=7&switchcmd=Off&level=0\""); | |
} | |
} | |
void changelight3PowerState(bool oldValue, bool newValue) { | |
if (newValue == true) | |
{ | |
printf("Switching on Bedroom Light...\n"); | |
system("curl -s \"http://gb160:password@127.0.0.1:8080/json.htm?type=command¶m=switchlight&idx=9&switchcmd=On&level=0\" &"); | |
} else { | |
printf("Switching off Bedroom Light...\n"); | |
system("curl -s \"http://gb160:password@127.0.0.1:8080/json.htm?type=command¶m=switchlight&idx=9&switchcmd=Off&level=0\""); | |
} | |
} | |
void changelight4PowerState(bool oldValue, bool newValue) { | |
if (newValue == true) | |
{ | |
printf("Switching on Xmas Light ...\n"); | |
system("curl -s \"http://gb160:password@127.0.0.1:8080/json.htm?type=command¶m=switchlight&idx=35&switchcmd=On&level=0\" &"); | |
} else { | |
printf("Switching off Xmas Light...\n"); | |
system("curl -s \"http://gb160:password@127.0.0.1:8080/json.htm?type=command¶m=switchlight&idx=35&switchcmd=Off&level=0\""); | |
} | |
} | |
void changefanPowerState(bool oldValue, bool newValue) { | |
if (newValue == true) | |
{ | |
printf("Switching on Fan...\n"); | |
} else { | |
printf("Switching off Fan...\n"); | |
} | |
} | |
void changeoutletPowerState(bool oldValue, bool newValue) { | |
if (newValue == true) | |
{ | |
printf("Switching on Fan...\n"); | |
} else { | |
printf("Switching off Fan...\n"); | |
} | |
} | |
AccessorySet *accSet; | |
void initAccessorySet() { | |
printf("Initial Accessory\n"); | |
Accessory *lightAcc = new Accessory(); | |
//Add Light | |
accSet = new AccessorySet(); | |
addInfoServiceToAccessory(lightAcc, "Light 1", "ET", "Light", "12345678", &lightIdentify); | |
accSet->addAccessory(lightAcc); | |
Service *lightService = new Service(charType_lightBulb); | |
lightAcc->addService(lightService); | |
stringCharacteristics *lightServiceName = new stringCharacteristics(charType_serviceName, premission_read, 0); | |
lightServiceName->setValue("Light"); | |
lightAcc->addCharacteristics(lightService, lightServiceName); | |
boolCharacteristics *powerState = new boolCharacteristics(charType_on, premission_read|premission_write); | |
powerState->setValue("true"); | |
powerState->valueChangeFunctionCall = &changeLightPowerState; | |
lightAcc->addCharacteristics(lightService, powerState); | |
intCharacteristics *brightnessState = new intCharacteristics(charType_brightness, premission_read|premission_write, 0, 100, 1, unit_percentage); | |
brightnessState->setValue("50"); | |
brightnessState->valueChangeFunctionCall = &changeLightIntensity; | |
lightAcc->addCharacteristics(lightService, brightnessState); | |
//Add light2 | |
Accessory *light2 = new Accessory(); | |
addInfoServiceToAccessory(light2, "Light 2", "ET", "light2", "12345678", &lightIdentify); | |
accSet->addAccessory(light2); | |
Service *light2Service = new Service(charType_lightBulb); | |
light2->addService(light2Service); | |
stringCharacteristics *light2ServiceName = new stringCharacteristics(charType_serviceName, premission_read, 0); | |
light2ServiceName->setValue("light2"); | |
light2->addCharacteristics(light2Service, lightServiceName); | |
boolCharacteristics *light2Power = new boolCharacteristics(charType_on, premission_read|premission_write); | |
light2Power->setValue("true"); | |
light2Power->valueChangeFunctionCall = &changelight2PowerState; | |
light2->addCharacteristics(light2Service, light2Power); | |
//Add light3 | |
Accessory *light3 = new Accessory(); | |
addInfoServiceToAccessory(light3, "Light 3", "ET", "light3", "12345678", &lightIdentify); | |
accSet->addAccessory(light3); | |
Service *light3Service = new Service(charType_lightBulb); | |
light3->addService(light3Service); | |
stringCharacteristics *light3ServiceName = new stringCharacteristics(charType_serviceName, premission_read, 0); | |
light3ServiceName->setValue("light3"); | |
light3->addCharacteristics(light3Service, lightServiceName); | |
boolCharacteristics *light3Power = new boolCharacteristics(charType_on, premission_read|premission_write); | |
light3Power->setValue("true"); | |
light3Power->valueChangeFunctionCall = &changelight3PowerState; | |
light3->addCharacteristics(light3Service, light3Power); | |
//Add light4 | |
Accessory *light4 = new Accessory(); | |
addInfoServiceToAccessory(light4, "Light 4", "ET", "light4", "12345678", &lightIdentify); | |
accSet->addAccessory(light4); | |
Service *light4Service = new Service(charType_lightBulb); | |
light4->addService(light4Service); | |
stringCharacteristics *light4ServiceName = new stringCharacteristics(charType_serviceName, premission_read, 0); | |
light4ServiceName->setValue("light4"); | |
light4->addCharacteristics(light4Service, lightServiceName); | |
boolCharacteristics *light4Power = new boolCharacteristics(charType_on, premission_read|premission_write); | |
light4Power->setValue("true"); | |
light4Power->valueChangeFunctionCall = &changelight4PowerState; | |
light4->addCharacteristics(light4Service, light4Power); | |
//Add fan | |
Accessory *fan = new Accessory(); | |
addInfoServiceToAccessory(fan, "Fan 1", "ET", "Fan", "12345678", &lightIdentify); | |
accSet->addAccessory(fan); | |
Service *fanService = new Service(charType_fan); | |
fan->addService(fanService); | |
stringCharacteristics *fanServiceName = new stringCharacteristics(charType_serviceName, premission_read, 0); | |
fanServiceName->setValue("Fan"); | |
fan->addCharacteristics(fanService, lightServiceName); | |
boolCharacteristics *fanPower = new boolCharacteristics(charType_on, premission_read|premission_write); | |
fanPower->setValue("true"); | |
fanPower->valueChangeFunctionCall = &changefanPowerState; | |
fan->addCharacteristics(fanService, fanPower); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment