This is an automated email from the ASF dual-hosted git repository.

rymek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 9ac0d86ed0bcbae99e788d58253ed67b9f595cb1
Author: Jerzy Kasenberg <[email protected]>
AuthorDate: Tue Jun 6 14:21:25 2023 +0200

    lvgl/trackball: Add cursor image
    
    As temporary solution character from font was used as cursor
    image.
    Now there is normal triangle shaped cursor.
    Additionally cursor will change to drag cursor when button
    (track ball) is held for specific number of ms.
    
    Signed-off-by: Jerzy Kasenberg <[email protected]>
---
 .../display/lvgl/indev/trackball/src/trackball.c   | 129 ++++++++++++++++++++-
 1 file changed, 126 insertions(+), 3 deletions(-)

diff --git a/hw/drivers/display/lvgl/indev/trackball/src/trackball.c 
b/hw/drivers/display/lvgl/indev/trackball/src/trackball.c
index f1a2eec93..9a98366bc 100644
--- a/hw/drivers/display/lvgl/indev/trackball/src/trackball.c
+++ b/hw/drivers/display/lvgl/indev/trackball/src/trackball.c
@@ -158,6 +158,116 @@ trackball_button(void *arg)
     }
 }
 
+#ifndef LV_ATTRIBUTE_MEM_ALIGN
+#define LV_ATTRIBUTE_MEM_ALIGN
+#endif
+
+#ifndef LV_ATTRIBUTE_IMG_CURSOR
+#define LV_ATTRIBUTE_IMG_CURSOR
+#endif
+
+static const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST uint8_t 
cursor_normal_map[] = {
+    0x00, 0x00, 0x00, 0x00,     /*Color of index 0*/
+    0xff, 0xff, 0xff, 0xff,     /*Color of index 1*/
+    0x00, 0x00, 0x00, 0xff,     /*Color of index 2*/
+    0x00, 0x00, 0x00, 0x00,     /*Color of index 3*/
+    0x00, 0x00, 0x00, 0x00,     /*Color of index 4*/
+    0x00, 0x00, 0x00, 0x00,     /*Color of index 5*/
+    0x00, 0x00, 0x00, 0x00,     /*Color of index 6*/
+    0x00, 0x00, 0x00, 0x00,     /*Color of index 7*/
+    0x00, 0x00, 0x00, 0x00,     /*Color of index 8*/
+    0x00, 0x00, 0x00, 0x00,     /*Color of index 9*/
+    0x00, 0x00, 0x00, 0x00,     /*Color of index 10*/
+    0x00, 0x00, 0x00, 0x00,     /*Color of index 11*/
+    0x00, 0x00, 0x00, 0x00,     /*Color of index 12*/
+    0x00, 0x00, 0x00, 0x00,     /*Color of index 13*/
+    0x00, 0x00, 0x00, 0x00,     /*Color of index 14*/
+    0x00, 0x00, 0x00, 0x00,     /*Color of index 15*/
+
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x02, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x02, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00,
+    0x02, 0x11, 0x12, 0x00, 0x00, 0x00, 0x00,
+    0x02, 0x11, 0x11, 0x20, 0x00, 0x00, 0x00,
+    0x02, 0x11, 0x11, 0x12, 0x00, 0x00, 0x00,
+    0x02, 0x11, 0x11, 0x11, 0x20, 0x00, 0x00,
+    0x02, 0x11, 0x11, 0x11, 0x12, 0x00, 0x00,
+    0x02, 0x11, 0x11, 0x11, 0x11, 0x20, 0x00,
+    0x02, 0x11, 0x11, 0x11, 0x11, 0x22, 0x00,
+    0x02, 0x11, 0x11, 0x11, 0x22, 0x00, 0x00,
+    0x02, 0x11, 0x12, 0x22, 0x00, 0x00, 0x00,
+    0x02, 0x12, 0x20, 0x00, 0x00, 0x00, 0x00,
+    0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+};
+
+static const lv_img_dsc_t cursor_normal_img_dsc = {
+    .header.cf = LV_IMG_CF_INDEXED_4BIT,
+    .header.always_zero = 0,
+    .header.reserved = 0,
+    .header.w = 13,
+    .header.h = 17,
+    .data_size = 183,
+    .data = cursor_normal_map,
+};
+
+
+static const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST uint8_t 
cursor_drag_map[] = {
+    0x00, 0x00, 0x00, 0x00,     /*Color of index 0*/
+    0xff, 0xff, 0x00, 0x01,     /*Color of index 1*/
+    0x80, 0x80, 0x15, 0x04,     /*Color of index 2*/
+    0x9d, 0x9d, 0x34, 0x06,     /*Color of index 3*/
+    0xb8, 0xb8, 0x45, 0x12,     /*Color of index 4*/
+    0x83, 0x83, 0x30, 0x1a,     /*Color of index 5*/
+    0xb8, 0xb8, 0x44, 0x3a,     /*Color of index 6*/
+    0x81, 0x82, 0x30, 0x4b,     /*Color of index 7*/
+    0xb7, 0xb7, 0x44, 0x79,     /*Color of index 8*/
+    0xb7, 0xb7, 0x43, 0x91,     /*Color of index 9*/
+    0x81, 0x82, 0x30, 0x69,     /*Color of index 10*/
+    0xb8, 0xb8, 0x43, 0xae,     /*Color of index 11*/
+    0x80, 0x81, 0x2f, 0x85,     /*Color of index 12*/
+    0xb8, 0xb8, 0x43, 0xe8,     /*Color of index 13*/
+    0x81, 0x81, 0x30, 0xc8,     /*Color of index 14*/
+    0x81, 0x82, 0x30, 0xed,     /*Color of index 15*/
+
+    0x00, 0x00, 0x5c, 0xe7, 0x07, 0xec, 0x50, 0x00, 0x00,
+    0x00, 0x2a, 0xfe, 0xa5, 0x05, 0xae, 0xfa, 0x10, 0x00,
+    0x01, 0xcf, 0x73, 0x69, 0x99, 0x63, 0x7f, 0xc0, 0x00,
+    0x0a, 0xf5, 0x6d, 0xdb, 0x9b, 0xdd, 0x47, 0xfa, 0x00,
+    0x5f, 0x76, 0xd9, 0x41, 0x01, 0x49, 0xd4, 0xaf, 0x50,
+    0xae, 0x3b, 0xb4, 0x96, 0x06, 0x94, 0xbb, 0x5e, 0xa0,
+    0xec, 0x6d, 0x49, 0xd4, 0x04, 0xd8, 0x4d, 0x6c, 0xe0,
+    0xf7, 0x8b, 0x4d, 0x60, 0x00, 0x6d, 0x4b, 0x87, 0xe0,
+    0xf5, 0x99, 0x6d, 0x40, 0x00, 0x4d, 0x4b, 0x87, 0xf0,
+    0xf7, 0x8b, 0x4d, 0x60, 0x00, 0x6d, 0x4b, 0x87, 0xf0,
+    0xea, 0x6d, 0x49, 0xd6, 0x46, 0xd9, 0x4d, 0x6a, 0xe0,
+    0xae, 0x3d, 0x94, 0x9d, 0xdd, 0x94, 0xbb, 0x5e, 0xa0,
+    0x5f, 0xa4, 0xd9, 0x44, 0x64, 0x49, 0xd4, 0xaf, 0x50,
+    0x0a, 0xf7, 0x6d, 0xdb, 0x9b, 0xdd, 0x47, 0xf7, 0x00,
+    0x01, 0xcf, 0x73, 0x69, 0x99, 0x64, 0x7f, 0xc0, 0x00,
+    0x00, 0x2a, 0xfe, 0xa5, 0x05, 0xae, 0xfa, 0x10, 0x00,
+    0x00, 0x00, 0x5c, 0xe7, 0x07, 0xec, 0x50, 0x00, 0x00,
+};
+
+const lv_img_dsc_t cursor_drag_img_dsc = {
+    .header.cf = LV_IMG_CF_INDEXED_4BIT,
+    .header.always_zero = 0,
+    .header.reserved = 0,
+    .header.w = 17,
+    .header.h = 17,
+    .data_size = 217,
+    .data = cursor_drag_map,
+};
+
+static lv_style_t style_normal;
+static lv_style_t style_pressed;
+
+static lv_obj_t *mouse_cursor;
+static lv_obj_t *drag_cursor;
+static bool drag_cursor_set;
+
 /**
  * Get the current position and state of the touchpad
  * @param data store the read data here
@@ -170,7 +280,12 @@ trackball_read(lv_indev_drv_t *indev_drv, lv_indev_data_t 
*data)
     if (trackball_data.state == PRESSED_WAITING_FOR_HOLD) {
         if ((now - trackball_data.press_time) > HOLD_TIME) {
             trackball_data.state = PRESS_HELD;
+            lv_img_set_src(mouse_cursor, &cursor_drag_img_dsc);
+            drag_cursor_set = true;
         }
+    } else if (trackball_data.state == RELEASED && drag_cursor_set) {
+        lv_img_set_src(mouse_cursor, &cursor_normal_img_dsc);
+        drag_cursor_set = false;
     }
     if (DRAG_PIN >= 0) {
         hal_gpio_write(LED_1, trackball_data.state == PRESS_HELD ? 
DRAG_PIN_VALUE : !DRAG_PIN_VALUE);
@@ -216,8 +331,16 @@ trackball_register_lv_indev(void)
     trackball_drv.read_cb = trackball_read;
     trackball_dev = lv_indev_drv_register(&trackball_drv);
 
-    /*Set cursor. For simplicity set a HOME symbol now.*/
-    lv_obj_t *mouse_cursor = lv_img_create(lv_scr_act());
-    lv_img_set_src(mouse_cursor, LV_SYMBOL_BLUETOOTH);
+    lv_style_init(&style_normal);
+    lv_style_set_translate_x(&style_normal, 0);
+    lv_style_init(&style_pressed);
+    lv_style_set_translate_x(&style_pressed, -10);
+    lv_style_set_translate_y(&style_pressed, -10);
+    mouse_cursor = lv_img_create(lv_scr_act());
+    drag_cursor = lv_img_create(lv_scr_act());
+    lv_img_set_src(mouse_cursor, &cursor_normal_img_dsc);
+    lv_img_set_src(drag_cursor, &cursor_drag_img_dsc);
+    lv_obj_add_style(mouse_cursor, &style_normal, LV_STATE_DEFAULT);
+    lv_obj_add_style(drag_cursor, &style_pressed, LV_STATE_DEFAULT);
     lv_indev_set_cursor(trackball_dev, mouse_cursor);
 }

Reply via email to