「App:Library:LVGL:docs:Porting:Input device interface」の版間の差分

提供: robot-jp wiki
ナビゲーションに移動検索に移動
35行目: 35行目:
  
 
== Types of input devices ==
 
== Types of input devices ==
To register an input device an <code>lv_indev_drv_t</code> variable has to be initialized. Be sure to register at least one display before you register any input devices.
+
To register an input device an <code style="color: #bb0000;">lv_indev_drv_t</code> variable has to be initialized. Be sure to register at least one display before you register any input devices.
 +
<syntaxhighlight lang="C++">
 
  lv_disp_drv_register(&disp_drv);
 
  lv_disp_drv_register(&disp_drv);
 
   
 
   
44行目: 45行目:
 
  /*Register the driver in LVGL and save the created input device object*/
 
  /*Register the driver in LVGL and save the created input device object*/
 
  lv_indev_t * my_indev = lv_indev_drv_register(&indev_drv);
 
  lv_indev_t * my_indev = lv_indev_drv_register(&indev_drv);
The <code>type</code> member can be:
+
</syntaxhighlight>
 +
The <code style="color: #bb0000;">type</code> member can be:
  
* <code>LV_INDEV_TYPE_POINTER</code> touchpad or mouse
+
* <code style="color: #bb0000;">LV_INDEV_TYPE_POINTER</code> touchpad or mouse
* <code>LV_INDEV_TYPE_KEYPAD</code> keyboard or keypad
+
* <code style="color: #bb0000;">LV_INDEV_TYPE_KEYPAD</code> keyboard or keypad
* <code>LV_INDEV_TYPE_ENCODER</code> encoder with left/right turn and push options
+
* <code style="color: #bb0000;">LV_INDEV_TYPE_ENCODER</code> encoder with left/right turn and push options
* <code>LV_INDEV_TYPE_BUTTON</code> external buttons virtually pressing the screen
+
* <code style="color: #bb0000;">LV_INDEV_TYPE_BUTTON</code> external buttons virtually pressing the screen
  
<code>read_cb</code> is a function pointer which will be called periodically to report the current state of an input device.
+
<code style="color: #bb0000;">read_cb</code> is a function pointer which will be called periodically to report the current state of an input device.
  
 
Visit Input devices to learn more about input devices in general.
 
Visit Input devices to learn more about input devices in general.
59行目: 61行目:
 
=== Touchpad, mouse or any pointer ===
 
=== Touchpad, mouse or any pointer ===
 
Input devices that can click points on the screen belong to this category.
 
Input devices that can click points on the screen belong to this category.
 +
<syntaxhighlight lang="C++">
 
  indev_drv.type = LV_INDEV_TYPE_POINTER;
 
  indev_drv.type = LV_INDEV_TYPE_POINTER;
 
  indev_drv.read_cb = my_input_read;
 
  indev_drv.read_cb = my_input_read;
74行目: 77行目:
 
   }
 
   }
 
  }
 
  }
To set a mouse cursor use <code>lv_indev_set_cursor(my_indev, &img_cursor)</code>. (<code>my_indev</code> is the return value of <code>lv_indev_drv_register</code>)
+
</syntaxhighlight>
 +
To set a mouse cursor use <code style="color: #bb0000;">lv_indev_set_cursor(my_indev, &img_cursor)</code>. (<code style="color: #bb0000;">my_indev</code> is the return value of <code style="color: #bb0000;">lv_indev_drv_register</code>)
 
:[https://robot-jp.com/wiki/index.php/App:Library:LVGL:docs:Porting 戻る : Previous]
 
:[https://robot-jp.com/wiki/index.php/App:Library:LVGL:docs:Porting 戻る : Previous]
  
83行目: 87行目:
 
To use a keyboard/keypad:
 
To use a keyboard/keypad:
  
* Register a <code>read_cb</code> function with <code>LV_INDEV_TYPE_KEYPAD</code> type.
+
* Register a <code style="color: #bb0000;">read_cb</code> function with <code style="color: #bb0000;">LV_INDEV_TYPE_KEYPAD</code> type.
* An object group has to be created: <code>lv_group_t * g = lv_group_create()</code> and objects have to be added to it with <code>lv_group_add_obj(g, obj)</code>
+
* An object group has to be created: <code style="color: #bb0000;">lv_group_t * g = lv_group_create()</code> and objects have to be added to it with <code style="color: #bb0000;">lv_group_add_obj(g, obj)</code>
* The created group has to be assigned to an input device: <code>lv_indev_set_group(my_indev, g)</code> (<code>my_indev</code> is the return value of <code>lv_indev_drv_register</code>)
+
* The created group has to be assigned to an input device: <code style="color: #bb0000;">lv_indev_set_group(my_indev, g)</code> (<code style="color: #bb0000;">my_indev</code> is the return value of <code style="color: #bb0000;">lv_indev_drv_register</code>)
* Use <code>LV_KEY_...</code> to navigate among the objects in the group. See <code>lv_core/lv_group.h</code> for the available keys.
+
* Use <code style="color: #bb0000;">LV_KEY_...</code> to navigate among the objects in the group. See <code style="color: #bb0000;">lv_core/lv_group.h</code> for the available keys.
 
+
<syntaxhighlight lang="C++">
 
  indev_drv.type = LV_INDEV_TYPE_KEYPAD;
 
  indev_drv.type = LV_INDEV_TYPE_KEYPAD;
 
  indev_drv.read_cb = keyboard_read;
 
  indev_drv.read_cb = keyboard_read;
99行目: 103行目:
 
   else data->state = LV_INDEV_STATE_RELEASED;
 
   else data->state = LV_INDEV_STATE_RELEASED;
 
  }
 
  }
 +
</syntaxhighlight>
 
:[https://robot-jp.com/wiki/index.php/App:Library:LVGL:docs:Porting 戻る : Previous]
 
:[https://robot-jp.com/wiki/index.php/App:Library:LVGL:docs:Porting 戻る : Previous]
  
118行目: 123行目:
  
 
To use an ''Encoder'' (similarly to the ''Keypads'') the objects should be added to groups.
 
To use an ''Encoder'' (similarly to the ''Keypads'') the objects should be added to groups.
 +
<syntaxhighlight lang="C++">
 
  indev_drv.type = LV_INDEV_TYPE_ENCODER;
 
  indev_drv.type = LV_INDEV_TYPE_ENCODER;
 
  indev_drv.read_cb = encoder_read;
 
  indev_drv.read_cb = encoder_read;
129行目: 135行目:
 
   else data->state = LV_INDEV_STATE_RELEASED;
 
   else data->state = LV_INDEV_STATE_RELEASED;
 
  }
 
  }
 +
</syntaxhighlight>
 
