Skip to content

Commit

Permalink
Merge pull request #31 from d3m3vilurr/refactor-input-identifier
Browse files Browse the repository at this point in the history
Refactor input identifier of map
  • Loading branch information
Vasiliy Horbachenko authored Sep 20, 2016
2 parents cbb4873 + e2c8433 commit d811df7
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 68 deletions.
32 changes: 16 additions & 16 deletions mappings/vita.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,35 @@ abs_rx = 2
abs_ry = 3

# cross
btn_south = 16383
btn_south = 304000
# circle
btn_east = 8191
btn_east = 302000
# triangle
btn_north = 4095
btn_north = 301000
# square
btn_west = 32767
btn_west = 308000
# select
btn_select = 0
btn_select = 300001
# start
btn_start = 7
btn_start = 300008
# dpad
btn_dpad_up = 15
btn_dpad_down = 63
btn_dpad_left = 127
btn_dpad_right = 31
btn_dpad_up = 300010
btn_dpad_down = 300040
btn_dpad_left = 300080
btn_dpad_right = 300020
# LB
btn_thumbl = 255
btn_thumbl = 300100
# RB
btn_thumbr = 511
btn_thumbr = 300200

# LT
btn_tl = 600
btn_tl = 500258
# RT
btn_tr = 601
btn_tr = 500259
# LS
btn_tl2 = 602
btn_tl2 = 50025a
# RS
btn_tr2 = 603
btn_tr2 = 50025b

# not used
btn_mode = -1
Expand Down
5 changes: 3 additions & 2 deletions src/input/mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,22 @@
#include <stdlib.h>
#include <string.h>

#define write_config(fd, key, value) fprintf(fd, "%s = %hd\n", key, value)
#define write_config(fd, key, value) fprintf(fd, "%s = %x\n", key, value)
#define write_config_bool(fd, key, value) fprintf(fd, "%s = %s\n", key, value?"true":"false");

