Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Commit

Permalink
check analog user calibration for plausibility; clone controlers may …
Browse files Browse the repository at this point in the history
…report having a user calibration but return all zero values
  • Loading branch information
bitmeal committed Nov 21, 2020
1 parent 5371d38 commit 7f984ed
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/hid-nintendo.c
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,14 @@ static int joycon_request_calibration(struct joycon_ctlr *ctlr)
&ctlr->left_stick_cal_x,
&ctlr->left_stick_cal_y,
true);
if (ret) {

/* check wether read succeeded and perform plausibility check for retrieved values */
if (ret ||
ctlr->left_stick_cal_x.min >= ctlr->left_stick_cal_x.center ||
ctlr->left_stick_cal_x.center >= ctlr->left_stick_cal_x.max ||
ctlr->left_stick_cal_y.min >= ctlr->left_stick_cal_y.center ||
ctlr->left_stick_cal_y.center >= ctlr->left_stick_cal_y.max
) {
hid_warn(ctlr->hdev,
"Failed to read left stick cal, using dflts; e=%d\n",
ret);
Expand All @@ -772,7 +779,14 @@ static int joycon_request_calibration(struct joycon_ctlr *ctlr)
&ctlr->right_stick_cal_x,
&ctlr->right_stick_cal_y,
false);
if (ret) {

/* check wether read succeeded and perform plausibility check for retrieved values */
if (ret ||
ctlr->right_stick_cal_x.min >= ctlr->right_stick_cal_x.center ||
ctlr->right_stick_cal_x.center >= ctlr->right_stick_cal_x.max ||
ctlr->right_stick_cal_y.min >= ctlr->right_stick_cal_y.center ||
ctlr->right_stick_cal_y.center >= ctlr->right_stick_cal_y.max
) {
hid_warn(ctlr->hdev,
"Failed to read right stick cal, using dflts; e=%d\n",
ret);
Expand Down

0 comments on commit 7f984ed

Please sign in to comment.