/*------------------ * Keypad * -----------------*/ /*Initialize your keypad*/ staticvoidkeypad_init(void) { /*Your code comes here*/ } /*Will be called by the library to read the mouse*/ staticvoidkeypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) { staticuint32_t last_key = 0; /*Get the current x and y coordinates*/ mouse_get_xy(&data->point.x, &data->point.y); /*Get whether the a key is pressed and save the pressed key*/ uint32_t act_key = keypad_get_key(); if(act_key != 0) { data->state = LV_INDEV_STATE_PR; /*Translate the keys to LVGL control characters according to your key definitions*/ switch(act_key) { case1: act_key = LV_KEY_NEXT; break; case2: act_key = LV_KEY_PREV; break; case3: act_key = LV_KEY_LEFT; break; case4: act_key = LV_KEY_RIGHT; break; case5: act_key = LV_KEY_ENTER; break; } last_key = act_key; } else { data->state = LV_INDEV_STATE_REL; } data->key = last_key; } /*Get the currently being pressed key. 0 if no key is pressed*/ staticuint32_tkeypad_get_key(void) { /*Your code comes here*/ return0; }
voidscreen_init(void) { tft.begin(); // tft初始化 tft.setRotation( 1 ); // 屏幕方向 lv_disp_draw_buf_init( &draw_buf, buf, NULL, screenWidth * 10 ); /*初始化显示*/ staticlv_disp_drv_t disp_drv; lv_disp_drv_init( &disp_drv ); /*Change the following line to your display resolution*/ disp_drv.hor_res = screenWidth; disp_drv.ver_res = screenHeight; disp_drv.flush_cb = my_disp_flush; disp_drv.draw_buf = &draw_buf; lv_disp_drv_register( &disp_drv ); /*Initialize your keypad or keyboard if you have*/ keypad_init(); /*Register a keypad input device*/ lv_indev_drv_init(&indev_drv); indev_drv.type = LV_INDEV_TYPE_KEYPAD; indev_drv.read_cb = keypad_read; indev_keypad1 = lv_indev_drv_register(&indev_drv); /*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)` *and assign this input device to group to navigate in it: *`lv_indev_set_group(indev_keypad1, group);`*/ group1 = lv_group_create(); lv_indev_set_group(indev_keypad1, group1); }