「App:Library:LVGL:docs:Overview:Timers」の版間の差分
2行目: | 2行目: | ||
__NOTOC__ | __NOTOC__ | ||
= Timers = | = Timers = | ||
− | LVGL has a built-in timer system. You can register a function to have it be called periodically. The timers are handled and called in <code>lv_timer_handler()</code>, which needs to be called every few milliseconds. See Porting for more information. | + | {| class="wikitable" |
+ | !英文 | ||
+ | !自動翻訳 | ||
+ | |- | ||
+ | | | ||
+ | LVGL has a built-in timer system. You can register a function to have it be called periodically. The timers are handled and called in <code style="color: #bb0000;">lv_timer_handler()</code>, which needs to be called every few milliseconds. See Porting for more information. | ||
Timers are non-preemptive, which means a timer cannot interrupt another timer. Therefore, you can call any LVGL related function in a timer. | Timers are non-preemptive, which means a timer cannot interrupt another timer. Therefore, you can call any LVGL related function in a timer. | ||
− | + | | | |
+ | |} | ||
+ | :[[App:Library:LVGL:docs:Overview#Timers|戻る : Previous]] | ||
== Create a timer == | == Create a timer == | ||
− | To create a new timer, use <code>lv_timer_create(timer_cb, period_ms, user_data)</code>. It will create an <code>lv_timer_t *</code> variable, which can be used later to modify the parameters of the timer. <code>lv_timer_create_basic()</code> can also be used. This allows you to create a new timer without specifying any parameters. | + | {| class="wikitable" |
+ | !英文 | ||
+ | !自動翻訳 | ||
+ | |- | ||
+ | | | ||
+ | To create a new timer, use <code style="color: #bb0000;">lv_timer_create(timer_cb, period_ms, user_data)</code>. It will create an <code style="color: #bb0000;">lv_timer_t *</code> variable, which can be used later to modify the parameters of the timer. <code style="color: #bb0000;">lv_timer_create_basic()</code> can also be used. This allows you to create a new timer without specifying any parameters. | ||
− | A timer callback should have a <code>void (*lv_timer_cb_t)(lv_timer_t *);</code> prototype. | + | A timer callback should have a <code style="color: #bb0000;">void (*lv_timer_cb_t)(lv_timer_t *);</code> prototype. |
For example: | For example: | ||
+ | <syntaxhighlight lang="C++" style="border:1px dashed gray;"> | ||
void my_timer(lv_timer_t * timer) | void my_timer(lv_timer_t * timer) | ||
{ | { | ||
31行目: | 44行目: | ||
static uint32_t user_data = 10; | static uint32_t user_data = 10; | ||
lv_timer_t * timer = lv_timer_create(my_timer, 500, &user_data); | lv_timer_t * timer = lv_timer_create(my_timer, 500, &user_data); | ||
+ | </syntaxhighlight> | ||
+ | | | ||
+ | |} | ||
+ | :[[App:Library:LVGL:docs:Overview#Timers|戻る : Previous]] | ||
+ | |||
== Ready and Reset == | == Ready and Reset == | ||
− | <code>lv_timer_ready(timer)</code> makes a timer run on the next call of <code>lv_timer_handler()</code>. | + | {| class="wikitable" |
+ | !英文 | ||
+ | !自動翻訳 | ||
+ | |- | ||
+ | | | ||
+ | <code style="color: #bb0000;">lv_timer_ready(timer)</code> makes a timer run on the next call of <code style="color: #bb0000;">lv_timer_handler()</code>. | ||
+ | |||
+ | <code style="color: #bb0000;">lv_timer_reset(timer)</code> resets the period of a timer. It will be called again after the defined period of milliseconds has elapsed. | ||
+ | | | ||
+ | |} | ||
+ | :[[App:Library:LVGL:docs:Overview#Timers|戻る : Previous]] | ||
− | |||
== Set parameters == | == Set parameters == | ||
+ | {| class="wikitable" | ||
+ | !英文 | ||
+ | !自動翻訳 | ||
+ | |- | ||
+ | | | ||
You can modify some timer parameters later: | You can modify some timer parameters later: | ||
− | * <code>lv_timer_set_cb(timer, new_cb)</code> | + | * <code style="color: #bb0000;">lv_timer_set_cb(timer, new_cb)</code> |
− | * <code>lv_timer_set_period(timer, new_period)</code> | + | * <code style="color: #bb0000;">lv_timer_set_period(timer, new_period)</code> |
+ | | | ||
+ | |} | ||
+ | :[[App:Library:LVGL:docs:Overview#Timers|戻る : Previous]] | ||
+ | |||
== Repeat count == | == Repeat count == | ||
− | You can make a timer repeat only a given number of times with <code>lv_timer_set_repeat_count(timer, count)</code>. The timer will automatically be deleted after it's called the defined number of times. Set the count to <code>-1</code> to repeat indefinitely. | + | {| class="wikitable" |
+ | !英文 | ||
+ | !自動翻訳 | ||
+ | |- | ||
+ | | | ||
+ | You can make a timer repeat only a given number of times with <code style="color: #bb0000;">lv_timer_set_repeat_count(timer, count)</code>. The timer will automatically be deleted after it's called the defined number of times. Set the count to <code style="color: #bb0000;">-1</code> to repeat indefinitely. | ||
+ | | | ||
+ | |} | ||
+ | :[[App:Library:LVGL:docs:Overview#Timers|戻る : Previous]] | ||
+ | |||
== Measure idle time == | == Measure idle time == | ||
− | You can get the idle percentage time of <code>lv_timer_handler</code> with <code>lv_timer_get_idle()</code>. Note that, it doesn't measure the idle time of the overall system, only <code>lv_timer_handler</code>. It can be misleading if you use an operating system and call <code>lv_timer_handler</code> in a timer, as it won't actually measure the time the OS spends in an idle thread. | + | {| class="wikitable" |
− | + | !英文 | |
+ | !自動翻訳 | ||
+ | |- | ||
+ | | | ||
+ | You can get the idle percentage time of <code style="color: #bb0000;">lv_timer_handler</code> with <code style="color: #bb0000;">lv_timer_get_idle()</code>. Note that, it doesn't measure the idle time of the overall system, only <code style="color: #bb0000;">lv_timer_handler</code>. It can be misleading if you use an operating system and call <code style="color: #bb0000;">lv_timer_handler</code> in a timer, as it won't actually measure the time the OS spends in an idle thread. | ||
+ | | | ||
+ | |} | ||
+ | :[[App:Library:LVGL:docs:Overview#Timers|戻る : Previous]] | ||
== Asynchronous calls == | == Asynchronous calls == | ||
− | In some cases, you can't perform an action immediately. For example, you can't delete an object because something else is still using it, or you don't want to block the execution now. For these cases, <code>lv_async_call(my_function, data_p)</code> can be used to call <code>my_function</code> on the next invocation of <code>lv_timer_handler</code>. <code>data_p</code> will be passed to the function when it's called. Note that only the data pointer is saved, so you need to ensure that the variable will be "alive" while the function is called. It can be ''static'', global or dynamically allocated data. | + | {| class="wikitable" |
+ | !英文 | ||
+ | !自動翻訳 | ||
+ | |- | ||
+ | | | ||
+ | In some cases, you can't perform an action immediately. For example, you can't delete an object because something else is still using it, or you don't want to block the execution now. For these cases, <code style="color: #bb0000;">lv_async_call(my_function, data_p)</code> can be used to call <code style="color: #bb0000;">my_function</code> on the next invocation of <code style="color: #bb0000;">lv_timer_handler</code>. <code style="color: #bb0000;">data_p</code> will be passed to the function when it's called. Note that only the data pointer is saved, so you need to ensure that the variable will be "alive" while the function is called. It can be ''static'', global or dynamically allocated data. | ||
For example: | For example: | ||
+ | <syntaxhighlight lang="C++" style="border:1px dashed gray;"> | ||
void my_screen_clean_up(void * scr) | void my_screen_clean_up(void * scr) | ||
{ | { | ||
71行目: | 129行目: | ||
/*The screen is still valid so you can do other things with it*/ | /*The screen is still valid so you can do other things with it*/ | ||
− | If you just want to delete an object and don't need to clean anything up in <code>my_screen_cleanup</code> you could just use <code>lv_obj_del_async</code> which will delete the object on the next call to <code>lv_timer_handler</code>. | + | </syntaxhighlight> |
− | + | If you just want to delete an object and don't need to clean anything up in <code style="color: #bb0000;">my_screen_cleanup</code> you could just use <code style="color: #bb0000;">lv_obj_del_async</code> which will delete the object on the next call to <code style="color: #bb0000;">lv_timer_handler</code>. | |
+ | | | ||
+ | |} | ||
+ | :[[App:Library:LVGL:docs:Overview#Timers|戻る : Previous]] | ||
== API == | == API == | ||
+ | {| class="wikitable" | ||
+ | !英文 | ||
+ | !自動翻訳 | ||
+ | |- | ||
+ | | | ||
Typedefs | Typedefs | ||
− | + | <span style="background-color:#e7f2fa;color:#2980b9;">typedef void (*lv_timer_cb_t)(struct _lv_timer_t*) </span> | |
: Timers execute this type of functions. | : Timers execute this type of functions. | ||
− | + | <span style="background-color:#e7f2fa;color:#2980b9;">typedef struct _lv_timer_t lv_timer_t </span> | |
: Descriptor of a lv_timer | : Descriptor of a lv_timer | ||
− | + | Functions | |
− | + | <span style="background-color:#e7f2fa;color:#2980b9;">void _lv_timer_core_init(void) </span> | |
: Init the lv_timer module | : Init the lv_timer module | ||
− | |||
− | + | ||
− | : Create an "empty" timer. It needs | + | <span style="background-color:#e7f2fa;color:#2980b9;">lv_timer_t *lv_timer_create_basic(void) </span> |
− | : | + | : Create an "empty" timer. It needs to initialized with at least <code style="color: #bb0000;">lv_timer_set_cb</code> and <code style="color: #bb0000;">lv_timer_set_period</code> |
+ | : Returns | ||
:: pointer to the created timer | :: pointer to the created timer | ||
− | + | <span style="background-color:#e7f2fa;color:#2980b9;">lv_timer_t *lv_timer_create(lv_timer_cb_t timer_xcb, uint32_t period, void *user_data) </span> | |
: Create a new lv_timer | : Create a new lv_timer | ||
− | : | + | : Parameters |
− | ::* timer_xcb -- a callback to call | + | ::* timer_xcb -- a callback to call periodically. (the 'x' in the argument name indicates that it's not a fully generic function because it not follows the <code style="color: #bb0000;">func_name(object, callback, ...)</code> convention) |
::* period -- call period in ms unit | ::* period -- call period in ms unit | ||
::* user_data -- custom parameter | ::* user_data -- custom parameter | ||
− | : | + | : Returns |
:: pointer to the new timer | :: pointer to the new timer | ||
− | + | <span style="background-color:#e7f2fa;color:#2980b9;">void lv_timer_del(lv_timer_t *timer) </span> | |
: Delete a lv_timer | : Delete a lv_timer | ||
− | : | + | : Parameters |
:: timer -- pointer to an lv_timer | :: timer -- pointer to an lv_timer | ||
− | + | <span style="background-color:#e7f2fa;color:#2980b9;">void lv_timer_pause(lv_timer_t *timer) </span> | |
: Pause/resume a timer. | : Pause/resume a timer. | ||
− | : | + | : Parameters |
:: timer -- pointer to an lv_timer | :: timer -- pointer to an lv_timer | ||
− | + | <span style="background-color:#e7f2fa;color:#2980b9;">void lv_timer_resume(lv_timer_t *timer) </span> | |
: | : | ||
− | + | <span style="background-color:#e7f2fa;color:#2980b9;">void lv_timer_set_cb(lv_timer_t *timer, lv_timer_cb_t timer_cb) </span> | |
− | : Set the callback the timer (the function to call | + | : Set the callback the timer (the function to call periodically) |
− | : | + | : Parameters |
::* timer -- pointer to a timer | ::* timer -- pointer to a timer | ||
::* timer_cb -- the function to call periodically | ::* timer_cb -- the function to call periodically | ||
− | + | <span style="background-color:#e7f2fa;color:#2980b9;">void lv_timer_set_period(lv_timer_t *timer, uint32_t period) </span> | |
: Set new period for a lv_timer | : Set new period for a lv_timer | ||
− | : | + | : Parameters |
− | ::* timer - | + | ::* timer -- pointer to a lv_timer |
::* period -- the new period | ::* period -- the new period | ||
− | + | <span style="background-color:#e7f2fa;color:#2980b9;">void lv_timer_ready(lv_timer_t *timer) </span> | |
− | : Make a lv_timer ready. It will not | + | : Make a lv_timer ready. It will not wait its period. |
− | : | + | : Parameters |
:: timer -- pointer to a lv_timer. | :: timer -- pointer to a lv_timer. | ||
− | + | <span style="background-color:#e7f2fa;color:#2980b9;">void lv_timer_set_repeat_count(lv_timer_t *timer, int32_t repeat_count) </span> | |
: Set the number of times a timer will repeat. | : Set the number of times a timer will repeat. | ||
− | : | + | : Parameters |
− | ::* | + | ::* timer -- pointer to a lv_timer. |
::* repeat_count -- -1 : infinity; 0 : stop ; n>0: residual times | ::* repeat_count -- -1 : infinity; 0 : stop ; n>0: residual times | ||
− | + | <span style="background-color:#e7f2fa;color:#2980b9;">void lv_timer_reset(lv_timer_t *timer) </span> | |
− | : Reset a lv_timer. It will be | + | : Reset a lv_timer. It will be called the previously set period milliseconds later. |
− | : | + | : Parameters |
:: timer -- pointer to a lv_timer. | :: timer -- pointer to a lv_timer. | ||
− | + | <span style="background-color:#e7f2fa;color:#2980b9;">void lv_timer_enable(bool en) </span> | |
− | : Enable or disable the | + | : Enable or disable the whole lv_timer handling |
− | : | + | : Parameters |
:: en -- true: lv_timer handling is running, false: lv_timer handling is suspended | :: en -- true: lv_timer handling is running, false: lv_timer handling is suspended | ||
− | + | <span style="background-color:#e7f2fa;color:#2980b9;">uint8_t lv_timer_get_idle(void) </span> | |
: Get idle percentage | : Get idle percentage | ||
− | : | + | : Returns |
:: the lv_timer idle in percentage | :: the lv_timer idle in percentage | ||
− | + | <span style="background-color:#e7f2fa;color:#2980b9;">lv_timer_t *lv_timer_get_next(lv_timer_t *timer) </span> | |
: Iterate through the timers | : Iterate through the timers | ||
− | : | + | : Parameters |
− | :: | + | :: timer -- NULL to start iteration or the previous return value to get the next timer |
− | : | + | : Returns |
:: the next timer or NULL if there is no more timer | :: the next timer or NULL if there is no more timer | ||
− | + | <span style="background-color:#e7f2fa;color:#2980b9;">struct _lv_timer_t </span> | |
− | : ''#include <lv_t'' | + | : ''#include <lv_t''''imer.h>'' Descriptor of a lv_timer Public Members |
− | : | + | : <span style="background-color: #eeeeee;">uint32_t period </span> |
− | :: How often | + | :: How often the timer should run |
− | : | + | : <span style="background-color: #eeeeee;">uint32_t last_run </span> |
− | :: Last time the | + | :: Last time the timer ran |
− | : | + | : <span style="background-color: #eeeeee;">lv_timer_cb_t timer_cb </span> |
:: Timer function | :: Timer function | ||
− | : | + | : |
− | : | + | : <span style="background-color: #eeeeee;">void *user_data </span> |
− | :: Custom user | + | :: Custom user data |
− | : | + | : <span style="background-color: #eeeeee;">int32_t repeat_count </span> |
− | :: 1: One time; -1 | + | :: 1: One time; -1 : infinity; n>0: residual times |
− | : | + | : <span style="background-color: #eeeeee;">uint32_t paused </span> |
:: | :: | ||
− | + | Typedefs | |
− | + | <span style="background-color:#e7f2fa;color:#2980b9;">typedef void (*lv_async_cb_t)(void*) </span> | |
: Type for async callback. | : Type for async callback. | ||
− | + | Functions | |
− | + | <span style="background-color:#e7f2fa;color:#2980b9;">lv_res_t lv_async_call(lv_async_cb_t async_xcb, void *user_data) </span> | |
− | : Call an asynchronous function the next time lv_timer_handler | + | : Call an asynchronous function the next time lv_timer_handler() is run. This function is likely to return before the call actually happens! |
− | : | + | : Parameters |
− | ::* async_xcb -- a callback which is the task itself. (the 'x' in the argument name indicates that it's not a fully generic function because it not follows the <code>func_name(object, callback, ...)</code> convention) | + | ::* async_xcb -- a callback which is the task itself. (the 'x' in the argument name indicates that it's not a fully generic function because it not follows the <code style="color: #bb0000;">func_name(object, callback, ...)</code> convention) |
::* user_data -- custom parameter | ::* user_data -- custom parameter | ||
+ | | | ||
+ | |} | ||
− | + | [[App:Library:LVGL#Overview|戻る : Previous]] | |
− | |||
− | |||
− | |||
− | |||
− |
2022年7月2日 (土) 12:29時点における版
https://docs.lvgl.io/8.2/overview/timer.html
Timers
英文 | 自動翻訳 |
---|---|
LVGL has a built-in timer system. You can register a function to have it be called periodically. The timers are handled and called in Timers are non-preemptive, which means a timer cannot interrupt another timer. Therefore, you can call any LVGL related function in a timer. |
Create a timer
英文 | 自動翻訳 |
---|---|
To create a new timer, use A timer callback should have a For example: void my_timer(lv_timer_t * timer)
{
/*Use the user_data*/
uint32_t * user_data = timer->user_data;
printf("my_timer called with user data: %d\n", *user_data);
/*Do something with LVGL*/
if(something_happened) {
something_happened = false;
lv_btn_create(lv_scr_act(), NULL);
}
}
...
static uint32_t user_data = 10;
lv_timer_t * timer = lv_timer_create(my_timer, 500, &user_data);
|
Ready and Reset
英文 | 自動翻訳 |
---|---|
|
Set parameters
英文 | 自動翻訳 |
---|---|
You can modify some timer parameters later:
|
Repeat count
英文 | 自動翻訳 |
---|---|
You can make a timer repeat only a given number of times with |
Measure idle time
英文 | 自動翻訳 |
---|---|
You can get the idle percentage time of |
Asynchronous calls
英文 | 自動翻訳 |
---|---|
In some cases, you can't perform an action immediately. For example, you can't delete an object because something else is still using it, or you don't want to block the execution now. For these cases, For example: void my_screen_clean_up(void * scr)
{
/*Free some resources related to `scr`*/
/*Finally delete the screen*/
lv_obj_del(scr);
}
...
/*Do something with the object on the current screen*/
/*Delete screen on next call of `lv_timer_handler`, not right now.*/
lv_async_call(my_screen_clean_up, lv_scr_act());
/*The screen is still valid so you can do other things with it*/
If you just want to delete an object and don't need to clean anything up in |
API
英文 | 自動翻訳 |
---|---|
Typedefs typedef void (*lv_timer_cb_t)(struct _lv_timer_t*)
typedef struct _lv_timer_t lv_timer_t
Functions void _lv_timer_core_init(void)
lv_timer_t *lv_timer_create(lv_timer_cb_t timer_xcb, uint32_t period, void *user_data)
void lv_timer_del(lv_timer_t *timer)
void lv_timer_pause(lv_timer_t *timer)
void lv_timer_resume(lv_timer_t *timer) void lv_timer_set_cb(lv_timer_t *timer, lv_timer_cb_t timer_cb)
void lv_timer_set_period(lv_timer_t *timer, uint32_t period)
void lv_timer_ready(lv_timer_t *timer)
void lv_timer_set_repeat_count(lv_timer_t *timer, int32_t repeat_count)
void lv_timer_reset(lv_timer_t *timer)
void lv_timer_enable(bool en)
uint8_t lv_timer_get_idle(void)
lv_timer_t *lv_timer_get_next(lv_timer_t *timer)
struct _lv_timer_t
Typedefs typedef void (*lv_async_cb_t)(void*)
Functions lv_res_t lv_async_call(lv_async_cb_t async_xcb, void *user_data)
|