mirror of
git://projects.qi-hardware.com/openwrt-xburst.git
synced 2024-11-27 17:15:00 +02:00
[package] rssileds: improve performance
LEDs brightness is now only updated if the value actually changed, thus reducing the number of fwrite syscalls significantly. Signed-off-by: Daniel Golle <dgolle@allnet.de> git-svn-id: svn://svn.openwrt.org/openwrt/trunk@33766 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
parent
8178ce6c3b
commit
c663cbf571
@ -8,7 +8,7 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=rssileds
|
||||
PKG_VERSION:=0.1
|
||||
PKG_VERSION:=0.2
|
||||
PKG_RELEASE:=1
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
@ -70,6 +70,32 @@ void log_rules(rule_t *rules)
|
||||
}
|
||||
}
|
||||
|
||||
int set_led(struct led *led, unsigned char value)
|
||||
{
|
||||
char buf[8];
|
||||
|
||||
if ( ! led )
|
||||
return -1;
|
||||
|
||||
if ( ! led->controlfd )
|
||||
return -1;
|
||||
|
||||
if ( led->state == value )
|
||||
return 0;
|
||||
|
||||
snprintf(buf, 8, "%d", value);
|
||||
|
||||
rewind(led->controlfd);
|
||||
|
||||
if ( ! fwrite(buf, sizeof(char), strlen(buf), led->controlfd) )
|
||||
return -2;
|
||||
|
||||
fflush(led->controlfd);
|
||||
led->state=value;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int init_led(struct led **led, char *ledname)
|
||||
{
|
||||
struct led *newled;
|
||||
@ -104,6 +130,13 @@ int init_led(struct led **led, char *ledname)
|
||||
newled->controlfd = bfp;
|
||||
|
||||
*led = newled;
|
||||
|
||||
if ( set_led(newled, 255) )
|
||||
goto cleanup_fp;
|
||||
|
||||
if ( set_led(newled, 0) )
|
||||
goto cleanup_fp;
|
||||
|
||||
return 0;
|
||||
|
||||
cleanup_fp:
|
||||
@ -124,29 +157,6 @@ void close_led(struct led **led)
|
||||
(*led)=NULL;
|
||||
}
|
||||
|
||||
int set_led(struct led *led, unsigned char value)
|
||||
{
|
||||
char buf[8];
|
||||
|
||||
if ( ! led )
|
||||
return -1;
|
||||
|
||||
if ( ! led->controlfd )
|
||||
return -1;
|
||||
|
||||
snprintf(buf, 8, "%d", value);
|
||||
|
||||
rewind(led->controlfd);
|
||||
|
||||
if ( ! fwrite(buf, sizeof(char), strlen(buf), led->controlfd) )
|
||||
return -2;
|
||||
|
||||
fflush(led->controlfd);
|
||||
led->state=value;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int quality(const struct iwinfo_ops *iw, const char *ifname)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user