Skip to content

Commit

Permalink
xpadneo, core: Remove code duplication
Browse files Browse the repository at this point in the history
Signed-off-by: Kai Krakow <[email protected]>
  • Loading branch information
kakra committed Sep 22, 2024
1 parent bc99c69 commit 70ef8ee
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
10 changes: 2 additions & 8 deletions hid-xpadneo/src/hid-xpadneo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1020,10 +1020,7 @@ static int xpadneo_event(struct hid_device *hdev, struct hid_field *field,
return 0;

keyboard_missing:
if ((xdata->missing_reported & XPADNEO_MISSING_KEYBOARD) == 0) {
xdata->missing_reported |= XPADNEO_MISSING_KEYBOARD;
hid_err(hdev, "keyboard not detected\n");
}
xpadneo_core_missing(xdata, XPADNEO_MISSING_KEYBOARD);

stop_processing:
return 1;
Expand All @@ -1035,10 +1032,7 @@ static int xpadneo_init_hw(struct hid_device *hdev)
struct xpadneo_devdata *xdata = hid_get_drvdata(hdev);

if (!xdata->gamepad) {
if ((xdata->missing_reported & XPADNEO_MISSING_GAMEPAD) == 0) {
xdata->missing_reported |= XPADNEO_MISSING_GAMEPAD;
hid_err(hdev, "gamepad not detected\n");
}
xpadneo_core_missing(xdata, XPADNEO_MISSING_GAMEPAD);
return -EINVAL;
}

Expand Down
1 change: 1 addition & 0 deletions hid-xpadneo/src/xpadneo.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,6 @@ extern int xpadneo_init_consumer(struct xpadneo_devdata *);
extern int xpadneo_init_keyboard(struct xpadneo_devdata *);
extern int xpadneo_init_synthetic(struct xpadneo_devdata *, char *, struct input_dev **);
extern void xpadneo_report(struct hid_device *, struct hid_report *);
extern void xpadneo_core_missing(struct xpadneo_devdata *, u32);

#endif
20 changes: 20 additions & 0 deletions hid-xpadneo/src/xpadneo/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,23 @@ extern void xpadneo_report(struct hid_device *hdev, struct hid_report *report)
input_sync(xdata->keyboard);
}
}

extern void xpadneo_core_missing(struct xpadneo_devdata *xdata, u32 flag)
{
struct hid_device *hdev = xdata->hdev;

if ((xdata->missing_reported & flag) == 0) {
xdata->missing_reported |= flag;
switch (flag) {
case XPADNEO_MISSING_GAMEPAD:
hid_err(hdev, "gamepad not detected\n");
break;
case XPADNEO_MISSING_KEYBOARD:
hid_err(hdev, "keyboard not detected\n");
break;
default:
hid_err(hdev, "unexpected subdevice missing: %d\n", flag);
}
}

}

0 comments on commit 70ef8ee

Please sign in to comment.