diff --git a/src/main/config/analogs.c b/src/main/config/analogs.c index 4a532ee..5a7bcee 100644 --- a/src/main/config/analogs.c +++ b/src/main/config/analogs.c @@ -49,6 +49,7 @@ static INT_PTR analog_ui_handle_init(HWND hwnd, struct analog_def *def); static void analog_ui_handle_init_label(HWND hwnd); static void analog_ui_handle_init_dev(HWND hwnd); static void analog_ui_handle_init_sensitivity(HWND hwnd); +static void analog_ui_handle_init_invert(HWND hwnd); static bool analog_ui_match_device(struct hid_stub *hid); static void analog_ui_populate_controls(HWND hwnd); static INT_PTR analog_ui_handle_device_change(HWND hwnd); @@ -258,6 +259,7 @@ static INT_PTR analog_ui_handle_init(HWND hwnd, struct analog_def *def) analog_ui_handle_init_label(hwnd); analog_ui_handle_init_dev(hwnd); analog_ui_handle_init_sensitivity(hwnd); + analog_ui_handle_init_invert(hwnd); return TRUE; } @@ -353,6 +355,17 @@ static void analog_ui_handle_init_sensitivity(HWND hwnd) EnableWindow(slider, !mapper_is_analog_absolute(ui->def->tag)); } +static void analog_ui_handle_init_invert(HWND hwnd) +{ + struct analog_ui *ui; + + ui = (struct analog_ui *) GetWindowLongPtr(hwnd, GWLP_USERDATA); + + if (mapper_get_analog_invert(ui->def->tag)) { + SendMessage(GetDlgItem(hwnd, IDC_ANALOG_INVERT), BM_SETCHECK, BST_CHECKED, 0); + } +} + static bool analog_ui_match_device(struct hid_stub *hid) { struct hid_control *controls; diff --git a/src/main/geninput/geninput.def b/src/main/geninput/geninput.def index a5dede8..6ef4cf3 100644 --- a/src/main/geninput/geninput.def +++ b/src/main/geninput/geninput.def @@ -35,6 +35,7 @@ EXPORTS mapper_get_action_map mapper_get_analog_map mapper_get_analog_sensitivity + mapper_get_analog_invert mapper_get_npages mapper_get_nanalogs mapper_get_nlights diff --git a/src/main/geninput/input-config.h b/src/main/geninput/input-config.h index f1c4559..d7fe181 100644 --- a/src/main/geninput/input-config.h +++ b/src/main/geninput/input-config.h @@ -15,6 +15,7 @@ bool mapper_get_action_map( uint8_t action, uint8_t page, struct mapped_action *ma); bool mapper_get_analog_map(uint8_t analog, struct mapped_analog *ma); int32_t mapper_get_analog_sensitivity(uint8_t analog); +bool mapper_get_analog_invert(uint8_t analog); uint8_t mapper_get_nanalogs(void); uint8_t mapper_get_nlights(void); uint8_t mapper_get_npages(void); diff --git a/src/main/geninput/input.c b/src/main/geninput/input.c index 3a2d94c..b37292e 100644 --- a/src/main/geninput/input.c +++ b/src/main/geninput/input.c @@ -144,6 +144,11 @@ int32_t mapper_get_analog_sensitivity(uint8_t analog) return mapper_impl_get_analog_sensitivity(mapper_inst, analog); } +bool mapper_get_analog_invert(uint8_t analog) +{ + return mapper_impl_get_analog_invert(mapper_inst, analog); +} + uint8_t mapper_get_nanalogs(void) { return mapper_impl_get_nanalogs(mapper_inst); diff --git a/src/main/geninput/mapper-s11n.c b/src/main/geninput/mapper-s11n.c index 06b5d39..79094a8 100644 --- a/src/main/geninput/mapper-s11n.c +++ b/src/main/geninput/mapper-s11n.c @@ -74,6 +74,7 @@ static bool mapper_impl_config_load_analogs(struct mapper *m, FILE *f) char *dev_node; struct mapped_analog ma; int32_t sensitivity; + bool invert; uint8_t nanalogs; uint8_t i; @@ -101,8 +102,13 @@ static bool mapper_impl_config_load_analogs(struct mapper *m, FILE *f) return false; } + if (!read_u8(f, &invert)) { + return false; + } + mapper_impl_set_analog_map(m, i, &ma); mapper_impl_set_analog_sensitivity(m, i, sensitivity); + mapper_impl_set_analog_invert(m, i, invert); } free(dev_node); @@ -211,6 +217,7 @@ static void mapper_impl_config_save_analogs(struct mapper *m, FILE *f) { struct mapped_analog ma; int32_t sensitivity; + bool invert; uint8_t nanalogs; uint8_t i; @@ -224,10 +231,12 @@ static void mapper_impl_config_save_analogs(struct mapper *m, FILE *f) write_str(f, ""); } else { sensitivity = mapper_impl_get_analog_sensitivity(m, i); + invert = mapper_impl_get_analog_invert(m, i); write_str(f, hid_stub_get_dev_node(ma.hid)); write_u32(f, &ma.control_no); write_u32(f, &sensitivity); + write_u8(f, &invert); } } } diff --git a/src/main/geninput/mapper.c b/src/main/geninput/mapper.c index d258e21..c3d0214 100644 --- a/src/main/geninput/mapper.c +++ b/src/main/geninput/mapper.c @@ -175,7 +175,6 @@ static void analog_mapping_bind(struct analog_mapping *am) 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: @@ -425,6 +424,15 @@ int32_t mapper_impl_get_analog_sensitivity(struct mapper *m, uint8_t analog) return m->analogs[analog].sensitivity; } +bool mapper_impl_get_analog_invert(struct mapper* m, uint8_t analog) +{ + if (analog >= m->nanalogs) { + return 0; + } + + return m->analogs[analog].invert; +} + uint8_t mapper_impl_get_nanalogs(struct mapper *m) { return m->nanalogs; diff --git a/src/main/geninput/mapper.h b/src/main/geninput/mapper.h index 344a14e..7cc0ad4 100644 --- a/src/main/geninput/mapper.h +++ b/src/main/geninput/mapper.h @@ -57,6 +57,7 @@ bool mapper_impl_get_analog_map( bool mapper_impl_get_action_map( struct mapper *m, uint8_t action, uint8_t page, struct mapped_action *ma); int32_t mapper_impl_get_analog_sensitivity(struct mapper *m, uint8_t analog); +bool mapper_impl_get_analog_invert(struct mapper *m, uint8_t analog); uint8_t mapper_impl_get_nanalogs(struct mapper *m); uint8_t mapper_impl_get_nlights(struct mapper *m); uint8_t mapper_impl_get_npages(struct mapper *m);