Results 1 to 3 of 3

Thread: flashing LEDs

  1. #1
    Join Date
    Dec 2009
    Beans
    114
    Distro
    Ubuntu 9.10 Karmic Koala

    flashing LEDs

    Anyone ever found anything to flash the keyboard leds? I've done a bit of googling and found a bunch of stuff that seems out-dated, eg kernel modules that reference non-existent includes, and "ledcontrol" which appears to do nothing on my system.

    XChangeKeyboardControl() can apparently do this "if possible", but in fact it will not change anything including the bell:
    Code:
           Display *XDisplay = XOpenDisplay(NULL);
           KCntl.bell_percent = 50;
            KCntl.bell_duration = 150;
            XChangeKeyboardControl(XDisplay,KBBellPercent | KBBellDuration,&KCntl);
            printf("%%: %d pitch: %u dur: %u\n",KState.bell_percent,KState.bell_pitch,KState.bell_duration);
    None of the values are changed, and the same is true for the LEDS. The most I seem to be able to do with Xlib is get information.

    (which occasionally my bell does ring, god knows how...)
    Last edited by akashiraffee; January 4th, 2010 at 10:20 PM.
    (\ /)
    (O.o)
    (> <)
    This is Bunny. Copy Bunny into your signature to help him on his way to world domination.

  2. #2
    Join Date
    Dec 2009
    Beans
    114
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: flashing LEDs

    Wow, I just learned all about ioctl and spend some time paging thru the kernel source and c include headers. Now that's *nix programming.

    Anyhow, there's some old stuff out there on the web that may not work, so for posterity:
    Code:
    #include <stdio.h>
    #include <unistd.h>        /* close */
    #include <fcntl.h>        /* open */
    #include <errno.h>        /* perror */
    #include <linux/kd.h>        /* Keyboard macros */
    #include <sys/ioctl.h>        /* ioctl */
    
    int main() {
        int tty = open("/dev/console", 0), led;
        unsigned long int arg;
    
        if (tty<3) {
            perror("open: ");
            return -1;
        }
        if (ioctl(tty,KDGKBTYPE, &arg) > 0) perror("ioctl: ");
        if (arg == KB_101) puts("You have a 101 key keyboard.");
    
        for (led=1; led<9; led++) {
            if (ioctl(tty,KDSETLED, led) > 0) perror("ioctl led on: ");
            printf("LED %d on...hit enter", led);
            getchar();
            if (ioctl(tty,KDSETLED, led+0xff) > 0) perror("ioctl led off: ");
            printf("off (hit enter)\n");
            getchar();
        }
    
        close(tty);
    
        return 0;
    }
    Most people have a 101 key keyboard, so the first ioctl is just a check. The LED numbers are bitmasks; on my keyboard there are three: 1,2, and 4 -- 3, 5, 6, and 7 set patterns of multiple lights. 8 doesn't do anything, but I suppose it will if you have a forth LED. This doesn't actually set the CAPLOCK or anything, it just flashes the lights.

    This is pretty handy if you need to be alerted but have problems with the linux soundsystem, such that you can't play a wav while watching youtube

    If I keep digging maybe I'll find the bell
    Last edited by akashiraffee; January 5th, 2010 at 06:00 PM.
    (\ /)
    (O.o)
    (> <)
    This is Bunny. Copy Bunny into your signature to help him on his way to world domination.

  3. #3
    Join Date
    Apr 2007
    Location
    Stockholm, Sweden
    Beans
    2,042

    Re: flashing LEDs

    Cool, now create a little game with these!
    nissband.com my post-metal/instrumental

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •