mirror of
https://github.com/lvgl/lvgl.git
synced 2026-05-30 15:17:33 +08:00
feat(indev) change the prototype of indev read_cb
Instead of returning bool to indicate that there is more data to read set data->continue_reading = true. It's less error porne because if the user doesn't set the flag the indev will be read once which is usually the inteded behaviour.
This commit is contained in:
@@ -24,17 +24,17 @@
|
||||
**********************/
|
||||
|
||||
static void touchpad_init(void);
|
||||
static bool touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
||||
static void touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
||||
static bool touchpad_is_pressed(void);
|
||||
static void touchpad_get_xy(lv_coord_t * x, lv_coord_t * y);
|
||||
|
||||
static void mouse_init(void);
|
||||
static bool mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
||||
static void mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
||||
static bool mouse_is_pressed(void);
|
||||
static void mouse_get_xy(lv_coord_t * x, lv_coord_t * y);
|
||||
|
||||
static void keypad_init(void);
|
||||
static bool keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
||||
static void keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
||||
static uint32_t keypad_get_key(void);
|
||||
|
||||
static void encoder_init(void);
|
||||
@@ -42,7 +42,7 @@ static bool encoder_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
||||
static void encoder_handler(void);
|
||||
|
||||
static void button_init(void);
|
||||
static bool button_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
||||
static void button_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
||||
static int8_t button_get_pressed_id(void);
|
||||
static bool button_is_pressed(uint8_t id);
|
||||
|
||||
@@ -185,7 +185,7 @@ static void touchpad_init(void)
|
||||
}
|
||||
|
||||
/*Will be called by the library to read the touchpad*/
|
||||
static bool touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
|
||||
static void touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
|
||||
{
|
||||
static lv_coord_t last_x = 0;
|
||||
static lv_coord_t last_y = 0;
|
||||
@@ -201,9 +201,6 @@ static bool touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
|
||||
/*Set the last pressed coordinates*/
|
||||
data->point.x = last_x;
|
||||
data->point.y = last_y;
|
||||
|
||||
/*Return `false` because we are not buffering and no more data to read*/
|
||||
return false;
|
||||
}
|
||||
|
||||
/*Return true is the touchpad is pressed*/
|
||||
@@ -234,7 +231,7 @@ static void mouse_init(void)
|
||||
}
|
||||
|
||||
/*Will be called by the library to read the mouse*/
|
||||
static bool mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
|
||||
static void mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
|
||||
{
|
||||
/*Get the current x and y coordinates*/
|
||||
mouse_get_xy(&data->point.x, &data->point.y);
|
||||
@@ -245,9 +242,6 @@ static bool mouse_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
|
||||
} else {
|
||||
data->state = LV_INDEV_STATE_REL;
|
||||
}
|
||||
|
||||
/*Return `false` because we are not buffering and no more data to read*/
|
||||
return false;
|
||||
}
|
||||
|
||||
/*Return true is the mouse button is pressed*/
|
||||
@@ -278,7 +272,7 @@ static void keypad_init(void)
|
||||
}
|
||||
|
||||
/*Will be called by the library to read the mouse*/
|
||||
static bool keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
|
||||
static void keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
|
||||
{
|
||||
static uint32_t last_key = 0;
|
||||
|
||||
@@ -315,9 +309,6 @@ static bool keypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
|
||||
}
|
||||
|
||||
data->key = last_key;
|
||||
|
||||
/*Return `false` because we are not buffering and no more data to read*/
|
||||
return false;
|
||||
}
|
||||
|
||||
/*Get the currently being pressed key. 0 if no key is pressed*/
|
||||
@@ -339,14 +330,11 @@ static void encoder_init(void)
|
||||
}
|
||||
|
||||
/*Will be called by the library to read the encoder*/
|
||||
static bool encoder_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
|
||||
static void encoder_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
|
||||
{
|
||||
|
||||
data->enc_diff = encoder_diff;
|
||||
data->state = encoder_state;
|
||||
|
||||
/*Return `false` because we are not buffering and no more data to read*/
|
||||
return false;
|
||||
}
|
||||
|
||||
/*Call this function in an interrupt to process encoder events (turn, press)*/
|
||||
@@ -369,7 +357,7 @@ static void button_init(void)
|
||||
}
|
||||
|
||||
/*Will be called by the library to read the button*/
|
||||
static bool button_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
|
||||
static void button_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
|
||||
{
|
||||
|
||||
static uint8_t last_btn = 0;
|
||||
@@ -386,9 +374,6 @@ static bool button_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)
|
||||
|
||||
/*Save the last pressed button's ID*/
|
||||
data->btn_id = last_btn;
|
||||
|
||||
/*Return `false` because we are not buffering and no more data to read*/
|
||||
return false;
|
||||
}
|
||||
|
||||
/*Get ID (0, 1, 2 ..) of the pressed button*/
|
||||
|
||||
+4
-3
@@ -76,10 +76,11 @@ void lv_indev_read_timer_cb(lv_timer_t * timer)
|
||||
indev_proc_reset_query_handler(indev_act);
|
||||
|
||||
if(indev_act->proc.disabled) return;
|
||||
bool more_to_read;
|
||||
bool continue_reading;
|
||||
do {
|
||||
/*Read the data*/
|
||||
more_to_read = _lv_indev_read(indev_act, &data);
|
||||
_lv_indev_read(indev_act, &data);
|
||||
continue_reading = data.continue_reading;
|
||||
|
||||
/*The active object might deleted even in the read function*/
|
||||
indev_proc_reset_query_handler(indev_act);
|
||||
@@ -109,7 +110,7 @@ void lv_indev_read_timer_cb(lv_timer_t * timer)
|
||||
}
|
||||
/*Handle reset query if it happened in during processing*/
|
||||
indev_proc_reset_query_handler(indev_act);
|
||||
} while(more_to_read);
|
||||
} while(continue_reading);
|
||||
|
||||
/*End of indev processing, so no act indev*/
|
||||
indev_act = NULL;
|
||||
|
||||
@@ -127,12 +127,9 @@ lv_indev_t * lv_indev_get_next(lv_indev_t * indev)
|
||||
* Read data from an input device.
|
||||
* @param indev pointer to an input device
|
||||
* @param data input device will write its data here
|
||||
* @return false: no more data; true: there more data to read (buffered)
|
||||
*/
|
||||
bool _lv_indev_read(lv_indev_t * indev, lv_indev_data_t * data)
|
||||
void _lv_indev_read(lv_indev_t * indev, lv_indev_data_t * data)
|
||||
{
|
||||
bool cont = false;
|
||||
|
||||
lv_memset_00(data, sizeof(lv_indev_data_t));
|
||||
|
||||
/* For touchpad sometimes users don't set the last pressed coordinate on release.
|
||||
@@ -152,13 +149,11 @@ bool _lv_indev_read(lv_indev_t * indev, lv_indev_data_t * data)
|
||||
|
||||
if(indev->driver->read_cb) {
|
||||
INDEV_TRACE("calling indev_read_cb");
|
||||
cont = indev->driver->read_cb(indev->driver, data);
|
||||
indev->driver->read_cb(indev->driver, data);
|
||||
}
|
||||
else {
|
||||
LV_LOG_WARN("indev_read_cb is not registered");
|
||||
}
|
||||
|
||||
return cont;
|
||||
}
|
||||
|
||||
/**********************
|
||||
|
||||
@@ -81,6 +81,7 @@ typedef struct {
|
||||
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; /**< Call the read callback until it's set to true*/
|
||||
} lv_indev_data_t;
|
||||
|
||||
/** Initialized by the user and registered by 'lv_indev_add()'*/
|
||||
@@ -89,10 +90,8 @@ typedef struct _lv_indev_drv_t {
|
||||
/**< Input device type*/
|
||||
lv_indev_type_t type;
|
||||
|
||||
/**< Function pointer to read input device data.
|
||||
* Return 'true' if there is more data to be read (buffered).
|
||||
* Most drivers can safely return 'false'*/
|
||||
bool (*read_cb)(struct _lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
||||
/**< Function pointer to read input device data.*/
|
||||
void (*read_cb)(struct _lv_indev_drv_t * indev_drv, lv_indev_data_t * data);
|
||||
|
||||
/** Called when an action happened on the input device.
|
||||
* The second parameter is the event from `lv_event_t`*/
|
||||
@@ -220,9 +219,8 @@ lv_indev_t * lv_indev_get_next(lv_indev_t * indev);
|
||||
* Read data from an input device.
|
||||
* @param indev pointer to an input device
|
||||
* @param data input device will write its data here
|
||||
* @return false: no more data; true: there more data to read (buffered)
|
||||
*/
|
||||
bool _lv_indev_read(lv_indev_t * indev, lv_indev_data_t * data);
|
||||
void _lv_indev_read(lv_indev_t * indev, lv_indev_data_t * data);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
|
||||
Reference in New Issue
Block a user