Chips-fr / uae4arm-rpi

Port of uae4arm on Raspberry Pi and Libretro
73 stars 41 forks source link

Keyboard Leds dont Work (Fix inside) #17

Open neurorulez opened 8 years ago

neurorulez commented 8 years ago

For making the Capslock LED working we need to modify the file "src/od-pandora/pandora.cpp" Firs add those includes (need to put < > en the include name, if i use it, the text disapear here.

ifdef CAPSLOCK_DEBIAN_WORKAROUND

include linux/kd.h

include sys/ioctl.h

endif

After line 122 add the new var: static unsigned long kb_led_status; the code looks like

ifdef CAPSLOCK_DEBIAN_WORKAROUND

static int capslock = 0; static unsigned long kb_led_status;

endif

After line 942 add: if (iAmigaKeyCode == AK_CAPSLOCK) { ioctl(NULL, KDGETLED, &kb_led_status); kb_led_status |= LED_CAP; ioctl(NULL, KDSETLED, kb_led_status); } the code looks like

ifdef CAPSLOCK_DEBIAN_WORKAROUND

            if (iAmigaKeyCode == AK_CAPSLOCK && uae4all_keystate[AK_CAPSLOCK] == 1) { iAmigaKeyCode = -1; capslock = 1; }
            if (iAmigaKeyCode == AK_CAPSLOCK) { ioctl(NULL, KDGETLED, &kb_led_status); kb_led_status |= LED_CAP; ioctl(NULL, KDSETLED, kb_led_status); }

endif

After line 1014 add: if (iAmigaKeyCode == AK_CAPSLOCK) { ioctl(NULL, KDGETLED, &kb_led_status); kb_led_status &= ~LED_CAP; ioctl(NULL, KDSETLED, kb_led_status); } the code looks like

ifdef CAPSLOCK_DEBIAN_WORKAROUND

            if (iAmigaKeyCode == AK_CAPSLOCK) if (capslock==0) iAmigaKeyCode = -1; else capslock = 0;
            if (iAmigaKeyCode == AK_CAPSLOCK) { ioctl(NULL, KDGETLED, &kb_led_status); kb_led_status &= ~LED_CAP; ioctl(NULL, KDSETLED, kb_led_status); }

endif

With those changes, Capslock LED is working now.

For the FD & HD Leds we need to modify src/od-pandora/pandora_gui.cpp (Same than the first, need to use < > in the names)

ifdef RASPBERRY

include linux/kd.h

include sys/ioctl.h

endif

Then in line 1347 modify the empty gui_led process, leaving it with this code: void gui_led (int led, int on) {

ifdef RASPBERRY

static unsigned long kb_led_status;

ioctl(NULL, KDGETLED, &kb_led_status);
switch(led)
{
 case LED_DF0:
     if(on) kb_led_status |= LED_SCR;  else kb_led_status &= ~LED_SCR;
      break;
 case LED_HD:
      if(on) kb_led_status |= LED_NUM; else kb_led_status &= ~LED_NUM;
      break;
}
ioctl(NULL, KDSETLED, kb_led_status);

endif

}

And then modify the next process after the line 1363 add this new "case" for the fd: case LED_DF0: case LED_DF1: case LED_DF2: case LED_DF3: gui_led(LED_DF0,1); break;

Inside the "case LED_HD" after the line 1371 add this line: gui_led(LED_HD,1); the code looks like: case LED_HD: if (status == 0) { hd_resetcounter--; if (hd_resetcounter > 0) return; } gui_data.hd = status; hd_resetcounter = 2; gui_led(LED_HD,1); break;

And after the switch, add those lines to turn off the leds gui_led(LED_HD,0); gui_led(LED_DF0,0);

The gui_flicker_led must lokks like this: void gui_flicker_led (int led, int unitnum, int status) { static int hd_resetcounter;

switch(led) { case -1: // Reset HD and CD gui_data.hd = 0; break;

case LED_POWER:
  break;
case LED_DF0:
case LED_DF1:
case LED_DF2:
case LED_DF3:
gui_led(LED_DF0,1);
  break;
case LED_HD:
  if (status == 0) {
    hd_resetcounter--;
    if (hd_resetcounter > 0)
      return;
  }
  gui_data.hd = status;
  hd_resetcounter = 2;
  gui_led(LED_HD,1);
  break;

} gui_led(LED_HD,0); gui_led(LED_DF0,0); }

Whith this the leds will work.

One more thing, i changed the Mouse Swich & Menu keys to Alt-gr + F9 & Alt-gr + F10, for the peopple with the Keyrath and original Amiga Keyboard. (To return from the gui to the emulator, i left only F10).

Fixes.zip (Idea taken from the n0rt0nthec4t code published in the Rasberry Pi Forum).

n0rt0nthec4t commented 8 years ago

See some amendments posted in the Raspberry Pi forum based on your idea around the caps lock key

prefim commented 8 years ago

Hoping this gets added real soon. Vital when using original amiga hardware with something like Keyrah.

Chips-fr commented 8 years ago

Caps lock is not working anymore since latest merge of tomB version, moreover previous version was messing the caps lock management in X11... hence currently i'm stuck here with no time for this...

n0rt0nthec4t commented 8 years ago

I had fixed the caps key working in my code for led status. Would you consider checking this out for a committ to the code?

prefim commented 8 years ago

I don't mind giving it a go if I can get it compiled. There are some guys in our facebook group who will probably understand it better though. Any thoughts on getting the floppy and HDD access leds going as well (they are num lock and scroll lock).

Chips-fr commented 8 years ago

You can always propose, i will see... Note that the problem is not in uae4arm but in debian, there are quite some informations and correction you can find on internet about this, but as soon as SDL is started thoses correction has no more effect... from what i understand debian even add a dirty workaround in SDL... hence the mess. Ed: http://unix.stackexchange.com/questions/136817/caps-lock-led-not-working-on-linux-console

n0rt0nthec4t commented 8 years ago

here is my mods to the pandora.cpp file (based off your latest commits) which allow the capslock key and led to function as they should. Mirrors the system capslock state upon startup also pandora.cpp.zip

prefim commented 8 years ago

Hi n0rt0nthec4t, The caps lock now functions as expected but the LED doesn't light when enabled. Outside of the app, in command line, its lit when enabled.

Any thoughts on FDD and HDD to scroll and num lock?

n0rt0nthec4t commented 8 years ago

Not sure why. The code I made only has the caps lock key/led working inside the emulator when running ie. it in the configure menu

I posted a link in the uae4arm forum thread on raspberrypi.org which has the hdd / fdd code

Tested on kernel 4.4.c

prefim commented 8 years ago

I tested it on a fresh rasbian install with just the requirements for uae4arm installed. I'm not seeing keyboard leds in gui or command prompt although caps lock does toggle caps (just not the LED). After i run the fix for LEDs in CLI which is

echo keycode 58 = Caps_Lock |sudo loadkeys -

I can get caps and num lock LEDs to work in commandline, not the gui or inside workbench.

I've just found the led code from the forum so will give that a go, cheers.

On 28 August 2016 at 23:38, n0rt0nthec4t notifications@github.com wrote:

Not sure why. The code I made only has the caps lock key/led working inside the emulator when running ie. it in the configure menu

I posted a link in the uae4arm forum thread on raspberrypi.org which has the hdd / fdd code

Tested on kernel 4.4.c

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Chips-fr/uae4arm-rpi/issues/17#issuecomment-243003953, or mute the thread https://github.com/notifications/unsubscribe-auth/AUAKi1ORl_A5xDLBgWQiHi236gh0TfXXks5qkg3sgaJpZM4Ikf4L .

n0rt0nthec4t commented 8 years ago

If running on kernel 4.4.x you'll need to include a new dev rule as per the below thread to allow the scroll lock LED to function

https://github.com/raspberrypi/linux/issues/1516

I could never make the "echo key code 58 =..." work on the latest Debian releases. I did have to create a complete new keymap to allow the correct keys to work with my A600 UK keyboard via keyrah v2 interface

Does using "setleds +L +caps" turn on the caps lock led and "setleds +L -caps" turn it off via the commandline?

That is essential what my code is doing

prefim commented 8 years ago

Yes, using setleds I can enable either the caps or num lock lights. and your code compiled and I can use numlock for HDD or FDD. scroll lock doesnt function in commandline with setleds. I'll check that dev rule to see if it fixes the scroll lock. Just need to find out how all thats done! Thanks for all the help BTW.

On 29 August 2016 at 08:50, n0rt0nthec4t notifications@github.com wrote:

If running on kernel 4.4.x you'll need to include a new dev rule as per the below thread to allow the scroll lock LED to function

raspberrypi/linux#1516 https://github.com/raspberrypi/linux/issues/1516

I could never make the "echo key code 58 =..." work on the latest Debian releases. I did have to create a complete new keymap to allow the correct keys to work with my A600 UK keyboard via keyrah v2 interface

Does using "setleds +L +caps" turn on the caps lock led and "setleds +L -caps" turn it off via the commandline?

That is essential what my code is doing

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Chips-fr/uae4arm-rpi/issues/17#issuecomment-243055853, or mute the thread https://github.com/notifications/unsubscribe-auth/AUAKizaGMtY3TrsinvsqeOZ5CuxPMdA4ks5qko8tgaJpZM4Ikf4L .

n0rt0nthec4t commented 8 years ago

50-leds.rules.zip

Attached is mine (zipped) Correct, is placed in /etc/udev/rules.d

Have you done a "udevadm control --reload-rules"?

Didnt think I had to do anything more than that.

prefim commented 8 years ago

Thanks.that got it working. :)

maybe there was a typo between your file and mine. I had done the reload rules and rebooted (just the reload rules didnt enable this either) but it looks like its all working now! Cheers!

midwan commented 8 years ago

This solution works fine if uae4arm is launched from within X11 (or with xinit), but it doesn't seem to work if launched from the console. Maybe it's related to the input method used (X11 vs fbcon), but I haven't had the time to find out where exactly this is happening.

I tried using SDL input keys only, as is the case with the Android port, but it didn't seem to help in this case.

Have you tested this from a console, outside of X11?

n0rt0nthec4t commented 8 years ago

Yes, i don't even use X11 on my install.. Boots straight into uae4arm... (raspbian jessie install with 4.4.x kernel) Thanks for the feedback, I'll see what more testing i can do,.