-
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
Add example for irrigation system #251
base: master
Are you sure you want to change the base?
Conversation
examples/watering/main.c
Outdated
void task_fn(void * pvParameters) { | ||
gate *thisGate = (gate*)pvParameters; | ||
while(true) { | ||
homekit_characteristic_t *rd = thisGate->service->characteristics[5]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of relying on hard coded index, use homekit_service_characteristic_by_type:
homekit_characteristic_t *rd = homekit_service_characteristic_by_type(
thisGate->service, HOMEKIT_CHARACTERISTIC_REMAINING_DURATION
);
Or even pre-cache it inside gate
structure for improved performance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
homekit_service_characteristic_by_type
makes it a lot simpler 👍
But I don't quite understand how to implement the pre-cache thing.
examples/watering/main.c
Outdated
gates[i].number = i; | ||
gates[i].gpio = valve_gpios[i]; | ||
|
||
xTaskCreate(task_fn, valve_name_value, 256, &gates[i], tskIDLE_PRIORITY, &gates[i].task); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes sense to have a single task for all valves. All tasks needs to do is to wake up every second and check which valves are active and decrement their remaining duration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried my best here but I still need to store the task state as a variable. I tried to use vTaskGetInfo()
to get information about the task state but I got type undefined reference to vTaskGetInfo
from the compiler 😕
examples/watering/main.c
Outdated
10, | ||
.getter_ex=generic_getter, | ||
.setter_ex=generic_setter, | ||
.callback=HOMEKIT_CHARACTERISTIC_CALLBACK(on_update_generic), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what update sequence is there, but it feels that if this value is updated, you need to have a meaningful reaction (like update REMAINING_DURATION).
examples/watering/main.c
Outdated
gates[i].active = homekit_service_characteristic_by_type(nextService, "B0");; | ||
gates[i].remaining_duration = homekit_service_characteristic_by_type(nextService, "D4");; | ||
gates[i].set_duration = homekit_service_characteristic_by_type(nextService, "D3");; | ||
gates[i].in_use = homekit_service_characteristic_by_type(nextService, "D2");; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about saving some CPU cycles and creating characteristics first. Also, (for future) it is easier to use HOMEKIT_CHARACTERISTIC_<name>
(e.g. HOMEKIT_CHARACTERISTIC_ACTIVE
) defines instead of hard-coding UUIDs.
gates[i].active = NEW_HOMEKIT_CHARACTERISTIC(
ACTIVE, 0,
.callback=HOMEKIT_CHARACTERISTIC_CALLBACK(
on_update_active, .context=(void*)&gates[i],
),
);
// ...
homekit_service_t *nextService = NEW_HOMEKIT_SERVICE(VALVE, .characteristics=(homekit_characteristic_t*[]) {
// ...
gates[i].active,
gates[i].remaining_duration,
gates[i].set_duration,
gates[i].in_use,
NULL
});
examples/watering/main.c
Outdated
homekit_characteristic_t* in_use; | ||
} valve_t; | ||
|
||
valve_t gates[4]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
valve_t gates[valve_count];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But then the compiler complains: error: variably modified 'gates' at file scope
I improved some points you mentioned. |
ad3b9e4
to
4e282b6
Compare
After `Remaining Duration` reached 0 the valve would not turn of and stayed in `idle`. The bug was caused by turning of the `gate_task` to early.
Over the last weeks I improved my code a lot. As far I can see these points are not fixed right now: 1. Pre-cache characteristics
I don't quite understand how to implement this. 2. Use
|
Hey I did my best to implement an irrigation homekit service. It is similar to the
dynamic_services
example.Feedback is welcome 🙂