Compare commits
2 commits
332694aa10
...
f044825791
| Author | SHA1 | Date | |
|---|---|---|---|
| f044825791 | |||
| fb7fe32bf4 |
3 changed files with 147 additions and 22 deletions
|
|
@ -34,6 +34,8 @@ extern "C" {
|
||||||
* GLOBAL PROTOTYPES
|
* GLOBAL PROTOTYPES
|
||||||
**********************/
|
**********************/
|
||||||
void lv_ctr_indev_init(void);
|
void lv_ctr_indev_init(void);
|
||||||
|
lv_indev_t * lv_ctr_indev_get_touchpad(void);
|
||||||
|
lv_indev_t * lv_ctr_indev_get_keypad(void);
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* MACROS
|
* MACROS
|
||||||
|
|
|
||||||
|
|
@ -24,11 +24,13 @@
|
||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
static void touchpad_read(lv_indev_t * indev, lv_indev_data_t * data);
|
static void touchpad_read(lv_indev_t * indev, lv_indev_data_t * data);
|
||||||
|
static void keypad_read(lv_indev_t * indev, lv_indev_data_t * data);
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC VARIABLES
|
* STATIC VARIABLES
|
||||||
**********************/
|
**********************/
|
||||||
lv_indev_t * indev_touchpad;
|
lv_indev_t * indev_touchpad;
|
||||||
|
lv_indev_t * indev_keypad;
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* MACROS
|
* MACROS
|
||||||
|
|
@ -45,12 +47,27 @@ void lv_ctr_indev_init(void)
|
||||||
lv_indev_set_type(indev_touchpad, LV_INDEV_TYPE_POINTER);
|
lv_indev_set_type(indev_touchpad, LV_INDEV_TYPE_POINTER);
|
||||||
lv_indev_set_read_cb(indev_touchpad, touchpad_read);
|
lv_indev_set_read_cb(indev_touchpad, touchpad_read);
|
||||||
|
|
||||||
|
/*Register a keypad input device*/
|
||||||
|
indev_keypad = lv_indev_create();
|
||||||
|
lv_indev_set_type(indev_keypad, LV_INDEV_TYPE_KEYPAD);
|
||||||
|
lv_indev_set_read_cb(indev_keypad, keypad_read);
|
||||||
|
|
||||||
/*Later you should create group(s) with `lv_group_t * group = lv_group_create()`,
|
/*Later you should create group(s) with `lv_group_t * group = lv_group_create()`,
|
||||||
*add objects to the group with `lv_group_add_obj(group, obj)`
|
*add objects to the group with `lv_group_add_obj(group, obj)`
|
||||||
*and assign this input device to group to navigate in it:
|
*and assign this input device to group to navigate in it:
|
||||||
*`lv_indev_set_group(indev_keypad, group);`*/
|
*`lv_indev_set_group(indev_keypad, group);`*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lv_indev_t * lv_ctr_indev_get_touchpad(void)
|
||||||
|
{
|
||||||
|
return indev_touchpad;
|
||||||
|
}
|
||||||
|
|
||||||
|
lv_indev_t * lv_ctr_indev_get_keypad(void)
|
||||||
|
{
|
||||||
|
return indev_keypad;
|
||||||
|
}
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC FUNCTIONS
|
* STATIC FUNCTIONS
|
||||||
**********************/
|
**********************/
|
||||||
|
|
@ -65,8 +82,6 @@ static void touchpad_read(lv_indev_t * indev_drv, lv_indev_data_t * data)
|
||||||
static int32_t last_y = 0;
|
static int32_t last_y = 0;
|
||||||
touchPosition touch;
|
touchPosition touch;
|
||||||
|
|
||||||
hidScanInput();
|
|
||||||
|
|
||||||
/*Save the pressed coordinates and the state*/
|
/*Save the pressed coordinates and the state*/
|
||||||
if(hidKeysHeld() & KEY_TOUCH) {
|
if(hidKeysHeld() & KEY_TOUCH) {
|
||||||
hidTouchRead(&touch);
|
hidTouchRead(&touch);
|
||||||
|
|
@ -83,6 +98,61 @@ static void touchpad_read(lv_indev_t * indev_drv, lv_indev_data_t * data)
|
||||||
data->point.y = last_y;
|
data->point.y = last_y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*------------------
|
||||||
|
* Keypad
|
||||||
|
* -----------------*/
|
||||||
|
|
||||||
|
/* What do you mean you can't handle more than one button at the same time!? */
|
||||||
|
static void keypad_read(lv_indev_t * indev_drv, lv_indev_data_t * data)
|
||||||
|
{
|
||||||
|
static uint32_t last_key = 0;
|
||||||
|
bool key_pressed = false;
|
||||||
|
|
||||||
|
u32 kDown = hidKeysDown();
|
||||||
|
u32 kHeld = hidKeysHeld();
|
||||||
|
u32 kUp = hidKeysUp();
|
||||||
|
|
||||||
|
if (kHeld & KEY_UP) {
|
||||||
|
last_key = LV_KEY_UP;
|
||||||
|
key_pressed = true;
|
||||||
|
}
|
||||||
|
else if (kHeld & KEY_DOWN) {
|
||||||
|
last_key = LV_KEY_DOWN;
|
||||||
|
key_pressed = true;
|
||||||
|
}
|
||||||
|
else if (kHeld & KEY_LEFT) {
|
||||||
|
last_key = LV_KEY_LEFT;
|
||||||
|
key_pressed = true;
|
||||||
|
}
|
||||||
|
else if (kHeld & KEY_RIGHT) {
|
||||||
|
last_key = LV_KEY_RIGHT;
|
||||||
|
key_pressed = true;
|
||||||
|
}
|
||||||
|
else if (kHeld & KEY_A) {
|
||||||
|
last_key = LV_KEY_ENTER;
|
||||||
|
key_pressed = true;
|
||||||
|
}
|
||||||
|
else if (kHeld & KEY_B) {
|
||||||
|
last_key = LV_KEY_ESC;
|
||||||
|
key_pressed = true;
|
||||||
|
}
|
||||||
|
else if (kHeld & KEY_L) {
|
||||||
|
last_key = LV_KEY_PREV;
|
||||||
|
key_pressed = true;
|
||||||
|
}
|
||||||
|
else if (kHeld & KEY_R) {
|
||||||
|
last_key = LV_KEY_NEXT;
|
||||||
|
key_pressed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
data->key = last_key;
|
||||||
|
|
||||||
|
if (key_pressed)
|
||||||
|
data->state = LV_INDEV_STATE_PRESSED;
|
||||||
|
else
|
||||||
|
data->state = LV_INDEV_STATE_RELEASED;
|
||||||
|
}
|
||||||
|
|
||||||
#else /*Enable this file at the top*/
|
#else /*Enable this file at the top*/
|
||||||
|
|
||||||
/*This dummy typedef exists purely to silence -Wpedantic.*/
|
/*This dummy typedef exists purely to silence -Wpedantic.*/
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ static lv_obj_t * cursor;
|
||||||
static lv_obj_t * label;
|
static lv_obj_t * label;
|
||||||
static lv_obj_t * label2;
|
static lv_obj_t * label2;
|
||||||
static lv_obj_t * fps_label;
|
static lv_obj_t * fps_label;
|
||||||
|
static lv_obj_t * keypad_label;
|
||||||
|
|
||||||
|
|
||||||
long unsigned int sys_tick(void)
|
long unsigned int sys_tick(void)
|
||||||
|
|
@ -30,20 +31,18 @@ void sys_free(void)
|
||||||
gfxExit();
|
gfxExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cursor_timer_cb(lv_timer_t * t)
|
static void ui_timer_cb(lv_timer_t * t)
|
||||||
{
|
{
|
||||||
LV_UNUSED(t);
|
LV_UNUSED(t);
|
||||||
|
|
||||||
lv_indev_t * indev = lv_indev_get_next(NULL);
|
lv_indev_t * indev = lv_indev_get_next(NULL);
|
||||||
|
|
||||||
if (!indev)
|
while (indev) {
|
||||||
return;
|
if (lv_indev_get_type(indev) == LV_INDEV_TYPE_POINTER) {
|
||||||
|
|
||||||
lv_point_t p;
|
lv_point_t p;
|
||||||
lv_indev_get_point(indev, &p);
|
lv_indev_get_point(indev, &p);
|
||||||
|
|
||||||
if (lv_indev_get_state(indev) == LV_INDEV_STATE_PRESSED) {
|
if (lv_indev_get_state(indev) == LV_INDEV_STATE_PRESSED) {
|
||||||
|
|
||||||
lv_obj_set_pos(cursor, p.x - 5, p.y - 5);
|
lv_obj_set_pos(cursor, p.x - 5, p.y - 5);
|
||||||
lv_obj_clear_flag(cursor, LV_OBJ_FLAG_HIDDEN);
|
lv_obj_clear_flag(cursor, LV_OBJ_FLAG_HIDDEN);
|
||||||
|
|
||||||
|
|
@ -55,6 +54,49 @@ static void cursor_timer_cb(lv_timer_t * t)
|
||||||
else {
|
else {
|
||||||
lv_obj_add_flag(cursor, LV_OBJ_FLAG_HIDDEN);
|
lv_obj_add_flag(cursor, LV_OBJ_FLAG_HIDDEN);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (lv_indev_get_type(indev) == LV_INDEV_TYPE_KEYPAD) {
|
||||||
|
uint32_t key = lv_indev_get_key(indev);
|
||||||
|
uint32_t state = lv_indev_get_state(indev);
|
||||||
|
const char * txt = "None";
|
||||||
|
|
||||||
|
switch(key) {
|
||||||
|
case LV_KEY_UP:
|
||||||
|
txt = "UP";
|
||||||
|
break;
|
||||||
|
case LV_KEY_DOWN:
|
||||||
|
txt = "DOWN";
|
||||||
|
break;
|
||||||
|
case LV_KEY_LEFT:
|
||||||
|
txt = "LEFT";
|
||||||
|
break;
|
||||||
|
case LV_KEY_RIGHT:
|
||||||
|
txt = "RIGHT";
|
||||||
|
break;
|
||||||
|
case LV_KEY_ENTER:
|
||||||
|
txt = "A";
|
||||||
|
break;
|
||||||
|
case LV_KEY_ESC:
|
||||||
|
txt = "B";
|
||||||
|
break;
|
||||||
|
case LV_KEY_PREV:
|
||||||
|
txt = "L";
|
||||||
|
break;
|
||||||
|
case LV_KEY_NEXT:
|
||||||
|
txt = "R";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
txt = "None";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state == LV_INDEV_STATE_PRESSED)
|
||||||
|
lv_label_set_text_fmt(keypad_label, "Pressed: %s", txt);
|
||||||
|
else
|
||||||
|
lv_label_set_text_fmt(keypad_label, "Released", txt);
|
||||||
|
}
|
||||||
|
indev = lv_indev_get_next(indev);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void switch_event_cb(lv_event_t * e)
|
static void switch_event_cb(lv_event_t * e)
|
||||||
|
|
@ -131,6 +173,10 @@ static void ui_prepare(void)
|
||||||
label2 = lv_label_create(lv_screen_active());
|
label2 = lv_label_create(lv_screen_active());
|
||||||
lv_obj_align(label2, LV_ALIGN_TOP_LEFT, 4, 4);
|
lv_obj_align(label2, LV_ALIGN_TOP_LEFT, 4, 4);
|
||||||
|
|
||||||
|
/* Keypad label */
|
||||||
|
keypad_label = lv_label_create(lv_screen_active());
|
||||||
|
lv_obj_align(keypad_label, LV_ALIGN_TOP_LEFT, 4, 36);
|
||||||
|
|
||||||
/* FPS label */
|
/* FPS label */
|
||||||
fps_label = lv_label_create(lv_screen_active());
|
fps_label = lv_label_create(lv_screen_active());
|
||||||
lv_obj_align(fps_label,
|
lv_obj_align(fps_label,
|
||||||
|
|
@ -139,7 +185,11 @@ static void ui_prepare(void)
|
||||||
-4);
|
-4);
|
||||||
|
|
||||||
/* Main loop UI update timer */
|
/* Main loop UI update timer */
|
||||||
lv_timer_create(cursor_timer_cb, 16, NULL);
|
lv_timer_create(ui_timer_cb, 16, NULL);
|
||||||
|
|
||||||
|
/* Dummy group to make indev happy */
|
||||||
|
lv_group_t * group = lv_group_create();
|
||||||
|
lv_indev_set_group(lv_ctr_indev_get_keypad(), group);
|
||||||
|
|
||||||
lv_obj_invalidate(lv_screen_active());
|
lv_obj_invalidate(lv_screen_active());
|
||||||
}
|
}
|
||||||
|
|
@ -157,13 +207,16 @@ int main(int argc, char* argv[])
|
||||||
// Main loop
|
// Main loop
|
||||||
while (aptMainLoop())
|
while (aptMainLoop())
|
||||||
{
|
{
|
||||||
|
// scan HID inputs
|
||||||
|
hidScanInput();
|
||||||
|
|
||||||
|
// call LVGL timer handler
|
||||||
u64 start = osGetTime();
|
u64 start = osGetTime();
|
||||||
lv_timer_handler();
|
lv_timer_handler();
|
||||||
u64 end = osGetTime();
|
u64 end = osGetTime();
|
||||||
lv_label_set_text_fmt(fps_label, "render: %llums", end - start);
|
lv_label_set_text_fmt(fps_label, "render: %llums", end - start);
|
||||||
|
|
||||||
hidScanInput();
|
// evacuate the dance floor!
|
||||||
|
|
||||||
u32 kDown = hidKeysDown();
|
u32 kDown = hidKeysDown();
|
||||||
if (kDown & KEY_START)
|
if (kDown & KEY_START)
|
||||||
break; // break in order to return to hbmenu
|
break; // break in order to return to hbmenu
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue