[bootlin/training-materials updates] master: nunchuk-mpd-client: be less strict on the expected joystick ABS_X/ABS_Y values (fa2529fa)
Thomas Petazzoni
thomas.petazzoni at bootlin.com
Fri Sep 30 16:46:06 CEST 2022
Repository : https://github.com/bootlin/training-materials
On branch : master
Link : https://github.com/bootlin/training-materials/commit/fa2529fa1a29c77cfc40edc1c5b1fe685d76d258
>---------------------------------------------------------------
commit fa2529fa1a29c77cfc40edc1c5b1fe685d76d258
Author: Thomas Petazzoni <thomas.petazzoni at bootlin.com>
Date: Fri Sep 30 16:44:51 2022 +0200
nunchuk-mpd-client: be less strict on the expected joystick ABS_X/ABS_Y values
With my Nunchuk, I never had a 0 or 255 value in ABS_X, the min I
could get was 1, the max was 254. To accomodate for this, be a bit
more flexible on the values that trigger a song next/prev. For
consistency, we do the same for ABS_Y for volume up/down.
Signed-off-by: Thomas Petazzoni <thomas.petazzoni at bootlin.com>
>---------------------------------------------------------------
fa2529fa1a29c77cfc40edc1c5b1fe685d76d258
lab-data/embedded-linux/appdev/nunchuk-mpd-client.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/lab-data/embedded-linux/appdev/nunchuk-mpd-client.c b/lab-data/embedded-linux/appdev/nunchuk-mpd-client.c
index 3586eb3c..2bde034d 100644
--- a/lab-data/embedded-linux/appdev/nunchuk-mpd-client.c
+++ b/lab-data/embedded-linux/appdev/nunchuk-mpd-client.c
@@ -128,16 +128,16 @@ int main(int argc, char ** argv)
case EV_ABS:
switch (event.code) {
case ABS_Y:
- if (event.value == 255) {
+ if (event.value > 250) {
printf("Volume up: ");
change_volume(conn, 5);
- } else if (event.value == 0) {
+ } else if (event.value < 5) {
printf("Volume down: ");
change_volume(conn, -5);
}
break;
case ABS_X:
- if (event.value == 255) {
+ if (event.value > 250) {
if (!mpd_run_next(conn)) {
printf("No next song. Aborting\n");
exit(handle_error(conn));
@@ -146,7 +146,7 @@ int main(int argc, char ** argv)
print_current_song(conn);
}
}
- else if (event.value == 0) {
+ else if (event.value < 5) {
if (!mpd_run_previous(conn)) {
printf("No previous song. Aborting\n");
exit(handle_error(conn));
More information about the training-materials-updates
mailing list