Running a task once and deleting a task

Hi everyone!
I am trying to achieve the following behaviour with lvgl micropython: a function/task creates a task which will be run once in x ms and get deleted then.
Creating a recurring task which would delete itself would be also useful. So far i found no solution how to this.

here some of my code, how i do it at the moment:
task_1 = lv.task_create(lambda task: led_toggle(), 1000, lv.TASK_PRIO.MID, None)
lv.task_create(lambda task: dimas_kohlemine.produce_ware(), 1000, lv.TASK_PRIO.HIGH, None)
lv.task_create(lambda task: gui_refresh_gauge(), 100, lv.TASK_PRIO.HIGH, None)
lv.task_create(lambda task: check_button_entladen_enabled(), 100, lv.TASK_PRIO.HIGH, None)

https://docs.lvgl.io/v7/en/html/overview/task.html

One-shot tasks

You can make a task to run only once by calling lv_task_once(task) . The task will automatically be deleted after being called for the first time.

This seems not available for the micropython bindings.
Also things like task_1._del() or task_1 = None doenst work. Could anyone point me in the right direction?

Something like that?

task = lv.task_create_basic()
task.set_period(1000)
task.set_repeat_count(1)
task.set_cb(lambda t: print("Hello once!"))

I think that lv_task_once no longer exists and was replaced by lv_set_repeat_count.
Docs are not up to date.

1 Like

Hi!
Thanks you a lot, i think this is exactly what i am looking for. Will test and verify the next days.