-
Notifications
You must be signed in to change notification settings - Fork 233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getter setter with variable #410
Comments
What you need to do is:
homekit_value_t light_on_get(homekit_charactersitic_t *ch) {
uint8_t gpio = *((uint8_t*) ch->conext);
return HOMEKIT_BOOL(gpio_read(gpio));
}
void light_on_set(homekit_characteristic_t *ch, homekit_value_t value) {
uint8_t gpio = *((uint8_t*) ch->conext);
gpio_write(gpio, value.bool_value);
}
HOMEKIT_SERVICE(LIGHTBULB, .primary=true, .characteristics=(homekit_characteristic_t*[]){
HOMEKIT_CHARACTERISTIC(NAME, "Relay 7"),
HOMEKIT_CHARACTERISTIC(
ON, false,
.getter_ex=light_on_get,
.setter_ex=light_on_set,
.context=(void*)&relay_gpios[6],
),
NULL
}), |
I will try that, right now I added 8 times led_on_set0, led_on_set1... Right now I have the „.primary=true“ on all 8 relays/lightbulbs, is that ok or whats the function of „.primary=true“? Just one additional question, when should I make a new task and when it is ok to have it direct in the „homekit“ function calls? |
No, this is not OK. Accessory should have only one primary service.
Well, the rule of thumb is to have all getters/setters/callbacks being fast: no waiting, sleeping, expensive computations. |
And whats the difference between primary and non primary? |
I think primary attribute determines which accessory tile will be displayed in Home app. E.g. if you have a thermostat and an outlet services together in one accessory, whichever is marked primary will be displayed on accessory tile in Home app. |
Thanks for support and the great git! |
Tried it out and get a warning which I dont understand, any ideas whats the problem? Thanks
Code:
|
I guess you're using wrong function signature for getters and setters. |
Hi
first of all thanks for that git and the option to programm an esp with homekit support
and I appriciate any help as I am stuck here right now.
I try to have multiple relays controller by PCF8574 via I2C from ESP-01
I got quite far and everything is working with the led getter and led setter example for one relay.
Now I want to have that for multiple relays which would need to have a variable passed to the getter and setter function.
=> Copying the setter and getter code multiple times seems with different function names is not really "professional"
and very frustation if I need to update something ;-)
How do I have to modify the code that it can pass an variable to getter and setter?
Initial Setter/Getter Example Code:
I tried to merge the dynamic and led sample code but the get seems not to work
as homekit showes only the latest set status and does not get the update:
Thanks
Philipp
The text was updated successfully, but these errors were encountered: