Skip to content

Commit

Permalink
Change status of leds at once. Previous sequential changes led to los…
Browse files Browse the repository at this point in the history
…t updates.
  • Loading branch information
wolkenschieber committed Mar 7, 2021
1 parent 4abd37c commit 886714d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# Change log

## Version 0.7 to 0.8 (Mar 07 2021)

* Set status of LEDs at once


## Version 0.6 to 0.7 (Mar 06 2021)

* Parse format of kernel 2.1+
* Dropped format of older kernels


## Version 0.5 to 0.6 (Dec 11 1999)

* Rewrote much of the `update_netproc` code, now faster (?) and smaller
Expand Down
38 changes: 21 additions & 17 deletions ifled.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* ifled - InterfaceLED
* Copyright (C)1999 Mattias Wadman <[email protected]>
* 2021 Wolkenschieber <https://wolkenschieber.github.io>
*
* 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
Expand Down Expand Up @@ -30,7 +31,8 @@


const char *banner =
"ifled v0.7 - (c)1999 Mattias Wadman <[email protected]>\n"
"ifled v0.8 - (c)1999 Mattias Wadman <[email protected]>\n"
" 2021 Wolkenschieber <https://wolkenschieber.github.io>\n"
"This program is distributed under the terms of GPL.\n";
const char *help =
"%sUsage: %s tty interface [options]\n"
Expand Down Expand Up @@ -83,16 +85,14 @@ void freakout(char *why)
exit(1);
}

void set_led(char mode,char flag)
{
unsigned char last_leds;
ioctl(ttyfd,KDGETLED,&last_leds);
char set_led(char leds, char mode,char flag)
{
if(options & OPT_INVERT)
mode = !mode;
if(mode)
ioctl(ttyfd,KDSETLED,last_leds|flag);
else
ioctl(ttyfd,KDSETLED,last_leds&~flag);
if(mode)
return leds|flag;
else
return leds&~flag;
}

void update_netproc(char *interface)
Expand Down Expand Up @@ -146,27 +146,31 @@ char is_changed(char temp)
void update_leds(char *tty)
{
char temp;
unsigned char real_status_leds[3] = {K_CAPSLOCK,K_NUMLOCK,K_SCROLLLOCK};
unsigned char real_status;
unsigned char led_values;
unsigned char status_leds[3] = {K_CAPSLOCK,K_NUMLOCK,K_SCROLLLOCK};
unsigned char leds[3] = {LED_NUM,LED_CAP,LED_SCR};

ioctl(ttyfd,KDGETLED,&led_values);

for(temp=0;temp < 3;temp++)
{
if(led_config[temp] == IF_NONE && options & OPT_ALTKBCODE)
{
ioctl(ttyfd,KDGKBLED,&real_status);
if(real_status & real_status_leds[temp])
set_led(TRUE,leds[temp]);
if(led_values & status_leds[temp])
led_values = set_led(led_values,TRUE,leds[temp]);
else
set_led(FALSE,leds[temp]);
led_values = set_led(led_values,FALSE,leds[temp]);
continue;
}
else if(led_config[temp] == IF_NONE)
continue;
if(is_changed(led_config[temp]))
set_led(TRUE,leds[temp]);
led_values = set_led(led_values,TRUE,leds[temp]);
else
set_led(FALSE,leds[temp]);
led_values = set_led(led_values,FALSE,leds[temp]);
}

ioctl(ttyfd,KDSETLED,led_values);
memcpy(&l_if_info,&if_info,sizeof(if_info));
}

Expand Down

0 comments on commit 886714d

Please sign in to comment.