annotate src/rocklight/rocklight.c @ 3114:d243a544f60b

Warning fix from Mark Loeser <halcy0n@gentoo.org>.
author Tony Vroon <chainsaw@gentoo.org>
date Mon, 04 May 2009 01:06:21 +0100
parents 3134a0987162
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
411
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
1 /*
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
2 * Copyright (C) 2004 Benedikt 'Hunz' Heinz <rocklight@hunz.org>
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
3 * Copyright (C) 2006 Tony Vroon <chainsaw@gentoo.org>
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
4 *
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
5 * This program is free software; you can redistribute it and/or modify
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
7 * the Free Software Foundation; either version 2 of the License, or
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
8 * (at your option) any later version.
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
9 *
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
13 * GNU Library General Public License for more details.
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
14 *
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
16 * along with this program; if not, write to the Free Software
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
18 */
411
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
19
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
20 #include <sys/types.h>
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
21 #include <sys/stat.h>
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
22 #include <fcntl.h>
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
23
2971
3134a0987162 - changed include path from audacious to audlegacy.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 1950
diff changeset
24 #include <audlegacy/plugin.h>
411
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
25 #include "rocklight.h"
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
26
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
27 enum type {
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
28 NONE = 0,
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
29 THINKLIGHT,
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
30 SYSLED,
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
31 };
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
32
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
33 static int fd, last, state;
411
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
34 static enum type type;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
35
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
36 static void rocklight_init(void) {
411
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
37 type = NONE;
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
38
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
39 fd = open("/proc/acpi/ibm/light", O_RDWR);
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
40 if (fd >= 0) {
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
41 type = THINKLIGHT;
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
42 return;
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
43 }
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
44
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
45 fd = open("/sys/class/leds/pmu-front-led/brightness", O_RDWR);
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
46 if (fd >= 0) {
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
47 type = SYSLED;
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
48 return;
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
49 }
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
50
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
51 fd = open("/sys/class/leds/smu-front-led/brightness", O_RDWR);
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
52 if (fd >= 0) {
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
53 type = SYSLED;
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
54 return;
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
55 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
56 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
57
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
58 static void rocklight_cleanup(void) {
411
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
59 close(fd);
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
60 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
61
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
62 static void rocklight_playback_start(void) {
411
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
63 /* Get original value */
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
64 switch (type) {
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
65 case THINKLIGHT:
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
66 last = state = thinklight_get(fd);
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
67 break;
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
68
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
69 case SYSLED:
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
70 last = state = sysled_get(fd);
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
71 break;
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
72
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
73 default:
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
74 break;
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
75 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
76 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
77
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
78 static void rocklight_playback_stop(void) {
411
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
79 if (last == state) return;
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
80
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
81 /* Reset to original value */
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
82 switch (type) {
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
83 case THINKLIGHT:
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
84 thinklight_set(fd, state);
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
85 break;
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
86
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
87 case SYSLED:
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
88 sysled_set(fd, state);
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
89 break;
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
90
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
91 default:
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
92 break;
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
93 }
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
94 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
95
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
96 static void rocklight_render_freq(gint16 data[2][256]) {
411
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
97 int new = ((data[0][0] + data[1][0]) >> 7) >= 80? 1:0;
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
98
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
99 if (new == last) return;
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
100 last = new;
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
101
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
102 switch (type) {
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
103 case THINKLIGHT:
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
104 thinklight_set(fd, new);
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
105 break;
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
106
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
107 case SYSLED:
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
108 sysled_set(fd, new);
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
109 break;
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
110
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
111 default:
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
112 break;
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
113 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
114 }
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
115
411
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
116 static VisPlugin rocklight_vp = {
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
117 .description = "RockLight",
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
118
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
119 .num_pcm_chs_wanted = 0,
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
120 .num_freq_chs_wanted = 2,
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
121
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
122 .init = rocklight_init,
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
123 .cleanup = rocklight_cleanup,
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
124 .playback_start = rocklight_playback_start,
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
125 .playback_stop = rocklight_playback_stop,
78a5e9c37469 [svn] - Rework and clean up code
hansmi
parents: 12
diff changeset
126 .render_freq = rocklight_render_freq
0
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
127 };
13389e613d67 [svn] - initial import of audacious-plugins tree (lots to do)
nenolod
parents:
diff changeset
128
1143
48aba1f78016 [svn] - rocklight: convert to plugin2 architecture.
nenolod
parents: 411
diff changeset
129 VisPlugin *rocklight_vplist[] = { &rocklight_vp, NULL };
48aba1f78016 [svn] - rocklight: convert to plugin2 architecture.
nenolod
parents: 411
diff changeset
130
1395
761e17b23e0c added Discovery plugin type
Cristi Magherusan <majeru@atheme-project.org>
parents: 1143
diff changeset
131 DECLARE_PLUGIN(rocklight, NULL, NULL, NULL, NULL, NULL, NULL, rocklight_vplist,NULL);