forked from etwmc/Personal-HomeKit-HAP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Accessory.cpp
52 lines (39 loc) · 1.74 KB
/
Accessory.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* This accessory.cpp is configurated for light 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 changeLightPower(bool oldValue, bool newValue) {
printf("New Light Power State\n");
}
void changeLightIntensity(int oldValue, int newValue) {
printf("New Intensity\n");
}
AccessorySet *accSet;
void initAccessorySet() {
currentDeviceType = deviceType_lightBulb;
printf("Initial Accessory\n");
accSet = &AccessorySet::getInstance();
Accessory *lightAcc = new Accessory();
addInfoServiceToAccessory(lightAcc, "Light 1", "ET", "Light", "12345678", &lightIdentify);
accSet->addAccessory(lightAcc);
Service *lightService = new Service(serviceType_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|premission_notify);
powerState->setValue("true");
powerState->valueChangeFunctionCall = &changeLightPower;
lightAcc->addCharacteristics(lightService, powerState);
intCharacteristics *brightnessState = new intCharacteristics(charType_brightness, premission_read|premission_write|premission_notify, 0, 100, 1, unit_percentage);
brightnessState->setValue("50");
brightnessState->valueChangeFunctionCall = &changeLightIntensity;
lightAcc->addCharacteristics(lightService, brightnessState);
};