/*****************************************************************************\
*   This program is free software; you can redistribute it and/or modify      *
*   it under the terms of the GNU General Public License as published by      *
*   the Free Software Foundation; either version 2 of the License, or         *
*   (at your option) any later version.                                       *
*                                                                             *
*   This program is distributed in the hope that it will be useful,           *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of            *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
*   GNU General Public License for more details.                              *
*                                                                             *
*   You should have received a copy of the GNU General Public License         *
*   along with this program; if not, write to the Free Software Foundation,   *
*   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.            *
\*****************************************************************************/

#include <sys/types.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/kd.h>
#include <unistd.h>
#include <stdlib.h>

/* Tastatur-LEDs ein- und ausschalten
   Programmaufruf: leds Led-Wert (s.u.) Anzeigezeit 
   Keyboard layout:    [NUM]   [CAP]   [SCR]
   Value:                2       4       1

   Geht nur, wenn man auch die richtige Zugriffsberechtigung
   hat (bei /dev/console eigentlich nur root).
*/
#define SCRLED 1
#define NUMLED 2
#define CAPLED 4

int main(int argc, char *argv[]) 
  {
  int fd, time = 1000;
  char leds = 7, oldleds;
  fd = open("/dev/console",O_RDONLY);
  if (argc > 2)
    {
    leds = atoi(argv[1]);
    time = atoi(argv[2]);
    }

  leds = leds%8;
  ioctl(fd, KDGETLED, &oldleds);
  ioctl(fd, KDSETLED, leds);
  usleep(1000*time);
  ioctl(fd, KDSETLED, oldleds);
  close(fd);
  return(0);
  }

