lomo/source/lv_ctr_indev.c

160 lines
3.6 KiB
C

/**
* @file lv_ctr_indev.c
*
*/
#if 1
/*********************
* INCLUDES
*********************/
#include "lv_ctr_indev.h"
#include <3ds.h>
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
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
**********************/
lv_indev_t * indev_touchpad;
lv_indev_t * indev_keypad;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_ctr_indev_init(void)
{
/*Register a touch screen input device*/
indev_touchpad = lv_indev_create();
lv_indev_set_type(indev_touchpad, LV_INDEV_TYPE_POINTER);
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()`,
*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_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
**********************/
/*------------------
* Touchpad
* -----------------*/
static void touchpad_read(lv_indev_t * indev_drv, lv_indev_data_t * data)
{
static int32_t last_x = 0;
static int32_t last_y = 0;
touchPosition touch;
/*Save the pressed coordinates and the state*/
if(hidKeysHeld() & KEY_TOUCH) {
hidTouchRead(&touch);
last_x = touch.px;
last_y = touch.py;
data->state = LV_INDEV_STATE_PRESSED;
}
else {
data->state = LV_INDEV_STATE_RELEASED;
}
/*Set the last pressed coordinates*/
data->point.x = last_x;
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*/
/*This dummy typedef exists purely to silence -Wpedantic.*/
typedef int keep_pedantic_happy;
#endif