acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

lv_test_indev.c (2517B)

      1 #if LV_BUILD_TEST
      2 #include "../lvgl.h"
      3 #include <stdio.h>
      4 #include <stdlib.h>
      5 
      6 #include <sys/time.h>
      7 #include "lv_test_indev.h"
      8 #include "lv_test_init.h"
      9 
     10 static lv_coord_t x_act;
     11 static lv_coord_t y_act;
     12 static uint32_t key_act;
     13 static int32_t diff_act;
     14 static bool mouse_pressed;
     15 static bool key_pressed;
     16 static bool enc_pressed;
     17 
     18 void lv_test_mouse_read_cb(lv_indev_drv_t * drv, lv_indev_data_t * data)
     19 {
     20   LV_UNUSED(drv);
     21   data->point.x = x_act;
     22   data->point.y = y_act;
     23   data->state = mouse_pressed ? LV_INDEV_STATE_PRESSED : LV_INDEV_STATE_RELEASED;
     24 }
     25 
     26 void lv_test_mouse_move_to(lv_coord_t x, lv_coord_t y)
     27 {
     28   x_act = x;
     29   y_act = y;
     30 }
     31 
     32 void lv_test_mouse_move_by(lv_coord_t x, lv_coord_t y)
     33 {
     34   x_act += x;
     35   y_act += y;
     36 }
     37 
     38 void lv_test_mouse_press(void)
     39 {
     40   mouse_pressed = true;
     41 }
     42 
     43 void lv_test_mouse_release(void)
     44 {
     45   mouse_pressed = false;
     46 }
     47 
     48 void lv_test_mouse_click_at(lv_coord_t x, lv_coord_t y)
     49 {
     50   lv_test_mouse_release();
     51   lv_test_indev_wait(50);
     52   lv_test_mouse_move_to(x, y);
     53   lv_test_mouse_press();
     54   lv_test_indev_wait(50);
     55   lv_test_mouse_release();
     56   lv_test_indev_wait(50);
     57 }
     58 
     59 
     60 void lv_test_keypad_read_cb(lv_indev_drv_t * drv, lv_indev_data_t * data)
     61 {
     62   LV_UNUSED(drv);
     63   data->key = key_act;
     64   data->state = key_pressed ? LV_INDEV_STATE_PRESSED : LV_INDEV_STATE_RELEASED;
     65 }
     66 
     67 void lv_test_key_press(uint32_t k)
     68 {
     69   key_act = k;
     70   key_pressed = true;
     71 }
     72 
     73 void lv_test_key_release(void)
     74 {
     75   key_pressed = false;
     76 }
     77 
     78 void lv_test_key_hit(uint32_t k)
     79 {
     80   lv_test_key_release();
     81   lv_test_indev_wait(50);
     82   lv_test_key_press(k);
     83   lv_test_mouse_press();
     84   lv_test_indev_wait(50);
     85   lv_test_key_release();
     86   lv_test_indev_wait(50);
     87 }
     88 
     89 void lv_test_encoder_read_cb(lv_indev_drv_t * drv, lv_indev_data_t * data)
     90 {
     91   LV_UNUSED(drv);
     92   data->enc_diff = diff_act;
     93   data->state = enc_pressed ? LV_INDEV_STATE_PRESSED : LV_INDEV_STATE_RELEASED;
     94   diff_act = 0;
     95 }
     96 
     97 void lv_test_encoder_add_diff(int32_t d)
     98 {
     99   diff_act += d;
    100 }
    101 
    102 void lv_test_encoder_turn(int32_t d)
    103 {
    104   diff_act += d;
    105   lv_test_indev_wait(50);
    106 }
    107 
    108 
    109 void lv_test_encoder_press(void)
    110 {
    111   enc_pressed = true;
    112 }
    113 
    114 void lv_test_encoder_release(void)
    115 {
    116   enc_pressed = false;
    117 }
    118 
    119 void lv_test_encoder_click(void)
    120 {
    121   lv_test_encoder_release();
    122   lv_test_indev_wait(50);
    123   lv_test_encoder_press();
    124   lv_test_indev_wait(50);
    125   lv_test_encoder_release();
    126   lv_test_indev_wait(50);
    127 }
    128 
    129 
    130 void lv_test_indev_wait(uint32_t ms)
    131 {
    132   uint32_t t = lv_tick_get();
    133   while(lv_tick_elaps(t) < ms) {
    134     lv_timer_handler();
    135     lv_tick_inc(1);
    136   }
    137 }
    138 
    139 
    140 #endif