Mercurial > audlegacy-plugins
changeset 411:78a5e9c37469 trunk
[svn] - Rework and clean up code
- Add generic support for /sys/class/leds/ LEDs, used for Apple PMU and SMU
- Make rocklight configurable in configure
author | hansmi |
---|---|
date | Sat, 06 Jan 2007 07:40:46 -0800 |
parents | 4333f0bbcc55 |
children | 108e169b7e4b |
files | ChangeLog configure.ac src/rocklight/Makefile src/rocklight/apple_pmu.c src/rocklight/rocklight.c src/rocklight/rocklight.h src/rocklight/sysled.c src/rocklight/thinklight.c src/rocklight/thinklight.h |
diffstat | 9 files changed, 187 insertions(+), 141 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Sat Jan 06 02:00:15 2007 -0800 +++ b/ChangeLog Sat Jan 06 07:40:46 2007 -0800 @@ -1,3 +1,11 @@ +2007-01-06 10:00:15 +0000 William Pitcock <nenolod@nenolod.net> + revision [898] + - select waves randomly + + trunk/src/rovascope/actuatorbin.c | 8 +------- + 1 file changed, 1 insertion(+), 7 deletions(-) + + 2007-01-06 09:59:37 +0000 William Pitcock <nenolod@nenolod.net> revision [896] - actuatorbin.c was missing.
--- a/configure.ac Sat Jan 06 02:00:15 2007 -0800 +++ b/configure.ac Sat Jan 06 07:40:46 2007 -0800 @@ -320,11 +320,15 @@ dnl *** Rocklight -AC_CHECK_FILE([/proc/acpi/ibm/light], [VISUALIZATION_PLUGINS="$VISUALIZATION_PLUGINS rocklight" - LEDCODE=thinklight.c]) -AC_CHECK_FILE([/sys/class/leds/pmu-front-led/brightness], [VISUALIZATION_PLUGINS="$VISUALIZATION_PLUGINS rocklight" - LEDCODE=apple_pmu.c]) -AC_SUBST(LEDCODE) +AC_ARG_ENABLE(rocklight, + AS_HELP_STRING([--disable-rocklight], [disable Rocklight vis plugin (default=enabled)]), + [enable_rocklight="$enableval"], + [enable_rocklight="yes"] +) + +if test "$enable_rocklight" = "yes"; then + VISUALIZATION_PLUGINS="$VISUALIZATION_PLUGINS rocklight" +fi dnl *** LIRC client libraries
--- a/src/rocklight/Makefile Sat Jan 06 02:00:15 2007 -0800 +++ b/src/rocklight/Makefile Sat Jan 06 07:40:46 2007 -0800 @@ -7,7 +7,7 @@ LIBADD = $(GTK_LIBS) -SOURCES = rocklight.c $(LEDCODE) +SOURCES = rocklight.c thinklight.c sysled.c OBJECTS = ${SOURCES:.c=.o}
--- a/src/rocklight/apple_pmu.c Sat Jan 06 02:00:15 2007 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -/*************************************************************************** - * apple_pmu.c - * - * Sun Dec 03 01:07:42 2006 - * Copyright 2006 Tony 'Chainsaw' Vroon - * chainsaw@gentoo.org - ****************************************************************************/ - -/* - * 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 Library 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <unistd.h> - -int thinklight_open(void) { - return open("/sys/class/leds/pmu-front-led/brightness",O_RDWR); -} - -void thinklight_close(int fd) { - close(fd); -} - -int thinklight_set(int fd, int state) { - return write(fd,state?"255\n":"0\n",state?2:4); -} - -int thinklight_get(int fd) { - char buf[256]; - int ret=read(fd,&buf,sizeof(buf)); - - if(atoi(buf) == 255) - return 1; - else - return 0; -}
--- a/src/rocklight/rocklight.c Sat Jan 06 02:00:15 2007 -0800 +++ b/src/rocklight/rocklight.c Sat Jan 06 07:40:46 2007 -0800 @@ -1,13 +1,7 @@ -/*************************************************************************** - * rocklight.c +/* + * Copyright (C) 2004 Benedikt 'Hunz' Heinz <rocklight@hunz.org> + * Copyright (C) 2006 Tony Vroon <chainsaw@gentoo.org> * - * Sun Dec 26 18:26:59 2004 - * Copyright 2004 Benedikt 'Hunz' Heinz - * rocklight@hunz.org - * Audacious implementation by Tony Vroon <chainsaw@gentoo.org> in August 2006 - ****************************************************************************/ - -/* * 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 @@ -22,54 +16,114 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - + +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + #include "audacious/plugin.h" -#include "thinklight.h" +#include "rocklight.h" + +enum type { + NONE = 0, + THINKLIGHT, + SYSLED, +}; static int fd, last, state; +static enum type type; static void rocklight_init(void) { - fd=thinklight_open(); + type = NONE; + + fd = open("/proc/acpi/ibm/light", O_RDWR); + if (fd >= 0) { + type = THINKLIGHT; + return; + } + + fd = open("/sys/class/leds/pmu-front-led/brightness", O_RDWR); + if (fd >= 0) { + type = SYSLED; + return; + } + + fd = open("/sys/class/leds/smu-front-led/brightness", O_RDWR); + if (fd >= 0) { + type = SYSLED; + return; + } } static void rocklight_cleanup(void) { - thinklight_close(fd); + close(fd); } static void rocklight_playback_start(void) { - last=state=thinklight_get(fd); + /* Get original value */ + switch (type) { + case THINKLIGHT: + last = state = thinklight_get(fd); + break; + + case SYSLED: + last = state = sysled_get(fd); + break; + + default: + break; + } } static void rocklight_playback_stop(void) { - if(last!=state) - thinklight_set(fd,state); + if (last == state) return; + + /* Reset to original value */ + switch (type) { + case THINKLIGHT: + thinklight_set(fd, state); + break; + + case SYSLED: + sysled_set(fd, state); + break; + + default: + break; + } } static void rocklight_render_freq(gint16 data[2][256]) { - int new=((data[0][0]+data[1][0])>>7)>=80?1:0; - - if(new!=last) { - thinklight_set(fd,new); - last=new; + int new = ((data[0][0] + data[1][0]) >> 7) >= 80? 1:0; + + if (new == last) return; + last = new; + + switch (type) { + case THINKLIGHT: + thinklight_set(fd, new); + break; + + case SYSLED: + sysled_set(fd, new); + break; + + default: + break; } } -VisPlugin rocklight_vp = { - NULL, - NULL, - 0, - "RockLight", - 0, - 2, - rocklight_init, - rocklight_cleanup, - NULL, - NULL, - NULL, - rocklight_playback_start, - rocklight_playback_stop, - NULL, - rocklight_render_freq +static VisPlugin rocklight_vp = { + .description = "RockLight", + + .num_pcm_chs_wanted = 0, + .num_freq_chs_wanted = 2, + + .init = rocklight_init, + .cleanup = rocklight_cleanup, + .playback_start = rocklight_playback_start, + .playback_stop = rocklight_playback_stop, + .render_freq = rocklight_render_freq }; VisPlugin *get_vplugin_info(void) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/rocklight/rocklight.h Sat Jan 06 07:40:46 2007 -0800 @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2004 Benedikt 'Hunz' Heinz <rocklight@hunz.org> + * + * 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 Library 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef _ROCKLIGHT_H +#define _ROCKLIGHT_H + +int thinklight_set(int fd, int state); +int thinklight_get(int fd); + +int sysled_set(int fd, int state); +int sysled_get(int fd); + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/rocklight/sysled.c Sat Jan 06 07:40:46 2007 -0800 @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2006 Tony Vroon <chainsaw@gentoo.org> + * Copyright (C) 2007 Michael Hanselmann <audacious@hansmi.ch> + * + * 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 Library 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include <unistd.h> +#include <stdlib.h> + +#include "rocklight.h" + +int sysled_set(int fd, int state) { + if (state) { + return write(fd, "255\n", 4); + } else { + return write(fd, "0\n", 2); + } +} + +int sysled_get(int fd) { + char buf[256]; + int ret = read(fd, &buf, sizeof(buf)); + + return (strtol(buf, NULL, 10) == 255); +}
--- a/src/rocklight/thinklight.c Sat Jan 06 02:00:15 2007 -0800 +++ b/src/rocklight/thinklight.c Sat Jan 06 07:40:46 2007 -0800 @@ -28,29 +28,27 @@ #include <fcntl.h> #include <unistd.h> -int thinklight_open(void) { - return open("/proc/acpi/ibm/light",O_RDWR); -} - -void thinklight_close(int fd) { - close(fd); -} +#include "rocklight.h" int thinklight_set(int fd, int state) { - return write(fd,state?"on\n":"off\n",state?3:4); + if (state) { + return write(fd, "on\n", 3); + } else { + return write(fd, "off\n", 4); + } } int thinklight_get(int fd) { char buf[256]; - int ret=read(fd,&buf,sizeof(buf)); - - if(ret<0) + int ret = read(fd, &buf, sizeof(buf)); + + if (ret < 0) return ret; - else if(ret<11) + else if (ret < 11) return -23; - else if(buf[10]=='f') + else if (buf[10] == 'f') return 0; - else if(buf[10]=='n') + else if (buf[10] == 'n') return 1; else return -42;
--- a/src/rocklight/thinklight.h Sat Jan 06 02:00:15 2007 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ -/*************************************************************************** - * thinklight.h - * - * Sun Dec 26 17:01:00 2004 - * Copyright 2004 Benedikt 'Hunz' Heinz - * rocklight@hunz.org - * $Id: thinklight.h,v 1.2 2005/03/26 21:29:17 hunz Exp $ - ****************************************************************************/ - -/* - * 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 Library 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef _THINKLIGHT_H -#define _THINKLIGHT_H - -int thinklight_open(void); -void thinklight_close(int fd); -int thinklight_set(int fd, int state); -int thinklight_get(int fd); - -#endif /* _THINKLIGHT_H */