:[https://robot-jp.com/wiki/index.php/App:Library:LVGL:docs:Porting 戻る : Previous]
 
:[https://robot-jp.com/wiki/index.php/App:Library:LVGL:docs:Porting 戻る : Previous]
  
137行目: 144行目:
 
You need to have 3 buttons available:
 
You need to have 3 buttons available:
  
* <code>LV_KEY_ENTER</code> will simulate press or pushing of the encoder button
+
* <code style="color: #bb0000;">LV_KEY_ENTER</code> will simulate press or pushing of the encoder button
* <code>LV_KEY_LEFT</code> will simulate turning encoder left
+
* <code style="color: #bb0000;">LV_KEY_LEFT</code> will simulate turning encoder left
* <code>LV_KEY_RIGHT</code> will simulate turning encoder right
+
* <code style="color: #bb0000;">LV_KEY_RIGHT</code> will simulate turning encoder right
 
* other keys will be passed to the focused widget
 
* other keys will be passed to the focused widget
  
If you hold the keys it will simulate an encoder advance with period specified in <code>indev_drv.long_press_rep_time</code>.
+
If you hold the keys it will simulate an encoder advance with period specified in <code style="color: #bb0000;">indev_drv.long_press_rep_time</code>.
 +
<syntaxhighlight lang="C++">
 
  indev_drv.type = LV_INDEV_TYPE_ENCODER;
 
  indev_drv.type = LV_INDEV_TYPE_ENCODER;
 
  indev_drv.read_cb = encoder_with_keys_read;
 
  indev_drv.read_cb = encoder_with_keys_read;
158行目: 166行目:
 
   }
 
   }
 
  }
 
  }
 +
</syntaxhighlight>
 
:[https://robot-jp.com/wiki/index.php/App:Library:LVGL:docs:Porting 戻る : Previous]
 
:[https://robot-jp.com/wiki/index.php/App:Library:LVGL:docs:Porting 戻る : Previous]
  
164行目: 173行目:
 
''Buttons'' mean external "hardware" buttons next to the screen which are assigned to specific coordinates of the screen. If a button is pressed it will simulate the pressing on the assigned coordinate. (Similarly to a touchpad)
 
''Buttons'' mean external "hardware" buttons next to the screen which are assigned to specific coordinates of the screen. If a button is pressed it will simulate the pressing on the assigned coordinate. (Similarly to a touchpad)
  
To assign buttons to coordinates use <code>lv_indev_set_button_points(my_indev, points_array)</code>.
+
To assign buttons to coordinates use <code style="color: #bb0000;">lv_indev_set_button_points(my_indev, points_array)</code>.
  
<code>points_array</code> should look like <code>const lv_point_t points_array[] = { {12,30},{60,90}, ...}</code>
+
<code style="color: #bb0000;">points_array</code> should look like <code style="color: #bb0000;">const lv_point_t points_array[] = { {12,30},{60,90}, ...}</code>
  
 
Important
 
Important
  
 
The points_array can't go out of scope. Either declare it as a global variable or as a static variable inside a function.
 
The points_array can't go out of scope. Either declare it as a global variable or as a static variable inside a function.
 +
<syntaxhighlight lang="C++">
 
  indev_drv.type = LV_INDEV_TYPE_BUTTON;
 
  indev_drv.type = LV_INDEV_TYPE_BUTTON;
 
  indev_drv.read_cb = button_read;
 
  indev_drv.read_cb = button_read;
188行目: 198行目:
 
     data->btn = last_btn;            /*Save the last button*/
 
     data->btn = last_btn;            /*Save the last button*/
 
  }
 
  }
 +
</syntaxhighlight>
 
