Skip to content

Commit

Permalink
Merge pull request #27 from xyzz/controller-special-keys
Browse files Browse the repository at this point in the history
Ability to use controller buttons for special keys
  • Loading branch information
d3m3vilurr authored Sep 17, 2016
2 parents 79d74b1 + f48ffd9 commit b39b80e
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 33 deletions.
9 changes: 5 additions & 4 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <string.h>
#include <getopt.h>
#include "graphics.h"
#include "input/vita.h"

#define MOONLIGHT_PATH "/moonlight"
#define USER_PATHS "."
Expand Down Expand Up @@ -258,7 +259,7 @@ bool config_file_parse(char* filename, PCONFIGURATION config) {
&config->back_deadzone.left);
} else if (strcmp(key, "special_keys") == 0) {
sscanf(value,
"%d,%d,%d,%d,%d,%d",
"%x,%x,%x,%x,%d,%d",
&config->special_keys.nw,
&config->special_keys.ne,
&config->special_keys.sw,
Expand Down Expand Up @@ -325,7 +326,7 @@ void config_save(char* filename, PCONFIGURATION config) {

sprintf(
value,
"%d,%d,%d,%d,%d,%d",
"%x,%x,%x,%x,%d,%d",
config->special_keys.nw,
config->special_keys.ne,
config->special_keys.sw,
Expand Down Expand Up @@ -360,8 +361,8 @@ void config_parse(int argc, char* argv[], PCONFIGURATION config) {
config->unsupported_version = false;
config->disable_powersave = true;

config->special_keys.nw = INPUT_SPECIAL_KEY_PAUSE;
config->special_keys.sw = INPUT_SPECIAL_KEY_MODE;
config->special_keys.nw = INPUT_SPECIAL_KEY_PAUSE | INPUT_TYPE_SPECIAL;
config->special_keys.sw = SPECIAL_FLAG | INPUT_TYPE_GAMEPAD;
config->special_keys.offset = 0;
config->special_keys.size = 150;

Expand Down
7 changes: 1 addition & 6 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,9 @@ struct touchscreen_deadzone {
int top, bottom, left, right;
};

enum {
INPUT_SPECIAL_KEY_MODE = -10,
INPUT_SPECIAL_KEY_PAUSE
};

struct special_keys {
int size, offset;
int nw, ne, sw, se;
unsigned int nw, ne, sw, se;
};

typedef struct _CONFIGURATION {
Expand Down
1 change: 1 addition & 0 deletions src/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ void connection_reset();

bool connection_is_ready();
int connection_get_status();
void connection_minimize();
16 changes: 13 additions & 3 deletions src/gui/guilib.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <psp2/rtc.h>
#include <psp2/power.h>

#define BUTTON_DELAY 150 * 1000

struct menu_geom make_geom_centered(int w, int h) {
struct menu_geom geom = {0};
geom.x = WIDTH / 2 - w / 2;
Expand Down Expand Up @@ -102,11 +104,20 @@ void draw_statusbar(struct menu_geom geom) {
battery_color);
}

SceCtrlData ctrl_old_pad;
SceCtrlData ctrl_new_pad;

static SceRtcTick button_current_tick, button_until_tick;
bool was_button_pressed(short id) {
return ctrl_new_pad.buttons & id && !(ctrl_old_pad.buttons & id);
sceRtcGetCurrentTick(&button_current_tick);

if (ctrl_new_pad.buttons & id) {
if (sceRtcCompareTick(&button_current_tick, &button_until_tick) > 0) {
sceRtcTickAddMicroseconds(&button_until_tick, &button_current_tick, BUTTON_DELAY);
return true;
}
}

return false;
}

bool is_button_down(short id) {
Expand Down Expand Up @@ -257,7 +268,6 @@ void gui_ctrl_begin() {
}

void gui_ctrl_end() {
sceCtrlPeekBufferPositive(0, &ctrl_old_pad, 1);
}

void gui_ctrl_cursor(int *cursor_ptr, int total_elements) {
Expand Down
17 changes: 14 additions & 3 deletions src/gui/ui_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,21 @@
#include <psp2/rtc.h>
#include <psp2/touch.h>
#include <vita2d.h>

static int settings_special_codes[] = {0, INPUT_SPECIAL_KEY_PAUSE, INPUT_SPECIAL_KEY_MODE,
#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,
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)",
static char *settings_special_names[] = {"None", "Pause stream",
"Special (XBox button)", "LB", "RB", "LS", "RS",
"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
38 changes: 21 additions & 17 deletions src/input/vita.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,31 +209,37 @@ static void special_input(SceTouchData screen, int *btn) {
for (int identifier = TOUCHSEC_SPECIAL_NW; identifier <= TOUCHSEC_SPECIAL_SE; identifier++) {
int idx = identifier - TOUCHSEC_SPECIAL_NW;
bool current_status = special_input_status[idx];
int config_code = special_input_config_code(identifier);
unsigned int config_code = special_input_config_code(identifier);

unsigned int type = config_code & INPUT_TYPE_MASK;
unsigned int code = config_code & INPUT_VALUE_MASK;
if (check_touch_sector(screen, identifier) && !current_status) {
switch (config_code) {
case INPUT_SPECIAL_KEY_MODE:
*btn |= SPECIAL_FLAG;
switch (type) {
case INPUT_TYPE_SPECIAL:
if (code == INPUT_SPECIAL_KEY_PAUSE) {
connection_minimize();
} break;
case INPUT_TYPE_GAMEPAD:
*btn |= code;
break;
case INPUT_SPECIAL_KEY_PAUSE:
connection_minimize();
case INPUT_TYPE_MOUSE:
special_input_status[idx] = true;
LiSendMouseButtonEvent(BUTTON_ACTION_PRESS, code);
break;
default:
case INPUT_TYPE_KEYBOARD:
special_input_status[idx] = true;
LiSendKeyboardEvent(config_code, KEY_ACTION_DOWN, 0);
LiSendKeyboardEvent(code, KEY_ACTION_DOWN, 0);
break;
}
} else if (!check_touch_sector(screen, identifier) && current_status) {
special_input_status[idx] = false;

switch (config_code) {
case INPUT_SPECIAL_KEY_MODE:
break;
case INPUT_SPECIAL_KEY_PAUSE:
switch (type) {
case INPUT_TYPE_MOUSE:
LiSendMouseButtonEvent(BUTTON_ACTION_RELEASE, code);
break;
default:
LiSendKeyboardEvent(config_code, KEY_ACTION_UP, 0);
case INPUT_TYPE_KEYBOARD:
LiSendKeyboardEvent(code, KEY_ACTION_UP, 0);
break;
}
}
Expand Down Expand Up @@ -319,11 +325,9 @@ void vitainput_process(void) {
case 1:
move_mouse(front_old, front);
break;
case 3:
LiSendControllerEvent((short) (0 | SPECIAL_FLAG), 0, 0, 0, 0, 0, 0);
break;
case 2:
move_wheel(front_old, front);
break;
}
memcpy(&front_old, &front, sizeof(front_old));
} else {
Expand Down
12 changes: 12 additions & 0 deletions src/input/vita.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ enum {
RIGHTY
} PadSection;

#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

enum {
INPUT_SPECIAL_KEY_PAUSE
};

bool vitainput_init();
void vitainput_config(CONFIGURATION config);

Expand Down

0 comments on commit b39b80e

Please sign in to comment.