Skip to content

Commit

Permalink
little input and ui cleanup; ability to use axis for special keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Vasiliy Horbachenko committed Sep 17, 2016
1 parent 5e34814 commit a17d793
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 66 deletions.
1 change: 0 additions & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ typedef struct _CONFIGURATION {
bool fullscreen;
bool forcehw;
bool unsupported_version;
bool fronttouchscreen_buttons;
struct touchscreen_deadzone back_deadzone;
struct special_keys special_keys;
bool disable_powersave;
Expand Down
16 changes: 9 additions & 7 deletions src/gui/ui_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@
#include <Limelight.h>

static unsigned int settings_special_codes[] = {0, INPUT_SPECIAL_KEY_PAUSE | INPUT_TYPE_SPECIAL,
1024 | INPUT_TYPE_GAMEPAD,
256 | INPUT_TYPE_GAMEPAD,
512 | INPUT_TYPE_GAMEPAD,
64 | INPUT_TYPE_GAMEPAD,
128 | INPUT_TYPE_GAMEPAD,
SPECIAL_FLAG | INPUT_TYPE_GAMEPAD,
LB_FLAG | INPUT_TYPE_GAMEPAD,
RB_FLAG | INPUT_TYPE_GAMEPAD,
LS_CLK_FLAG | INPUT_TYPE_GAMEPAD,
RS_CLK_FLAG | INPUT_TYPE_GAMEPAD,
LEFT_TRIGGER | INPUT_TYPE_AXIS,
RIGHT_TRIGGER | INPUT_TYPE_AXIS,
BUTTON_LEFT | INPUT_TYPE_MOUSE,
BUTTON_RIGHT | INPUT_TYPE_MOUSE,
BUTTON_MIDDLE | INPUT_TYPE_MOUSE,
27, 73, 77, 9, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123 };
static char *settings_special_names[] = {"None", "Pause stream",
"Special (XBox button)", "LB", "RB", "LS", "RS",
"Special (XBox button)", "LB", "RB", "LS", "RS", "LT", "RT",
"LMB", "RMB", "MMB",
"Esc", "I", "M", "Tab", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12" };
static bool settings_loop_setup = 1;
Expand Down Expand Up @@ -278,7 +280,7 @@ static void special_keys_draw() {
int special_offset = config.special_keys.offset,
special_size = config.special_keys.size;

unsigned int color = 0xffffffff;
unsigned int color = 0xff006000;

for (int i = TOUCHSEC_SPECIAL_NW; i <= TOUCHSEC_SPECIAL_SE; i++) {
switch (i) {
Expand Down
113 changes: 60 additions & 53 deletions src/input/vita.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@

static struct mapping map = {0};

typedef struct input_data {
short button;
char left_trigger;
char right_trigger;
short lx;
short ly;
short rx;
short ry;
} input_data;

#define lerp(value, from_max, to_max) ((((value*10) * (to_max*10))/(from_max*10))/10)

static int check_touch(SceTouchData scr, int lx, int ly, int rx, int ry) {
Expand Down Expand Up @@ -174,15 +184,9 @@ static short pad_value(SceCtrlData pad, int sec) {
return (short) (value * 256 - (1 << 15) + 128);
}

bool check_input(short identifier, SceCtrlData pad, SceTouchData screen, SceTouchData front, SceTouchData back) {
if (identifier >= TOUCHSEC_NORTHWEST && identifier < TOUCHSEC_SPECIAL_SW) {
bool check_input(short identifier, SceCtrlData pad, SceTouchData screen) {
if (identifier >= TOUCHSEC_NORTHWEST && identifier <= TOUCHSEC_SOUTHEAST) {
return check_touch_sector(screen, identifier) != -1;
} else if (identifier >= TOUCHSEC_SPECIAL_SW && identifier <= TOUCHSEC_SPECIAL_NE) {
if (config.fronttouchscreen_buttons == true) {
return false;
} else {
return check_touch_sector(front, identifier) != -1;
}
} else {
identifier = identifier + 1;
return pad.buttons & identifier;
Expand All @@ -205,7 +209,7 @@ static int special_input_config_code(short identifier) {
}

static bool special_input_status[4] = {0, 0, 0, 0};
static void special_input(SceTouchData screen, int *btn) {
static void special_input(SceTouchData screen, input_data *input) {
for (int identifier = TOUCHSEC_SPECIAL_NW; identifier <= TOUCHSEC_SPECIAL_SE; identifier++) {
int idx = identifier - TOUCHSEC_SPECIAL_NW;
bool current_status = special_input_status[idx];
Expand All @@ -220,12 +224,22 @@ static void special_input(SceTouchData screen, int *btn) {
connection_minimize();
} break;
case INPUT_TYPE_GAMEPAD:
*btn |= code;
input->button |= code;
break;
case INPUT_TYPE_MOUSE:
special_input_status[idx] = true;
LiSendMouseButtonEvent(BUTTON_ACTION_PRESS, code);
break;
case INPUT_TYPE_AXIS:
switch (code) {
case LEFT_TRIGGER:
input->left_trigger = 0xff;
break;
case RIGHT_TRIGGER:
input->right_trigger = 0xff;
break;
}
break;
case INPUT_TYPE_KEYBOARD:
special_input_status[idx] = true;
LiSendKeyboardEvent(code, KEY_ACTION_DOWN, 0);
Expand All @@ -246,8 +260,8 @@ static void special_input(SceTouchData screen, int *btn) {
}
}

#define CHECK_INPUT(id) check_input((id), pad, buttons_screen, front, back)
#define INPUT(id, flag) if (check_input((id), pad, buttons_screen, front, back)) input.button |= (flag);
#define CHECK_INPUT(id) check_input((id), pad, back)
#define INPUT(id, flag) if (check_input((id), pad, back)) input.button |= (flag);

static SceCtrlData pad;
static SceTouchData front;
Expand All @@ -261,16 +275,6 @@ static SceRtcTick current, until;

static int special_status;

typedef struct input_data {
short button;
char left_trigger;
char right_trigger;
short lx;
short ly;
short rx;
short ry;
} input_data;

static input_data old;

void vitainput_process(void) {
Expand All @@ -283,9 +287,40 @@ void vitainput_process(void) {

input_data input = {0};

SceTouchData buttons_screen = config.fronttouchscreen_buttons ? front : back;
special_input(front, &input.button);
// buttons
INPUT(map.btn_dpad_up, UP_FLAG);
INPUT(map.btn_dpad_up, UP_FLAG);
INPUT(map.btn_dpad_left, LEFT_FLAG);
INPUT(map.btn_dpad_down, DOWN_FLAG);
INPUT(map.btn_dpad_right, RIGHT_FLAG);

INPUT(map.btn_start, PLAY_FLAG);
INPUT(map.btn_select, BACK_FLAG);

INPUT(map.btn_north, Y_FLAG);
INPUT(map.btn_east, B_FLAG);
INPUT(map.btn_south, A_FLAG);
INPUT(map.btn_west, X_FLAG);

INPUT(map.btn_tl2, LS_CLK_FLAG);
INPUT(map.btn_tr2, RS_CLK_FLAG);

INPUT(map.btn_thumbl, LB_FLAG);
INPUT(map.btn_thumbr, RB_FLAG);

// AXIS
input.left_trigger = CHECK_INPUT(map.btn_tl) ? 0xff : 0;
input.right_trigger = CHECK_INPUT(map.btn_tr) ? 0xff : 0;

input.lx = pad_value(pad, map.abs_x),
input.ly = pad_value(pad, map.abs_y),
input.rx = pad_value(pad, map.abs_rx),
input.ry = pad_value(pad, map.abs_ry);

// special touchscreen buttons
special_input(front, &input);

// remove touches for special actions
for (int i = TOUCHSEC_SPECIAL_NW, touchIdx = -1; i <= TOUCHSEC_SPECIAL_SE; i++) {
unsigned int config_code = special_input_config_code(i);
if (config_code && (touchIdx = check_touch_sector(front, i)) != -1) {
Expand All @@ -299,6 +334,7 @@ void vitainput_process(void) {
}
}

// mouse
switch (front_state) {
case NO_TOUCH_ACTION:
if (front.reportNum > 0) {
Expand Down Expand Up @@ -353,35 +389,6 @@ void vitainput_process(void) {
break;
}

INPUT(map.btn_dpad_up, UP_FLAG);
INPUT(map.btn_dpad_up, UP_FLAG);
INPUT(map.btn_dpad_left, LEFT_FLAG);
INPUT(map.btn_dpad_down, DOWN_FLAG);
INPUT(map.btn_dpad_right, RIGHT_FLAG);

INPUT(map.btn_start, PLAY_FLAG);
INPUT(map.btn_select, BACK_FLAG);

INPUT(map.btn_north, Y_FLAG);
INPUT(map.btn_east, B_FLAG);
INPUT(map.btn_south, A_FLAG);
INPUT(map.btn_west, X_FLAG);

INPUT(map.btn_tl2, LS_CLK_FLAG);
INPUT(map.btn_tr2, RS_CLK_FLAG);

INPUT(map.btn_thumbl, LB_FLAG);
INPUT(map.btn_thumbr, RB_FLAG);

// TRIGGERS
input.left_trigger = CHECK_INPUT(map.btn_tl) ? 0xff : 0;
input.right_trigger = CHECK_INPUT(map.btn_tr) ? 0xff : 0;

input.lx = pad_value(pad, map.abs_x),
input.ly = pad_value(pad, map.abs_y),
input.rx = pad_value(pad, map.abs_rx),
input.ry = pad_value(pad, map.abs_ry);

if (memcmp(&input, &old, sizeof(input_data)) != 0) {
LiSendControllerEvent(input.button, input.left_trigger, input.right_trigger,
input.lx, -1 * input.ly, input.rx, -1 * input.ry);
Expand Down
13 changes: 8 additions & 5 deletions src/input/vita.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,19 @@ enum {
LEFTX,
LEFTY,
RIGHTX,
RIGHTY
RIGHTY,
LEFT_TRIGGER,
RIGHT_TRIGGER
} PadSection;

#define INPUT_TYPE_MASK 0xffff0000
#define INPUT_TYPE_MASK 0xffff0000
#define INPUT_VALUE_MASK 0x0000ffff

#define INPUT_TYPE_KEYBOARD 0x00000000
#define INPUT_TYPE_SPECIAL 0x00010000
#define INPUT_TYPE_MOUSE 0x00020000
#define INPUT_TYPE_GAMEPAD 0x00030000
#define INPUT_TYPE_SPECIAL 0x00010000
#define INPUT_TYPE_MOUSE 0x00020000
#define INPUT_TYPE_GAMEPAD 0x00030000
#define INPUT_TYPE_AXIS 0x00040000

enum {
INPUT_SPECIAL_KEY_PAUSE
Expand Down

0 comments on commit a17d793

Please sign in to comment.