「App:Library:LVGL:docs:Overview:Timers」の版間の差分
(同じ利用者による、間の2版が非表示) | |||
1行目: | 1行目: | ||
https://docs.lvgl.io/8.2/overview/timer.html | https://docs.lvgl.io/8.2/overview/timer.html | ||
__NOTOC__ | __NOTOC__ | ||
+ | = Timers = | ||
{| class="wikitable" | {| class="wikitable" | ||
!英文 | !英文 | ||
6行目: | 7行目: | ||
|- | |- | ||
| | | | ||
− | | | + | 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. | ||
+ | |LVGLはタイマーシステムを内蔵しています。 | ||
+ | |||
+ | 関数を登録することで、定期的に呼び出されるようにすることができます。 | ||
+ | |||
+ | タイマーは<code style="color: #bb0000;">lv_timer_handler()</code>の中で処理され、数ミリ秒ごとに呼ばれる必要があります。 | ||
− | + | 詳しくは移植を参照してください。 | |
− | |||
− | + | タイマーはノンプリエンプティブです。つまり、タイマーは他のタイマーを中断することができません。 | |
+ | したがって、タイマーの中でLVGLに関連するあらゆる関数を呼び出すことができます。 | ||
+ | |} | ||
+ | :[[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 | + | {| 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. | ||
− | A timer callback should have a <code>void (*lv_timer_cb_t)(lv_timer_t *);</code> prototype. | + | This allows you to create a new timer without specifying any parameters. |
+ | |||
+ | 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) | ||
+ | { | ||
+ | /*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); | ||
+ | </syntaxhighlight> | ||
+ | |タイマーを新規に作成するには、<code style="color: #bb0000;">lv_timer_create(timer_cb, period_ms, user_data)</code>を使用します。 | ||
+ | |||
+ | これは<code style="color: #bb0000;">lv_timer_t *</code> 変数を作成し、後でタイマーのパラメータを変更するために使用することができます。 | ||
+ | |||
+ | <code style="color: #bb0000;">lv_timer_create_basic()</code>も使用可能です。 | ||
+ | |||
+ | これは、パラメータを指定せずに新しいタイマーを作成することができます。 | ||
+ | |||
+ | タイマーのコールバックは、<code style="color: #bb0000;">void (*lv_timer_cb_t)(lv_timer_t *);</code> のプロトタイプを持つ必要があります。 | ||
+ | |||
+ | 例えば<syntaxhighlight lang="C++" style="border:1px dashed gray;"> | ||
void my_timer(lv_timer_t * timer) | void my_timer(lv_timer_t * timer) | ||
{ | { | ||
39行目: | 95行目: | ||
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. | ||
+ | |<code style="color: #bb0000;">lv_timer_ready(timer)</code> は、次の<code style="color: #bb0000;">lv_timer_handler()</code>のコールでタイマーを実行させる。 | ||
+ | |||
+ | <code style="color: #bb0000;">lv_timer_reset(timer)</code> は、タイマーの周期をリセットします。 | ||
+ | |||
+ | 定義されたミリ秒の期間が経過すると、再び呼び出されます。 | ||
+ | |} | ||
+ | :[[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> |
+ | |タイマーのパラメータは後で変更することができます. | ||
+ | |||
+ | *<code style="color: #bb0000;">lv_timer_set_cb(timer, new_cb)</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. | ||
+ | |<code style="color: #bb0000;">lv_timer_set_repeat_count(timer, count)</code>で指定した回数だけタイマーを繰り返すようにすることができます。 | ||
+ | |||
+ | タイマーは指定された回数だけ呼び出された後、自動的に削除されます。 | ||
+ | |||
+ | カウントを<code style="color: #bb0000;">-1</code>にすると、無限に繰り返すことができます。 | ||
+ | |} | ||
+ | :[[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. | ||
+ | |<code style="color: #bb0000;">lv_timer_handler</code> のアイドルパーセント時間は <code style="color: #bb0000;">lv_timer_get_idle()</code>で得ることができます。 | ||
+ | |||
+ | 注意:これはシステム全体のアイドル時間を測定しているわけではなく、 <code style="color: #bb0000;">lv_timer_handler</code> のみを測定しています。 | ||
+ | OSを使用していて、タイマーで<code style="color: #bb0000;">lv_timer_handler</code> を呼び出す場合、OSがアイドルスレッドで過ごす時間を実際に測定しないので、誤解を招く可能性があります。 | ||
+ | |} | ||
+ | :[[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) | ||
+ | { | ||
+ | /*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*/ | ||
+ | </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>. | ||
+ | |場合によっては、アクションをすぐに実行できないことがあります。 | ||
+ | |||
+ | たとえば、他のユーザーがまだオブジェクトを使用しているため、または実行をブロックしたくないために、オブジェクトを削除することはできません。 | ||
+ | |||
+ | |||
+ | このような場合、<code style="color: #bb0000;">lv_async_call(my_function, data_p)</code>を使用すると、次に<code style="color: #bb0000;">lv_timer_handler</code>を呼び出したときに<code style="color: #bb0000;">my_function</code> を呼び出すことができます。<code style="color: #bb0000;">data_p</code>は、関数が呼び出されたときに渡されます。 | ||
+ | |||
+ | |||
+ | データポインターのみが保存されることに注意してください。そのため、関数の呼び出し中に変数が"alive"されるようにする必要があります。 | ||
+ | |||
+ | 静的、グローバル、または動的に割り当てられたデータです。 | ||
+ | |||
+ | 例:<syntaxhighlight lang="C++" style="border:1px dashed gray;"> | ||
void my_screen_clean_up(void * scr) | void my_screen_clean_up(void * scr) | ||
{ | { | ||
79行目: | 247行目: | ||
/*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*/ | ||
− | + | </syntaxhighlight> | |
+ | |||
+ | オブジェクトを削除したいだけで、<code style="color: #bb0000;">my_screen_cleanup</code> 内をクリーンアップする必要がない場合は、<code style="color: #bb0000;">lv_obj_del_async</code> を使用すれば、次に<code style="color: #bb0000;">lv_timer_handler</code>を呼び出したときにオブジェクトが削除されます。 | ||
+ | |} | ||
+ | :[[App:Library:LVGL:docs:Overview#Timers|戻る : Previous]] | ||
== API == | == API == | ||
− | Typedefs | + | {| class="wikitable" |
+ | !英文 | ||
+ | !自動翻訳 | ||
+ | |- | ||
+ | | | ||
+ | '''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 < | + | : ''#include <lv_timer.h>'' |
− | : | + | : Descriptor of a lv_timer |
− | :: How often | + | : '''Public Members''' |
− | : | + | : <span style="background-color: #eeeeee;">uint32_t period </span> |
− | :: Last time the | + | :: How often the timer should run |
− | : | + | : <span style="background-color: #eeeeee;">uint32_t last_run </span> |
+ | :: 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! |
− | ::* 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) | + | : '''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 style="color: #bb0000;">func_name(object, callback, ...)</code> convention) | ||
::* user_data -- custom parameter | ::* user_data -- custom parameter | ||
+ | |'''Typedefs''' | ||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">typedef void (*lv_timer_cb_t)(struct _lv_timer_t*) </span> | ||
+ | : タイマはこのような機能を担っています。 | ||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">typedef struct _lv_timer_t lv_timer_t </span> | ||
+ | : lv_timer の記述子。 | ||
+ | '''Functions''' | ||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">void _lv_timer_core_init(void) </span> | ||
+ | : lv_timer モジュールの初期化 | ||
+ | |||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">lv_timer_t *lv_timer_create_basic(void) </span> | ||
+ | : 空の」タイマーを作成します。少なくとも<code style="color: #bb0000;">lv_timer_set_cb</code> と<code style="color: #bb0000;">lv_timer_set_period</code>で初期化されている必要があります。 | ||
+ | : '''Returns''' | ||
+ | :: 作成されたタイマへのポインタ | ||
+ | |||
+ | <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> | ||
+ | : lv_timerを新規に作成します。 | ||
+ | : '''Parameters''' | ||
+ | ::* '''timer_xcb''' -- 定期的に呼び出すコールバック。(引数名の「x」は、<code style="color: #bb0000;">func_name(object, callback, ...)</code>の規約に従っていないため、完全な汎用関数でないことを示しています) | ||
+ | ::* '''period''' -- 呼び出し時間(ms単位 | ||
+ | ::* '''user_data''' -- カスタムパラメータ | ||
+ | : '''Returns''' | ||
+ | :: 新しいタイマへのポインタ | ||
+ | |||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">void lv_timer_del(lv_timer_t *timer) </span> | ||
+ | : Delete a lv_timer | ||
+ | : '''Parameters''' | ||
+ | :: '''timer''' -- lv_timerへのポインタ | ||
+ | |||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">void lv_timer_pause(lv_timer_t *timer) </span> | ||
+ | : タイマーを一時停止/再開する。 | ||
+ | : '''Parameters''' | ||
+ | :: '''timer''' -- 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> | ||
+ | : コールバックにタイマーを設定する(定期的に呼び出す関数)。 | ||
+ | : '''Parameters''' | ||
+ | ::* '''timer''' -- タイマーのポインタ | ||
+ | ::* '''timer_cb''' -- 定期的に呼び出す関数 | ||
+ | |||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">void lv_timer_set_period(lv_timer_t *timer, uint32_t period) </span> | ||
+ | : lv_timerに新しい周期を設定する。 | ||
+ | : '''Parameters''' | ||
+ | ::* '''timer''' -- lv_timerへのポインタ | ||
+ | ::* '''period''' -- 新しい期間 | ||
+ | |||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">void lv_timer_ready(lv_timer_t *timer) </span> | ||
+ | : lv_timerを準備します。それはその期間を待たないだろう。 | ||
+ | : '''Parameters''' | ||
+ | :: '''timer''' -- lv_timerへのポインタ。 | ||
+ | |||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">void lv_timer_set_repeat_count(lv_timer_t *timer, int32_t repeat_count) </span> | ||
+ | : タイマーを繰り返す回数を設定します。 | ||
+ | : '''Parameters''' | ||
+ | ::* '''timer''' -- lv_timerへのポインタ。 | ||
+ | ::* '''repeat_count''' -- -1:無限; 0:停止; n>0:残差時間 | ||
+ | |||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">void lv_timer_reset(lv_timer_t *timer) </span> | ||
+ | : lv_timerをリセットします。これは、事前に設定されたperiodミリ秒後に呼び出されます。 | ||
+ | : '''Parameters''' | ||
+ | :: '''timer''' -- lv_timerへのポインタ。 | ||
+ | |||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">void lv_timer_enable(bool en) </span> | ||
+ | : lv_timer処理全体を有効または無効にする | ||
+ | : '''Parameters''' | ||
+ | :: '''en''' -- true:lv_timer処理が実行中、 | ||
+ | :: false:lv_timer処理が中断されます。 | ||
+ | |||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">uint8_t lv_timer_get_idle(void) </span> | ||
+ | : アイドルパーセンテージの取得 | ||
+ | : '''Returns''' | ||
+ | :: lv_timerアイドル時間のパーセンテージ | ||
+ | |||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">lv_timer_t *lv_timer_get_next(lv_timer_t *timer) </span> | ||
+ | : タイマーを反復する | ||
+ | : '''Parameters''' | ||
+ | :: '''timer''' -- 反復を開始する場合はNULL、次のタイマーを取得する場合は前の戻り値 | ||
+ | : '''Returns''' | ||
+ | :: 次のタイマー、またはタイマーがない場合はNULL | ||
+ | |||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">struct _lv_timer_t </span> | ||
+ | :''#include <lv_timer.h>'' | ||
+ | : lv_timerの記述子 | ||
+ | : '''Public Members''' | ||
+ | :<span style="background-color: #eeeeee;">uint32_t period </span> | ||
+ | :: タイマーを実行する頻度 | ||
+ | :<span style="background-color: #eeeeee;">uint32_t last_run </span> | ||
+ | :: 前回タイマーが実行された時刻 | ||
+ | :<span style="background-color: #eeeeee;">lv_timer_cb_t timer_cb </span> | ||
+ | :: タイマー機能 | ||
+ | : | ||
+ | :<span style="background-color: #eeeeee;">void *user_data </span> | ||
+ | :: カスタム・ユーザー・データ | ||
+ | :<span style="background-color: #eeeeee;">int32_t repeat_count </span> | ||
+ | :: 1:1回; -1:無限; n>0:残差時間 | ||
+ | :<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> | ||
+ | : 非同期コールバックの型。 | ||
+ | |||
+ | '''Functions''' | ||
+ | |||
+ | <span style="background-color:#e7f2fa;color:#2980b9;">lv_res_t lv_async_call(lv_async_cb_t async_xcb, void *user_data) </span> | ||
+ | : 次にlv_timer_handler () が実行された時に非同期関数をコールします。 この関数は、呼び出しが実際に発生する前に返される可能性があります。 | ||
+ | : '''Parameters''' | ||
+ | ::* async_xcb--タスク自体のコールバック。(引数名の'x'は、<code style="color: #bb0000;">func_name(object, callback, ...)</code>の規約に従っていないため、完全なジェネリック関数ではないことを示します。) | ||
+ | ::* user_data -- カスタムパラメータ | ||
+ | |} | ||
− | + | [[App:Library:LVGL#Overview|戻る : Previous]] |
2022年7月2日 (土) 12:57時点における最新版
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 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. |
LVGLはタイマーシステムを内蔵しています。
関数を登録することで、定期的に呼び出されるようにすることができます。 タイマーは 詳しくは移植を参照してください。 タイマーはノンプリエンプティブです。つまり、タイマーは他のタイマーを中断することができません。 したがって、タイマーの中でLVGLに関連するあらゆる関数を呼び出すことができます。 |
Create a timer
英文 | 自動翻訳 |
---|---|
To create a new timer, use It will create an This allows you to create a new timer without specifying any parameters. 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);
|
タイマーを新規に作成するには、lv_timer_create(timer_cb, period_ms, user_data) を使用します。
これは
これは、パラメータを指定せずに新しいタイマーを作成することができます。 タイマーのコールバックは、 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
英文 | 自動翻訳 |
---|---|
It will be called again after the defined period of milliseconds has elapsed. |
lv_timer_ready(timer) は、次のlv_timer_handler() のコールでタイマーを実行させる。
定義されたミリ秒の期間が経過すると、再び呼び出されます。 |
Set parameters
英文 | 自動翻訳 |
---|---|
You can modify some timer parameters later:
|
タイマーのパラメータは後で変更することができます.
|
Repeat count
英文 | 自動翻訳 |
---|---|
You can make a timer repeat only a given number of times with The timer will automatically be deleted after it's called the defined number of times. Set the count to |
lv_timer_set_repeat_count(timer, count) で指定した回数だけタイマーを繰り返すようにすることができます。
タイマーは指定された回数だけ呼び出された後、自動的に削除されます。 カウントを |
Measure idle time
英文 | 自動翻訳 |
---|---|
You can get the idle percentage time of Note that, it doesn't measure the idle time of the overall system, only It can be misleading if you use an operating system and call |
lv_timer_handler のアイドルパーセント時間は lv_timer_get_idle() で得ることができます。
注意:これはシステム全体のアイドル時間を測定しているわけではなく、 OSを使用していて、タイマーで |
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.
It can be static, global or dynamically allocated data. 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*/
|
場合によっては、アクションをすぐに実行できないことがあります。
たとえば、他のユーザーがまだオブジェクトを使用しているため、または実行をブロックしたくないために、オブジェクトを削除することはできません。
静的、グローバル、または動的に割り当てられたデータです。 例: 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*/
|
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)
|
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)
|