:[https://robot-jp.com/wiki/index.php/App:Library:LVGL:docs:Porting 戻る : Previous]
 
:[https://robot-jp.com/wiki/index.php/App:Library:LVGL:docs:Porting 戻る : Previous]
  
194行目: 205行目:
  
 
=== Parameters ===
 
=== Parameters ===
The default value of the following parameters can be changed in <code>lv_indev_drv_t</code>:
+
The default value of the following parameters can be changed in <code style="color: #bb0000;">lv_indev_drv_t</code>:
  
* <code>scroll_limit</code> Number of pixels to slide before actually scrolling the object.
+
* <code style="color: #bb0000;">scroll_limit</code> Number of pixels to slide before actually scrolling the object.
* <code>scroll_throw</code> Scroll throw (momentum) slow-down in [%]. Greater value means faster slow-down.
+
* <code style="color: #bb0000;">scroll_throw</code> Scroll throw (momentum) slow-down in [%]. Greater value means faster slow-down.
* <code>long_press_time</code> Press time to send <code>LV_EVENT_LONG_PRESSED</code> (in milliseconds)
+
* <code style="color: #bb0000;">long_press_time</code> Press time to send <code style="color: #bb0000;">LV_EVENT_LONG_PRESSED</code> (in milliseconds)
* <code>long_press_rep_time</code> Interval of sending <code>LV_EVENT_LONG_PRESSED_REPEAT</code> (in milliseconds)
+
* <code style="color: #bb0000;">long_press_rep_time</code> Interval of sending <code style="color: #bb0000;">LV_EVENT_LONG_PRESSED_REPEAT</code> (in milliseconds)
* <code>read_timer</code> pointer to the <code>lv_timer</code> which reads the input device. Its parameters can be changed by <code>lv_timer_...()</code> functions. <code>LV_INDEV_DEF_READ_PERIOD</code> in <code>lv_conf.h</code> sets the default read period.
+
* <code style="color: #bb0000;">read_timer</code> pointer to the <code style="color: #bb0000;">lv_timer</code> which reads the input device. Its parameters can be changed by <code style="color: #bb0000;">lv_timer_...()</code> functions. <code style="color: #bb0000;">LV_INDEV_DEF_READ_PERIOD</code> in <code style="color: #bb0000;">lv_conf.h</code> sets the default read period.
 
:[https://robot-jp.com/wiki/index.php/App:Library:LVGL:docs:Porting 戻る : Previous]
 
:[https://robot-jp.com/wiki/index.php/App:Library:LVGL:docs:Porting 戻る : Previous]
  
  
 
=== Feedback ===
 
=== Feedback ===
Besides <code>read_cb</code> a <code>feedback_cb</code> callback can be also specified in <code>lv_indev_drv_t</code>. <code>feedback_cb</code> is called when any type of event is sent by the input devices (independently of its type). This allows generating feedback for the user, e.g. to play a sound on <code>LV_EVENT_CLICKED</code>.
+
Besides <code style="color: #bb0000;">read_cb</code> a <code style="color: #bb0000;">feedback_cb</code> callback can be also specified in <code style="color: #bb0000;">lv_indev_drv_t</code>. <code style="color: #bb0000;">feedback_cb</code> is called when any type of event is sent by the input devices (independently of its type). This allows generating feedback for the user, e.g. to play a sound on <code style="color: #bb0000;">LV_EVENT_CLICKED</code>.
 
:[https://robot-jp.com/wiki/index.php/App:Library:LVGL:docs:Porting 戻る : Previous]
 
:[https://robot-jp.com/wiki/index.php/App:Library:LVGL:docs:Porting 戻る : Previous]
  
  
 
=== Associating with a display ===
 
=== Associating with a display ===
Every input device is associated with a display. By default, a new input device is added to the last display created or explicitly selected (using <code>lv_disp_set_default()</code>). The associated display is stored and can be changed in <code>disp</code> field of the driver.
+
Every input device is associated with a display. By default, a new input device is added to the last display created or explicitly selected (using <code style="color: #bb0000;">lv_disp_set_default()</code>). The associated display is stored and can be changed in <code style="color: #bb0000;">disp</code> field of the driver.
 
:[https://robot-jp.com/wiki/index.php/App:Library:LVGL:docs:Porting 戻る : Previous]
 
:[https://robot-jp.com/wiki/index.php/App:Library:LVGL:docs:Porting 戻る : Previous]
  
  
 
=== Buffered reading ===
 
=== Buffered reading ===
By default, LVGL calls <code>read_cb</code> periodically. Because of this intermittent polling there is a chance that some user gestures are missed.
+
By default, LVGL calls <code style="color: #bb0000;">read_cb</code> periodically. Because of this intermittent polling there is a chance that some user gestures are missed.
  
To solve this you can write an event driven driver for your input device that buffers measured data. In <code>read_cb</code> you can report the buffered data instead of directly reading the input device. Setting the <code>data->continue_reading</code> flag will tell LVGL there is more data to read and it should call <code>read_cb</code> again.
+
To solve this you can write an event driven driver for your input device that buffers measured data. In <code style="color: #bb0000;">read_cb</code> you can report the buffered data instead of directly reading the input device. Setting the <code style="color: #bb0000;">data->continue_reading</code> flag will tell LVGL there is more data to read and it should call <code style="color: #bb0000;">read_cb</code> again.
 
:[https://robot-jp.com/wiki/index.php/App:Library:LVGL:docs:Porting 戻る : Previous]
 
:[https://robot-jp.com/wiki/index.php/App:Library:LVGL:docs:Porting 戻る : Previous]
  
281行目: 292行目:
 
: Update the driver in run time.
 
: Update the driver in run time.
 
:; Parameters
 
:; Parameters
::* indev -- pointer to an input device. (return value of <code>lv_indev_drv_register</code>)
+
::* indev -- pointer to an input device. (return value of <code style="color: #bb0000;">lv_indev_drv_register</code>)
 
::* new_drv -- pointer to the new driver
 
::* new_drv -- pointer to the new driver
  
324行目: 335行目:
 
::
 
::
 
:; void (*feedback_cb)(struct _lv_indev_drv_t*, uint8_t)  
 
:; void (*feedback_cb)(struct _lv_indev_drv_t*, uint8_t)  
:: Called when an action happened on the input device. The second parameter is the event from <code>lv_event_t</code>
+
:: Called when an action happened on the input device. The second parameter is the event from <code style="color: #bb0000;">lv_event_t</code>
 
:; void *user_data  
 
:; void *user_data  
 
::
 
::
358行目: 369行目:
 
:; lv_point_t act_point  
 
:; lv_point_t act_point  
 
:: Current point of input device.
 
:: Current point of input device.
:; <span id="_CPPv3N16_lv_indev_proc_t10last_pointE"></span><span id="_CPPv2N16_lv_indev_proc_t10last_pointE"></span><span id="_lv_indev_proc_t::last_point__lv_point_t"></span><span id="struct__lv__indev__proc__t_1a1cdaaba80366c5e69643ce39e9ccfe54" class="target"></span>lv_point_t last_point[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t10last_pointE] <span id="_CPPv3N16_lv_indev_proc_t10last_pointE"></span><span id="_CPPv2N16_lv_indev_proc_t10last_pointE"></span><span id="_lv_indev_proc_t::last_point__lv_point_t"></span><span id="struct__lv__indev__proc__t_1a1cdaaba80366c5e69643ce39e9ccfe54" class="target"></span>
+
:; lv_point_t last_point  
:: Last point of inp[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t10last_pointE]ut device.
+
:: Last point of input device.
:; <span id="_CPPv3N16_lv_indev_proc_t14last_raw_pointE"></span><span id="_CPPv2N16_lv_indev_proc_t14last_raw_pointE"></span><span id="_lv_indev_proc_t::last_raw_point__lv_point_t"></span><span id="struct__lv__indev__proc__t_1a5ef2276c058ae14671e0b2c95fcd0efd" class="target"></span>lv_point_t last_raw_point[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t14last_raw_pointE] <span id="_CPPv3N16_lv_indev_proc_t14last_raw_pointE"></span><span id="_CPPv2N16_lv_indev_proc_t14last_raw_pointE"></span><span id="_lv_indev_proc_t::last_raw_point__lv_point_t"></span><span id="struct__lv__indev__proc__t_1a5ef2276c058ae14671e0b2c95fcd0efd" class="target"></span>
+
:; lv_point_t last_raw_point  
:: Last point read from [https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t14last_raw_pointE]read_cb.
+
:: Last point read from read_cb.
:; <span id="_CPPv3N16_lv_indev_proc_t4vectE"></span><span id="_CPPv2N16_lv_indev_proc_t4vectE"></span><span id="_lv_indev_proc_t::vect__lv_point_t"></span><span id="struct__lv__indev__proc__t_1a311ca773c25e7719b27ec09a36bf17e1" class="target"></span>lv_point_t vect[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t4vectE] <span id="_CPPv3N16_lv_indev_proc_t4vectE"></span><span id="_CPPv2N16_lv_indev_proc_t4vectE"></span><span id="_lv_indev_proc_t::vect__lv_point_t"></span><span id="struct__lv__indev__proc__t_1a311ca773c25e7719b27ec09a36bf17e1" class="target"></span>
+
:; lv_point_t vect  
:: Difference [https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t4vectE]between <code>act_point</code> and <code>last_point</code>.
+
:: Difference between <code style="color: #bb0000;">act_point</code> and <code style="color: #bb0000;">last_point</code>.
:; <span id="_CPPv3N16_lv_indev_proc_t10scroll_sumE"></span><span id="_CPPv2N16_lv_indev_proc_t10scroll_sumE"></span><span id="_lv_indev_proc_t::scroll_sum__lv_point_t"></span><span id="struct__lv__indev__proc__t_1a6dcf864ff00cce45de9ad7da54c25db8" class="target"></span>lv_point_t scroll_sum[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t10scroll_sumE] <span id="_CPPv3N16_lv_indev_proc_t10scroll_sumE"></span><span id="_CPPv2N16_lv_indev_proc_t10scroll_sumE"></span><span id="_lv_indev_proc_t::scroll_sum__lv_point_t"></span><span id="struct__lv__indev__proc__t_1a6dcf864ff00cce45de9ad7da54c25db8" class="target"></span>
+
:; lv_point_t scroll_sum  
 
::
 
::
:; <span id="_CPPv3N16_lv_indev_proc_t17scroll_throw_vectE"></span><span id="_CPPv2N16_lv_indev_proc_t17scroll_throw_vectE"></span><span id="_lv_indev_proc_t::scroll_throw_vect__lv_point_t"></span><span id="struct__lv__indev__proc__t_1a9bb0b055f6a7b857c3d0f77bb652cb97" class="target"></span>lv_point_t [https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t10scroll_sumE]scroll_throw_vect[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t17scroll_throw_vectE] <span id="_CPPv3N16_lv_indev_proc_t17scroll_throw_vectE"></span><span id="_CPPv2N16_lv_indev_proc_t17scroll_throw_vectE"></span><span id="_lv_indev_proc_t::scroll_throw_vect__lv_point_t"></span><span id="struct__lv__indev__proc__t_1a9bb0b055f6a7b857c3d0f77bb652cb97" class="target"></span>
+
:; lv_point_t scroll_throw_vect  
 
::
 
::
:; <span id="_CPPv3N16_lv_indev_proc_t21scroll_throw_vect_oriE"></span><span id="_CPPv2N16_lv_indev_proc_t21scroll_throw_vect_oriE"></span><span id="_lv_indev_proc_t::scroll_throw_vect_ori__lv_point_t"></span><span id="struct__lv__indev__proc__t_1afded21d1887b4ca6c8f14669846c2152" class="target"></span>lv_point_t scroll_[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t17scroll_throw_vectE]throw_vect_ori[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t21scroll_throw_vect_oriE] <span id="_CPPv3N16_lv_indev_proc_t21scroll_throw_vect_oriE"></span><span id="_CPPv2N16_lv_indev_proc_t21scroll_throw_vect_oriE"></span><span id="_lv_indev_proc_t::scroll_throw_vect_ori__lv_point_t"></span><span id="struct__lv__indev__proc__t_1afded21d1887b4ca6c8f14669846c2152" class="target"></span>
+
:; lv_point_t scroll_throw_vect_ori
 
::
 
::
:; <span id="_CPPv3N16_lv_indev_proc_t7act_objE"></span><span id="_CPPv2N16_lv_indev_proc_t7act_objE"></span><span id="_lv_indev_proc_t::act_obj___lv_obj_tP"></span><span id="struct__lv__indev__proc__t_1a418af1d0a3452e6c97d22f6a690c2927" class="target"></span>struct _lv_obj_t *act_[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t21scroll_throw_vect_oriE]obj[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t7act_objE] <span id="_CPPv3N16_lv_indev_proc_t7act_objE"></span><span id="_CPPv2N16_lv_indev_proc_t7act_objE"></span><span id="_lv_indev_proc_t::act_obj___lv_obj_tP"></span><span id="struct__lv__indev__proc__t_1a418af1d0a3452e6c97d22f6a690c2927" class="target"></span>
+
:; struct _lv_obj_t *act_obj
 
::
 
::
:; <span id="_CPPv3N16_lv_indev_proc_t8last_objE"></span><span id="_CPPv2N16_lv_indev_proc_t8last_objE"></span><span id="_lv_indev_proc_t::last_obj___lv_obj_tP"></span><span id="struct__lv__indev__proc__t_1a31f25629da14f973a050f3723b47bb53" class="target"></span>struct _lv_obj_[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t7act_objE]t *last_obj[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t8last_objE] <span id="_CPPv3N16_lv_indev_proc_t8last_objE"></span><span id="_CPPv2N16_lv_indev_proc_t8last_objE"></span><span id="_lv_indev_proc_t::last_obj___lv_obj_tP"></span><span id="struct__lv__indev__proc__t_1a31f25629da14f973a050f3723b47bb53" class="target"></span>
+
:; struct _lv_obj_t *last_obj  
 
::
 
::
:; <span id="_CPPv3N16_lv_indev_proc_t10scroll_objE"></span><span id="_CPPv2N16_lv_indev_proc_t10scroll_objE"></span><span id="_lv_indev_proc_t::scroll_obj___lv_obj_tP"></span><span id="struct__lv__indev__proc__t_1a1a831877520ad18e9c57bb3f2563bd39" class="target"></span>struct _lv_obj_t[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t8last_objE] *scroll_obj[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t10scroll_objE] <span id="_CPPv3N16_lv_indev_proc_t10scroll_objE"></span><span id="_CPPv2N16_lv_indev_proc_t10scroll_objE"></span><span id="_lv_indev_proc_t::scroll_obj___lv_obj_tP"></span><span id="struct__lv__indev__proc__t_1a1a831877520ad18e9c57bb3f2563bd39" class="target"></span>
+
:; struct _lv_obj_t *scroll_obj  
 
::
 
::
:; <span id="_CPPv3N16_lv_indev_proc_t12last_pressedE"></span><span id="_CPPv2N16_lv_indev_proc_t12last_pressedE"></span><span id="_lv_indev_proc_t::last_pressed___lv_obj_tP"></span><span id="struct__lv__indev__proc__t_1a989c1d45df566aef0219fbc90f2ab628" class="target"></span>struct _lv_obj_t *[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t10scroll_objE]last_pressed[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t12last_pressedE] <span id="_CPPv3N16_lv_indev_proc_t12last_pressedE"></span><span id="_CPPv2N16_lv_indev_proc_t12last_pressedE"></span><span id="_lv_indev_proc_t::last_pressed___lv_obj_tP"></span><span id="struct__lv__indev__proc__t_1a989c1d45df566aef0219fbc90f2ab628" class="target"></span>
+
:; struct _lv_obj_t *last_pressed  
 
::
 
::
:; <span id="_CPPv3N16_lv_indev_proc_t11scroll_areaE"></span><span id="_CPPv2N16_lv_indev_proc_t11scroll_areaE"></span><span id="_lv_indev_proc_t::scroll_area__lv_area_t"></span><span id="struct__lv__indev__proc__t_1a3ed7b15fc351350fc9cd3044d36cca11" class="target"></span>lv_area_t scroll_are[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t12last_pressedE]a[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t11scroll_areaE] <span id="_CPPv3N16_lv_indev_proc_t11scroll_areaE"></span><span id="_CPPv2N16_lv_indev_proc_t11scroll_areaE"></span><span id="_lv_indev_proc_t::scroll_area__lv_area_t"></span><span id="struct__lv__indev__proc__t_1a3ed7b15fc351350fc9cd3044d36cca11" class="target"></span>
+
:; lv_area_t scroll_area
 
::
 
::
:; <span id="_CPPv3N16_lv_indev_proc_t11gesture_sumE"></span><span id="_CPPv2N16_lv_indev_proc_t11gesture_sumE"></span><span id="_lv_indev_proc_t::gesture_sum__lv_point_t"></span><span id="struct__lv__indev__proc__t_1ac1a0645fa105c22698920de514f3fb9b" class="target"></span>lv_point_t [https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t11scroll_areaE]gesture_sum[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t11gesture_sumE] <span id="_CPPv3N16_lv_indev_proc_t11gesture_sumE"></span><span id="_CPPv2N16_lv_indev_proc_t11gesture_sumE"></span><span id="_lv_indev_proc_t::gesture_sum__lv_point_t"></span><span id="struct__lv__indev__proc__t_1ac1a0645fa105c22698920de514f3fb9b" class="target"></span>
+
:; lv_point_t gesture_sum  
 
::
 
::
:; <span id="_CPPv3N16_lv_indev_proc_t10scroll_dirE"></span><span id="_CPPv2N16_lv_indev_proc_t10scroll_dirE"></span><span id="_lv_indev_proc_t::scroll_dir__lv_dir_t"></span><span id="struct__lv__indev__proc__t_1acbfc138ec3c3b93a38aae9ea5d48cb23" class="target"></span>lv_dir_t scr[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t11gesture_sumE]oll_dir[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t10scroll_dirE] <span id="_CPPv3N16_lv_indev_proc_t10scroll_dirE"></span><span id="_CPPv2N16_lv_indev_proc_t10scroll_dirE"></span><span id="_lv_indev_proc_t::scroll_dir__lv_dir_t"></span><span id="struct__lv__indev__proc__t_1acbfc138ec3c3b93a38aae9ea5d48cb23" class="target"></span>
+
:; lv_dir_t scroll_dir
 
::
 
::
:; <span id="_CPPv3N16_lv_indev_proc_t11gesture_dirE"></span><span id="_CPPv2N16_lv_indev_proc_t11gesture_dirE"></span><span id="_lv_indev_proc_t::gesture_dir__lv_dir_t"></span><span id="struct__lv__indev__proc__t_1a9511db2f0bed58a7ceca5b338154dfd5" class="target"></span>lv_dir_t [https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t10scroll_dirE]gesture_dir[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t11gesture_dirE] <span id="_CPPv3N16_lv_indev_proc_t11gesture_dirE"></span><span id="_CPPv2N16_lv_indev_proc_t11gesture_dirE"></span><span id="_lv_indev_proc_t::gesture_dir__lv_dir_t"></span><span id="struct__lv__indev__proc__t_1a9511db2f0bed58a7ceca5b338154dfd5" class="target"></span>
+
:; lv_dir_t gesture_dir  
 
::
 
::
:; <span id="_CPPv3N16_lv_indev_proc_t12gesture_sentE"></span><span id="_CPPv2N16_lv_indev_proc_t12gesture_sentE"></span><span id="_lv_indev_proc_t::gesture_sent__uint8_t"></span><span id="struct__lv__indev__proc__t_1a3c3fc31c7153e86968d25218c36aa2d9" class="target"></span>uint8_t ge[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t11gesture_dirE]sture_sent[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t12gesture_sentE] <span id="_CPPv3N16_lv_indev_proc_t12gesture_sentE"></span><span id="_CPPv2N16_lv_indev_proc_t12gesture_sentE"></span><span id="_lv_indev_proc_t::gesture_sent__uint8_t"></span><span id="struct__lv__indev__proc__t_1a3c3fc31c7153e86968d25218c36aa2d9" class="target"></span>
+
:; uint8_t gesture_sent
 
::
 
::
:; <span id="_CPPv3N16_lv_indev_proc_t7pointerE"></span><span id="_CPPv2N16_lv_indev_proc_t7pointerE"></span><span id="struct__lv__indev__proc__t_1aecfe5b95c514f83fd2d4b8217c945ac5" class="target"></span>struct _lv[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t12gesture_sentE]<nowiki>_indev_proc_t::[anonymous]::[anonymous] pointer</nowiki>[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t7pointerE] <span id="_CPPv3N16_lv_indev_proc_t7pointerE"></span><span id="_CPPv2N16_lv_indev_proc_t7pointerE"></span><span id="struct__lv__indev__proc__t_1aecfe5b95c514f83fd2d4b8217c945ac5" class="target"></span>
+
:; struct _lv<nowiki>_indev_proc_t::[anonymous]::[anonymous] pointer</nowiki>  
 
::
 
::
:; <span id="_CPPv3N16_lv_indev_proc_t10last_stateE"></span><span id="_CPPv2N16_lv_indev_proc_t10last_stateE"></span><span id="_lv_indev_proc_t::last_state__lv_indev_state_t"></span><span id="struct__lv__indev__proc__t_1a85c684f0eccad01a4f7cfe4ab4ebab89" class="target"></span>lv_indev_state_t last_state[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t10last_stateE] <span id="_CPPv3N16_lv_indev_proc_t10last_stateE"></span><span id="_CPPv2N16_lv_indev_proc_t10last_stateE"></span><span id="_lv_indev_proc_t::last_state__lv_indev_state_t"></span><span id="struct__lv__indev__proc__t_1a85c684f0eccad01a4f7cfe4ab4ebab89" class="target"></span>
+
:; lv_indev_state_t last_state  
 
::
 
::
:; <span id="_CPPv3N16_lv_indev_proc_t8last_keyE"></span><span id="_CPPv2N16_lv_indev_proc_t8last_keyE"></span><span id="_lv_indev_proc_t::last_key__uint32_t"></span><span id="struct__lv__indev__proc__t_1af5b18f4a595a9a1b74a7665b5e55f42b" class="target"></span>uint32_t[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t7pointerE] last_key[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t10last_stateE][https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t8last_keyE] <span id="_CPPv3N16_lv_indev_proc_t8last_keyE"></span><span id="_CPPv2N16_lv_indev_proc_t8last_keyE"></span><span id="_lv_indev_proc_t::last_key__uint32_t"></span><span id="struct__lv__indev__proc__t_1af5b18f4a595a9a1b74a7665b5e55f42b" class="target"></span>
+
:; uint32_t last_key  
 
::
 
::
:; <span id="_CPPv3N16_lv_indev_proc_t6keypadE"></span><span id="_CPPv2N16_lv_indev_proc_t6keypadE"></span><span id="struct__lv__indev__proc__t_1a1931afc3ec538f32c7278c01cbd5db45" class="target"></span>struct [https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t8last_keyE]<nowiki>_lv_indev_proc_t::[anonymous]::[anonymous] keypad</nowiki>[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t6keypadE] <span id="_CPPv3N16_lv_indev_proc_t6keypadE"></span><span id="_CPPv2N16_lv_indev_proc_t6keypadE"></span><span id="struct__lv__indev__proc__t_1a1931afc3ec538f32c7278c01cbd5db45" class="target"></span>
+
:; struct <nowiki>_lv_indev_proc_t::[anonymous]::[anonymous] keypad</nowiki>  
 
::
 
::
:; <span id="_CPPv3N16_lv_indev_proc_t5typesE"></span><span id="_CPPv2N16_lv_indev_proc_t5typesE"></span><span id="struct__lv__indev__proc__t_1ad3abefa0c3823bebc946a43f4660240c" class="target"></span><nowiki>union _lv_indev_proc_t::[anonymous] types</nowiki>[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t5typesE] <span id="_CPPv3N16_lv_indev_proc_t5typesE"></span><span id="_CPPv2N16_lv_indev_proc_t5typesE"></span><span id="struct__lv__indev__proc__t_1ad3abefa0c3823bebc946a43f4660240c" class="target"></span>
+
:; union _lv_indev_proc_t::[anonymous] types</nowiki>  
:: [https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t6keypadE]
+
::  
:; <span id="_CPPv3N16_lv_indev_proc_t12pr_timestampE"></span><span id="_CPPv2N16_lv_indev_proc_t12pr_timestampE"></span><span id="_lv_indev_proc_t::pr_timestamp__uint32_t"></span><span id="struct__lv__indev__proc__t_1a610fbc71cd450b55c0ad5fdf38dfaf5a" class="target"></span>uint32_t pr_timestamp[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t12pr_timestampE] <span id="_CPPv3N16_lv_indev_proc_t12pr_timestampE"></span><span id="_CPPv2N16_lv_indev_proc_t12pr_timestampE"></span><span id="_lv_indev_proc_t::pr_timestamp__uint32_t"></span><span id="struct__lv__indev__proc__t_1a610fbc71cd450b55c0ad5fdf38dfaf5a" class="target"></span>
+
:; uint32_t pr_timestamp  
:: Pres[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t5typesE]sed time stam[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t12pr_timestampE]p
+
:: Pressed time stamp
:; <span id="_CPPv3N16_lv_indev_proc_t20longpr_rep_timestampE"></span><span id="_CPPv2N16_lv_indev_proc_t20longpr_rep_timestampE"></span><span id="_lv_indev_proc_t::longpr_rep_timestamp__uint32_t"></span><span id="struct__lv__indev__proc__t_1a943cbd9cf549902dc4cfae4fbcea181f" class="target"></span>uint32_t longpr_rep_timestamp[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t20longpr_rep_timestampE] <span id="_CPPv3N16_lv_indev_proc_t20longpr_rep_timestampE"></span><span id="_CPPv2N16_lv_indev_proc_t20longpr_rep_timestampE"></span><span id="_lv_indev_proc_t::longpr_rep_timestamp__uint32_t"></span><span id="struct__lv__indev__proc__t_1a943cbd9cf549902dc4cfae4fbcea181f" class="target"></span>
+
:; uint32_t longpr_rep_timestamp  
:: Long press repeat time st[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N16_lv_indev_proc_t20longpr_rep_timestampE]amp
+
:: Long press repeat time stamp
  
; <span id="_CPPv311_lv_indev_t"></span><span id="_CPPv211_lv_indev_t"></span><span id="_lv_indev_t"></span><span id="struct__lv__indev__t" class="target"></span>struct _lv_indev_t[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv411_lv_indev_t] <span id="_CPPv311_lv_indev_t"></span><span id="_CPPv211_lv_indev_t"></span><span id="_lv_indev_t"></span><span id="struct__lv__indev__t" class="target"></span>
+
; struct _lv_indev_t  
: ''#include <lv_h''[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv411_lv_indev_t]''al_indev.h>'' The main input device descriptor with driver, runtime data ('proc') and some additional information  Public Members
+
: ''#include <lv_h''''al_indev.h>'' The main input device descriptor with driver, runtime data ('proc') and some additional information  Public Members
:; <span id="_CPPv3N11_lv_indev_t6driverE"></span><span id="_CPPv2N11_lv_indev_t6driverE"></span><span id="_lv_indev_t::driver___lv_indev_drv_tP"></span><span id="struct__lv__indev__t_1a5aed39e0d1027712f3894e1ba5e89d7a" class="target"></span>struct _lv_indev_drv_t *driver[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N11_lv_indev_t6driverE] <span id="_CPPv3N11_lv_indev_t6driverE"></span><span id="_CPPv2N11_lv_indev_t6driverE"></span><span id="_lv_indev_t::driver___lv_indev_drv_tP"></span><span id="struct__lv__indev__t_1a5aed39e0d1027712f3894e1ba5e89d7a" class="target"></span>
+
:; struct _lv_indev_drv_t *driver  
 
::
 
::
:; <span id="_CPPv3N11_lv_indev_t4procE"></span><span id="_CPPv2N11_lv_indev_t4procE"></span><span id="_lv_indev_t::proc___lv_indev_proc_t"></span><span id="struct__lv__indev__t_1a532e74e74e6a183ee3e0fde02c9b2beb" class="target"></span>_lv_indev_proc_t pro[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N11_lv_indev_t6driverE]c[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N11_lv_indev_t4procE] <span id="_CPPv3N11_lv_indev_t4procE"></span><span id="_CPPv2N11_lv_indev_t4procE"></span><span id="_lv_indev_t::proc___lv_indev_proc_t"></span><span id="struct__lv__indev__t_1a532e74e74e6a183ee3e0fde02c9b2beb" class="target"></span>
+
:; _lv_indev_proc_t proc
 
::
 
::
:; <span id="_CPPv3N11_lv_indev_t6cursorE"></span><span id="_CPPv2N11_lv_indev_t6cursorE"></span><span id="_lv_indev_t::cursor___lv_obj_tP"></span><span id="struct__lv__indev__t_1afca94f9275c3ca669979477d56fd884d" class="target"></span>struct _lv_[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N11_lv_indev_t4procE]obj_t *cursor[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N11_lv_indev_t6cursorE] <span id="_CPPv3N11_lv_indev_t6cursorE"></span><span id="_CPPv2N11_lv_indev_t6cursorE"></span><span id="_lv_indev_t::cursor___lv_obj_tP"></span><span id="struct__lv__indev__t_1afca94f9275c3ca669979477d56fd884d" class="target"></span>
+
:; struct _lv_obj_t *cursor  
:: Cursor for LV_INPUT_[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N11_lv_indev_t6cursorE]TYPE_POINTER
+
:: Cursor for LV_INPUT_TYPE_POINTER
:; <span id="_CPPv3N11_lv_indev_t5groupE"></span><span id="_CPPv2N11_lv_indev_t5groupE"></span><span id="_lv_indev_t::group___lv_group_tP"></span><span id="struct__lv__indev__t_1abe81eefe10ba7f66ff9ffe3a48db3a31" class="target"></span>struct _lv_group_t *group[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N11_lv_indev_t5groupE] <span id="_CPPv3N11_lv_indev_t5groupE"></span><span id="_CPPv2N11_lv_indev_t5groupE"></span><span id="_lv_indev_t::group___lv_group_tP"></span><span id="struct__lv__indev__t_1abe81eefe10ba7f66ff9ffe3a48db3a31" class="target"></span>
+
:; struct _lv_group_t *group  
:: Keypad destination gr[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N11_lv_indev_t5groupE]oup
+
:: Keypad destination group
:; <span id="_CPPv3N11_lv_indev_t10btn_pointsE"></span><span id="_CPPv2N11_lv_indev_t10btn_pointsE"></span><span id="_lv_indev_t::btn_points__lv_point_tCP"></span><span id="struct__lv__indev__t_1aa7c40dc6d671c802427db39a7181237b" class="target"></span>const lv_point_t *btn_points[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N11_lv_indev_t10btn_pointsE] <span id="_CPPv3N11_lv_indev_t10btn_pointsE"></span><span id="_CPPv2N11_lv_indev_t10btn_pointsE"></span><span id="_lv_indev_t::btn_points__lv_point_tCP"></span><span id="struct__lv__indev__t_1aa7c40dc6d671c802427db39a7181237b" class="target"></span>
+
:; const lv_point_t *btn_points  
:: Array points assigned to[https://docs.lvgl.io/8.2/porting/indev.html#_CPPv4N11_lv_indev_t10btn_pointsE] the button ()screen will be pressed here by the buttons
+
:: Array points assigned to the button ()screen will be pressed here by the buttons
  
 
:[https://robot-jp.com/wiki/index.php/App:Library:LVGL:docs:Porting 戻る : Previous]
 
:[https://robot-jp.com/wiki/index.php/App:Library:LVGL:docs:Porting 戻る : Previous]

2022年6月22日 (水) 13:12時点における版

https://docs.lvgl.io/8.2/porting/indev.html

英文 自動翻訳


Input device interface

Types of input devices

To register an input device an lv_indev_drv_t variable has to be initialized. Be sure to register at least one display before you register any input devices.

 lv_disp_drv_register(&disp_drv);
 
 static lv_indev_drv_t indev_drv;
 lv_indev_drv_init(&indev_drv);      /*Basic initialization*/
 indev_drv.type =...                 /*See below.*/
 indev_drv.read_cb =...              /*See below.*/
 /*Register the driver in LVGL and save the created input device object*/
 lv_indev_t * my_indev = lv_indev_drv_register(&indev_drv);

The type member can be:

  • LV_INDEV_TYPE_POINTER touchpad or mouse
  • LV_INDEV_TYPE_KEYPAD keyboard or keypad
  • LV_INDEV_TYPE_ENCODER encoder with left/right turn and push options
  • LV_INDEV_TYPE_BUTTON external buttons virtually pressing the screen

read_cb is a function pointer which will be called periodically to report the current state of an input device.

Visit Input devices to learn more about input devices in general.

戻る : Previous


Touchpad, mouse or any pointer

Input devices that can click points on the screen belong to this category.

 indev_drv.type = LV_INDEV_TYPE_POINTER;
 indev_drv.read_cb = my_input_read;
 
 ...
 
 void my_input_read(lv_indev_drv_t * drv, lv_indev_data_t*data)
 {
   if(touchpad_pressed) {
     data->point.x = touchpad_x;
     data->point.y = touchpad_y;
     data->state = LV_INDEV_STATE_PRESSED;
   } else {
     data->state = LV_INDEV_STATE_RELEASED; 
   }
 }

To set a mouse cursor use lv_indev_set_cursor(my_indev, &img_cursor). (my_indev is the return value of lv_indev_drv_register)

戻る : Previous


Keypad or keyboard

Full keyboards with all the letters or simple keypads with a few navigation buttons belong here.

To use a keyboard/keypad:

  • Register a read_cb function with LV_INDEV_TYPE_KEYPAD type.
  • An object group has to be created: lv_group_t * g = lv_group_create() and objects have to be added to it with lv_group_add_obj(g, obj)
  • The created group has to be assigned to an input device: lv_indev_set_group(my_indev, g) (my_indev is the return value of lv_indev_drv_register)
  • Use LV_KEY_... to navigate among the objects in the group. See lv_core/lv_group.h for the available keys.
 indev_drv.type = LV_INDEV_TYPE_KEYPAD;
 indev_drv.read_cb = keyboard_read;
 
 ...
 
 void keyboard_read(lv_indev_drv_t * drv, lv_indev_data_t*data){
   data->key = last_key();            /*Get the last pressed or released key*/
 
   if(key_pressed()) data->state = LV_INDEV_STATE_PRESSED;
   else data->state = LV_INDEV_STATE_RELEASED;
 }
戻る : Previous


Encoder

With an encoder you can do the following:

  1. Press its button
  2. Long-press its button
  3. Turn left
  4. Turn right

In short, the Encoder input devices work like this:

  • By turning the encoder you can focus on the next/previous object.
  • When you press the encoder on a simple object (like a button), it will be clicked.
  • If you press the encoder on a complex object (like a list, message box, etc.) the object will go to edit mode whereby you can navigate inside the object by turning the encoder.
  • To leave edit mode, long press the button.

To use an Encoder (similarly to the Keypads) the objects should be added to groups.

 indev_drv.type = LV_INDEV_TYPE_ENCODER;
 indev_drv.read_cb = encoder_read;
 
 ...
 
 void encoder_read(lv_indev_drv_t * drv, lv_indev_data_t*data){
   data->enc_diff = enc_get_new_moves();
 
   if(enc_pressed()) data->state = LV_INDEV_STATE_PRESSED;
   else data->state = LV_INDEV_STATE_RELEASED;
 }
戻る : Previous


Using buttons with Encoder logic

In addition to standard encoder behavior, you can also utilize its logic to navigate(focus) and edit widgets using buttons. This is especially handy if you have only few buttons available, or you want to use other buttons in addition to encoder wheel.

You need to have 3 buttons available:

  • LV_KEY_ENTER will simulate press or pushing of the encoder button
  • LV_KEY_LEFT will simulate turning encoder left
  • LV_KEY_RIGHT will simulate turning encoder right
  • other keys will be passed to the focused widget

If you hold the keys it will simulate an encoder advance with period specified in indev_drv.long_press_rep_time.

 indev_drv.type = LV_INDEV_TYPE_ENCODER;
 indev_drv.read_cb = encoder_with_keys_read;
 
 ...
 
 void encoder_with_keys_read(lv_indev_drv_t * drv, lv_indev_data_t*data){
   data->key = last_key();            /*Get the last pressed or released key*/
                                      /* use LV_KEY_ENTER for encoder press */
   if(key_pressed()) data->state = LV_INDEV_STATE_PRESSED;
   else {
       data->state = LV_INDEV_STATE_RELEASED;
       /* Optionally you can also use enc_diff, if you have encoder*/
       data->enc_diff = enc_get_new_moves();
   }
 }
戻る : Previous


Button

Buttons mean external "hardware" buttons next to the screen which are assigned to specific coordinates of the screen. If a button is pressed it will simulate the pressing on the assigned coordinate. (Similarly to a touchpad)

To assign buttons to coordinates use lv_indev_set_button_points(my_indev, points_array).

points_array should look like const lv_point_t points_array[] = { {12,30},{60,90}, ...}

Important

The points_array can't go out of scope. Either declare it as a global variable or as a static variable inside a function.

 indev_drv.type = LV_INDEV_TYPE_BUTTON;
 indev_drv.read_cb = button_read;
 
 ...
 
 void button_read(lv_indev_drv_t * drv, lv_indev_data_t*data){
     static uint32_t last_btn = 0;   /*Store the last pressed button*/
     int btn_pr = my_btn_read();     /*Get the ID (0,1,2...) of the pressed button*/
     if(btn_pr >= 0) {               /*Is there a button press? (E.g. -1 indicated no button was pressed)*/
        last_btn = btn_pr;           /*Save the ID of the pressed button*/
        data->state = LV_INDEV_STATE_PRESSED;  /*Set the pressed state*/
     } else {
        data->state = LV_INDEV_STATE_RELEASED; /*Set the released state*/
     }
 
     data->btn = last_btn;            /*Save the last button*/
 }
戻る : Previous


Other features

Parameters

The default value of the following parameters can be changed in lv_indev_drv_t:

  • scroll_limit Number of pixels to slide before actually scrolling the object.
  • scroll_throw Scroll throw (momentum) slow-down in [%]. Greater value means faster slow-down.
  • long_press_time Press time to send LV_EVENT_LONG_PRESSED (in milliseconds)
  • long_press_rep_time Interval of sending LV_EVENT_LONG_PRESSED_REPEAT (in milliseconds)
  • read_timer pointer to the lv_timer which reads the input device. Its parameters can be changed by lv_timer_...() functions. LV_INDEV_DEF_READ_PERIOD in lv_conf.h sets the default read period.
戻る : Previous


Feedback

Besides read_cb a feedback_cb callback can be also specified in lv_indev_drv_t. feedback_cb is called when any type of event is sent by the input devices (independently of its type). This allows generating feedback for the user, e.g. to play a sound on LV_EVENT_CLICKED.

戻る : Previous


Associating with a display

Every input device is associated with a display. By default, a new input device is added to the last display created or explicitly selected (using lv_disp_set_default()). The associated display is stored and can be changed in disp field of the driver.

戻る : Previous


Buffered reading

By default, LVGL calls read_cb periodically. Because of this intermittent polling there is a chance that some user gestures are missed.

To solve this you can write an event driven driver for your input device that buffers measured data. In read_cb you can report the buffered data instead of directly reading the input device. Setting the data->continue_reading flag will tell LVGL there is more data to read and it should call read_cb again.

戻る : Previous


Further reading

  • lv_port_indev_template.c for a template for your own driver.
  • INdev features to learn more about higher level input device features.
戻る : Previous


API

@description Input Device HAL interface layer header file

Typedefs

typedef struct _lv_indev_drv_t lv_indev_drv_t
Initialized by the user and registered by 'lv_indev_add()'
typedef struct _lv_indev_proc_t _lv_indev_proc_t
Run time data of input devices Internally used by the library, you should not need to touch it.
typedef struct _lv_indev_t lv_indev_t
The main input device descriptor with driver, runtime data ('proc') and some additional information

Enums

enum lv_indev_type_t
Possible input device types Values:
enumerator LV_INDEV_TYPE_NONE
Uninitialized state
enumerator LV_INDEV_TYPE_POINTER
Touch pad, mouse, external button
enumerator LV_INDEV_TYPE_KEYPAD
Keypad or keyboard
enumerator LV_INDEV_TYPE_BUTTON
External (hardware button) which is assigned to a specific point of the screen
enumerator LV_INDEV_TYPE_ENCODER
Encoder with only Left, Right turn and a Button
enum lv_indev_state_t
States for input devices Values:
enumerator LV_INDEV_STATE_RELEASED
enumerator LV_INDEV_STATE_PRESSED

Functions

void lv_indev_drv_init(struct _lv_indev_drv_t *driver)
Initialize an input device driver with default values. It is used to surely have known values in the fields and not memory junk. After it you can set the fields.
Parameters
driver -- pointer to driver variable to initialize
lv_indev_t *lv_indev_drv_register(struct _lv_indev_drv_t *driver)
Register an initialized input device driver.
Parameters
driver -- pointer to an initialized 'lv_indev_drv_t' variable (can be local variable)
Returns
pointer to the new input device or NULL on error
void lv_indev_drv_update(lv_indev_t *indev, struct _lv_indev_drv_t *new_drv)
Update the driver in run time.
Parameters
  • indev -- pointer to an input device. (return value of lv_indev_drv_register)
  • new_drv -- pointer to the new driver
void lv_indev_delete(lv_indev_t *indev)
Remove the provided input device. Make sure not to use the provided input device afterwards anymore.
Parameters
indev -- pointer to delete
lv_indev_t *lv_indev_get_next(lv_indev_t *indev)
Get the next input device.
Parameters
indev -- pointer to the current input device. NULL to initialize.
Returns
the next input device or NULL if there are no more. Provide the first input device when the parameter is NULL
void _lv_indev_read(lv_indev_t *indev, lv_indev_data_t *data)
Read data from an input device.
Parameters
  • indev -- pointer to an input device
  • data -- input device will write its data here
struct lv_indev_data_t
#include <lv_hal_i'ndev.h> Data structure passed to an input driver to fill Public Members
lv_point_t point
For LV_INDEV_TYPE_POINTER the currently pressed point
uint32_t key
For LV_INDEV_TYPE_KEYPAD the currently pressed key
uint32_t btn_id
For LV_INDEV_TYPE_BUTTON the currently pressed button
int16_t enc_diff
For LV_INDEV_TYPE_ENCODER number of steps since the previous read
lv_indev_state_t state
LV_INDEV_STATE_REL or LV_INDEV_STATE_PR
bool continue_reading
If set to true, the read callback is invoked again
struct _lv_indev_drv_t
#include <lv_hal_i'ndev.h> Initialized by the user and registered by 'lv_indev_add()' Public Members
lv_indev_type_t type
< Input device type Function pointer to read input device data.
void (*read_cb)(struct _lv_indev_drv_t *indev_drv, lv_indev_data_t *data)
void (*feedback_cb)(struct _lv_indev_drv_t*, uint8_t)
Called when an action happened on the input device. The second parameter is the event from lv_event_t
void *user_data
struct _lv_disp_t *disp
< Pointer to the assigned display Timer to periodically read the input device
lv_timer_t *read_timer
Number of pixels to slide before actually drag the object
uint8_t scroll_limit
Drag throw slow-down in [%]. Greater value means faster slow-down
uint8_t scroll_throw
At least this difference should be between two points to evaluate as gesture
uint8_t gesture_min_velocity
At least this difference should be to send a gesture
uint8_t gesture_limit
Long press time in milliseconds
uint16_t long_press_time
Repeated trigger period in long press [ms]
uint16_t long_press_repeat_time
struct _lv_indev_proc_t
#include <lv_hal_indev.h> Run time data of input devices Internally used by the library, you should not need to touch it. Public Members
lv_indev_state_t state
Current state of the input device.
uint8_t long_pr_sent
uint8_t reset_query
uint8_t disabled
uint8_t wait_until_release
lv_point_t act_point
Current point of input device.
lv_point_t last_point
Last point of input device.
lv_point_t last_raw_point
Last point read from read_cb.
lv_point_t vect
Difference between act_point and last_point.
lv_point_t scroll_sum
lv_point_t scroll_throw_vect
lv_point_t scroll_throw_vect_ori
struct _lv_obj_t *act_obj
struct _lv_obj_t *last_obj
struct _lv_obj_t *scroll_obj
struct _lv_obj_t *last_pressed
lv_area_t scroll_area
lv_point_t gesture_sum
lv_dir_t scroll_dir
lv_dir_t gesture_dir
uint8_t gesture_sent
struct _lv_indev_proc_t::[anonymous]::[anonymous] pointer
lv_indev_state_t last_state
uint32_t last_key
struct _lv_indev_proc_t::[anonymous]::[anonymous] keypad
union _lv_indev_proc_t
:[anonymous] types</nowiki>
uint32_t pr_timestamp
Pressed time stamp
uint32_t longpr_rep_timestamp
Long press repeat time stamp
struct _lv_indev_t
#include <lv_h'al_indev.h> The main input device descriptor with driver, runtime data ('proc') and some additional information Public Members
struct _lv_indev_drv_t *driver
_lv_indev_proc_t proc
struct _lv_obj_t *cursor
Cursor for LV_INPUT_TYPE_POINTER
struct _lv_group_t *group
Keypad destination group
const lv_point_t *btn_points
Array points assigned to the button ()screen will be pressed here by the buttons
戻る : Previous