1
0
mirror of https://github.com/djhackersdev/bemanitools.git synced 2024-11-30 17:24:30 +01:00

Add invert analog input option

This commit is contained in:
ahnada 2023-12-08 22:42:30 -08:00 committed by icex2
parent bdf493d2fb
commit f37f216c69
8 changed files with 76 additions and 9 deletions

View File

@ -54,6 +54,7 @@ static void analog_ui_populate_controls(HWND hwnd);
static INT_PTR analog_ui_handle_device_change(HWND hwnd);
static INT_PTR analog_ui_handle_control_change(HWND hwnd);
static INT_PTR analog_ui_handle_sensitivity_change(HWND hwnd);
static INT_PTR analog_ui_handle_invert_change(HWND hwnd);
static INT_PTR analog_ui_handle_tick(HWND hwnd);
static INT_PTR analog_ui_handle_fini(HWND hwnd);
@ -213,6 +214,15 @@ analog_ui_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
return FALSE;
}
case BN_CLICKED:
switch (LOWORD(wparam)) {
case IDC_ANALOG_INVERT:
return analog_ui_handle_invert_change(hwnd);
default:
return FALSE;
}
default:
return FALSE;
}
@ -519,6 +529,21 @@ static INT_PTR analog_ui_handle_sensitivity_change(HWND hwnd)
return TRUE;
}
static INT_PTR analog_ui_handle_invert_change(HWND hwnd)
{
struct analog_ui *ui;
HWND btn;
bool invert;
ui = (struct analog_ui *) GetWindowLongPtr(hwnd, GWLP_USERDATA);
btn = GetDlgItem(hwnd, IDC_ANALOG_INVERT);
invert = SendMessage(btn, BM_GETCHECK, 0, 0) == BST_CHECKED;
mapper_set_analog_invert(ui->def->tag, invert);
return TRUE;
}
static INT_PTR analog_ui_handle_tick(HWND hwnd)
{
struct analog_ui *ui;

View File

@ -22,18 +22,19 @@ IDR_USAGES USAGES "config/usages.txt"
// Dialog resources
//
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_ANALOG DIALOG 0, 0, 220, 100
IDD_ANALOG DIALOG 0, 0, 220, 115
STYLE DS_3DLOOK | DS_CENTER | DS_SHELLFONT | WS_VISIBLE | WS_CHILDWINDOW
EXSTYLE WS_EX_CONTROLPARENT
FONT 8, "Ms Shell Dlg"
{
GROUPBOX "", IDC_GROUP, 5, 5, 210, 90
GROUPBOX "", IDC_GROUP, 5, 5, 210, 105
CONTROL "", IDC_SENSITIVITY, TRACKBAR_CLASS, WS_TABSTOP | TBS_AUTOTICKS, 10, 75, 200, 15
LTEXT "Device", IDC_STATIC, 15, 15, 24, 8, SS_LEFT
COMBOBOX IDC_DEVICE, 15, 25, 135, 30, WS_GROUP | WS_TABSTOP | CBS_DROPDOWNLIST | CBS_HASSTRINGS
COMBOBOX IDC_CONTROL, 15, 50, 135, 30, WS_TABSTOP | CBS_DROPDOWNLIST | CBS_HASSTRINGS
LTEXT "Sensitivity", IDC_STATIC, 15, 65, 32, 8, SS_LEFT
LTEXT "Control", IDC_STATIC, 15, 40, 23, 8, SS_LEFT
AUTOCHECKBOX "Invert Axis", IDC_ANALOG_INVERT, 15, 95, 141, 8
CONTROL "", IDC_POSITION, "spinner", 0x50020000, 160, 15, 50, 50, 0x02002000
}
@ -126,7 +127,7 @@ FONT 8, "Ms Shell Dlg"
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_TAB_ANALOGS DIALOG 0, 0, 220, 215
IDD_TAB_ANALOGS DIALOG 0, 0, 220, 230
STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU
CAPTION "Analogs"
FONT 8, "Ms Shell Dlg"

View File

@ -30,6 +30,7 @@
#define IDC_DEVICE 1005
#define IDC_BINDING_EDIT 1006
#define IDC_CONTROL 1006
#define IDC_ANALOG_INVERT 1007
#define IDC_BINDING_CLEAR 1007
#define IDC_BINDING_MIN 1008
#define IDC_PAGE_TEXT 1008

View File

@ -44,6 +44,7 @@ EXPORTS
mapper_set_action_map
mapper_set_analog_map
mapper_set_analog_sensitivity
mapper_set_analog_invert
mapper_set_light_map
mapper_set_nanalogs
mapper_set_nlights

View File

@ -25,6 +25,7 @@ void mapper_set_action_map(
uint8_t action, uint8_t page, uint8_t bit, const struct mapped_action *ma);
bool mapper_set_analog_map(uint8_t analog, const struct mapped_analog *ma);
bool mapper_set_analog_sensitivity(uint8_t analog, int32_t sensitivity);
bool mapper_set_analog_invert(uint8_t analog, bool invert);
void mapper_set_nanalogs(uint8_t nanalogs);
void mapper_set_nlights(uint8_t nlights);
void mapper_set_light_map(const struct mapped_light *ml, uint8_t game_light);

View File

@ -190,6 +190,11 @@ bool mapper_set_analog_sensitivity(uint8_t analog, int32_t sensitivity)
return mapper_impl_set_analog_sensitivity(mapper_inst, analog, sensitivity);
}
bool mapper_set_analog_invert(uint8_t analog, bool invert)
{
return mapper_impl_set_analog_invert(mapper_inst, analog, invert);
}
void mapper_set_light_map(const struct mapped_light *ml, uint8_t game_light)
{
mapper_impl_set_light_map(mapper_inst, ml, game_light);

View File

@ -26,8 +26,10 @@ struct analog_mapping {
bool bound;
bool valid;
bool absolute;
double affine_scale;
double affine_bias;
bool invert;
double analog_min;
double analog_max;
double inv_analog_range;
uint8_t pos;
};
@ -169,9 +171,11 @@ static void analog_mapping_bind(struct analog_mapping *am)
ctl = &controls[am->src.control_no];
am->affine_bias = ctl->value_min;
am->affine_scale = ctl->value_max - ctl->value_min;
am->analog_min = ctl->value_min;
am->analog_max = ctl->value_max;
am->inv_analog_range = 1.0 / ((int64_t)ctl->value_max - ctl->value_min);
am->absolute = !(ctl->flags & HID_FLAG_RELATIVE);
am->invert = false;
am->valid = true;
read_fail:
@ -187,6 +191,7 @@ static void analog_mapping_update(struct analog_mapping *am)
{
double tmp;
int32_t value;
int8_t delta;
if (!am->bound) {
analog_mapping_bind(am);
@ -201,10 +206,24 @@ static void analog_mapping_update(struct analog_mapping *am)
}
if (am->absolute) {
tmp = (value - am->affine_bias) / am->affine_scale;
if (am->invert) {
tmp = am->analog_max - value;
} else {
tmp = value - am->analog_min;
}
// Scale the input value to [0,1] range
tmp *= am->inv_analog_range;
am->pos = (uint8_t) ((tmp + 0.5) * 256.0);
} else {
am->pos += (int8_t) (value * exp(am->sensitivity / 256.0));
delta = (int8_t) (value * exp(am->sensitivity / 256.0));
if (am->invert) {
delta *= -1;
}
am->pos += delta;
}
}
@ -531,6 +550,18 @@ bool mapper_impl_set_analog_sensitivity(
return true;
}
bool mapper_impl_set_analog_invert(
struct mapper *m, uint8_t analog, bool invert)
{
if (analog >= m->nanalogs) {
return false;
}
m->analogs[analog].invert = invert;
return true;
}
void mapper_impl_set_light_map(
struct mapper *m, const struct mapped_light *ml, uint8_t game_light)
{

View File

@ -73,6 +73,8 @@ bool mapper_impl_set_analog_map(
struct mapper *m, uint8_t analog, const struct mapped_analog *ma);
bool mapper_impl_set_analog_sensitivity(
struct mapper *m, uint8_t analog, int32_t sensitivity);
bool mapper_impl_set_analog_invert(
struct mapper *m, uint8_t analog, bool invert);
void mapper_impl_set_light_map(
struct mapper *m, const struct mapped_light *ml, uint8_t game_light);
void mapper_impl_set_nanalogs(struct mapper *m, uint8_t nanalogs);