void mapping_load(char* fileName, struct mapping* map) {
FILE* fd = fopen(fileName, "r");
if (fd == NULL) {
printf("Can't open mapping file: %s\n", fileName);
return;
}

char *line = NULL;
size_t len = 0;
while (__getline(&line, &len, fd) != -1) {
char key[256], value[256];
if (sscanf(line, "%s = %s", &key, &value) == 2) {
long int_value = strtol(value, NULL, 10);
long int_value = strtol(value, NULL, 16);
if (strcmp("abs_x", key) == 0)
map->abs_x = int_value;
else if (strcmp("abs_y", key) == 0)
Expand Down
11 changes: 6 additions & 5 deletions src/input/mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* along with Moonlight; if not, see <http://www.gnu.org/licenses/>.
*/

#include <stdint.h>
#include <stdbool.h>

struct mapping {
Expand All @@ -31,12 +32,12 @@ struct mapping {
short abs_dpad_x, abs_dpad_y;
bool reverse_dpad_x, reverse_dpad_y;

short btn_south, btn_east, btn_north, btn_west;
short btn_select, btn_start, btn_mode;
short btn_thumbl, btn_thumbr;
short btn_tl, btn_tr, btn_tl2, btn_tr2;
uint32_t btn_south, btn_east, btn_north, btn_west;
uint32_t btn_select, btn_start, btn_mode;
uint32_t btn_thumbl, btn_thumbr;
uint32_t btn_tl, btn_tr, btn_tl2, btn_tr2;

short btn_dpad_up, btn_dpad_down, btn_dpad_left, btn_dpad_right;
uint32_t btn_dpad_up, btn_dpad_down, btn_dpad_left, btn_dpad_right;
};

void mapping_load(char* fileName, struct mapping* map);
Expand Down
82 changes: 44 additions & 38 deletions src/input/vita.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,20 @@ static short pad_value(SceCtrlData pad, int sec) {
return (short) (value * 256 - (1 << 15) + 128);
}

bool check_input(short identifier, SceCtrlData pad, SceTouchData screen) {
if (identifier >= TOUCHSEC_NORTHWEST && identifier <= TOUCHSEC_SOUTHEAST) {
return check_touch_sector(screen, identifier) != -1;
} else {
identifier = identifier + 1;
return pad.buttons & identifier;
bool check_input(uint32_t identifier, SceCtrlData pad, SceTouchData screen) {
uint32_t type = identifier & INPUT_TYPE_MASK;
int value = identifier & INPUT_VALUE_MASK;

switch (type) {
case INPUT_TYPE_TOUCHSCREEN:
if (value < TOUCHSEC_NORTHWEST || value > TOUCHSEC_SOUTHEAST) {
return false;
}
return check_touch_sector(screen, value) != -1;
case INPUT_TYPE_GAMEPAD:
return pad.buttons & value;
}
return false;
}

static int special_input_config_code(short identifier) {
Expand Down Expand Up @@ -288,28 +295,27 @@ void vitainput_process(void) {
input_data input = {0};

// 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_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_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_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_tl2, LS_CLK_FLAG);
INPUT(map.btn_tr2, RS_CLK_FLAG);

INPUT(map.btn_thumbl, LB_FLAG);
INPUT(map.btn_thumbr, RB_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.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),
Expand Down Expand Up @@ -442,23 +448,23 @@ void vitainput_config(CONFIGURATION config) {
map.abs_rx = 2;
map.abs_ry = 3;

map.btn_south = SCE_CTRL_CROSS - 1;
map.btn_east = SCE_CTRL_CIRCLE - 1;
map.btn_north = SCE_CTRL_TRIANGLE - 1;
map.btn_west = SCE_CTRL_SQUARE - 1;
map.btn_select = SCE_CTRL_SELECT - 1;
map.btn_start = SCE_CTRL_START - 1;
map.btn_thumbl = SCE_CTRL_LTRIGGER - 1;
map.btn_thumbr = SCE_CTRL_RTRIGGER - 1;
map.btn_dpad_up = SCE_CTRL_UP - 1;
map.btn_dpad_down = SCE_CTRL_DOWN - 1;
map.btn_dpad_left = SCE_CTRL_LEFT - 1;
map.btn_dpad_right = SCE_CTRL_RIGHT - 1;

map.btn_tl = TOUCHSEC_NORTHWEST;
map.btn_tr = TOUCHSEC_NORTHEAST;
map.btn_tl2 = TOUCHSEC_SOUTHWEST;
map.btn_tr2 = TOUCHSEC_SOUTHEAST;
map.btn_south = SCE_CTRL_CROSS | INPUT_TYPE_GAMEPAD;
map.btn_east = SCE_CTRL_CIRCLE | INPUT_TYPE_GAMEPAD;
map.btn_north = SCE_CTRL_TRIANGLE | INPUT_TYPE_GAMEPAD;
map.btn_west = SCE_CTRL_SQUARE | INPUT_TYPE_GAMEPAD;
map.btn_select = SCE_CTRL_SELECT | INPUT_TYPE_GAMEPAD;
map.btn_start = SCE_CTRL_START | INPUT_TYPE_GAMEPAD;
map.btn_thumbl = SCE_CTRL_LTRIGGER | INPUT_TYPE_GAMEPAD;
map.btn_thumbr = SCE_CTRL_RTRIGGER | INPUT_TYPE_GAMEPAD;
map.btn_dpad_up = SCE_CTRL_UP | INPUT_TYPE_GAMEPAD;
map.btn_dpad_down = SCE_CTRL_DOWN | INPUT_TYPE_GAMEPAD;
map.btn_dpad_left = SCE_CTRL_LEFT | INPUT_TYPE_GAMEPAD;
map.btn_dpad_right = SCE_CTRL_RIGHT | INPUT_TYPE_GAMEPAD;

map.btn_tl = TOUCHSEC_NORTHWEST | INPUT_TYPE_TOUCHSCREEN;
map.btn_tr = TOUCHSEC_NORTHEAST | INPUT_TYPE_TOUCHSCREEN;
map.btn_tl2 = TOUCHSEC_SOUTHWEST | INPUT_TYPE_TOUCHSCREEN;
map.btn_tr2 = TOUCHSEC_SOUTHEAST | INPUT_TYPE_TOUCHSCREEN;

if (config.mapping) {
char config_path[256];
Expand Down
15 changes: 8 additions & 7 deletions src/input/vita.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ enum {
RIGHT_TRIGGER
} PadSection;

#define INPUT_TYPE_MASK 0xffff0000
#define INPUT_VALUE_MASK 0x0000ffff
#define INPUT_TYPE_MASK 0xfff00000
#define INPUT_VALUE_MASK 0x000fffff

#define INPUT_TYPE_KEYBOARD 0x00000000
#define INPUT_TYPE_SPECIAL 0x00010000
#define INPUT_TYPE_MOUSE 0x00020000
#define INPUT_TYPE_GAMEPAD 0x00030000
#define INPUT_TYPE_AXIS 0x00040000
#define INPUT_TYPE_KEYBOARD 0x00000000
#define INPUT_TYPE_SPECIAL 0x00100000
#define INPUT_TYPE_MOUSE 0x00200000
#define INPUT_TYPE_GAMEPAD 0x00300000
#define INPUT_TYPE_AXIS 0x00400000
#define INPUT_TYPE_TOUCHSCREEN 0x00500000

enum {
INPUT_SPECIAL_KEY_PAUSE
Expand Down

0 comments on commit d811df7

Please sign in to comment.