4 * Copyright (C) 2010 Enrico Zini <enrico@enricozini.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 public int brightness;
30 public string trigger;
34 public LedState(string name)
40 public void set_constant(int power)
48 public void set_blink(int power, int delay_on=200, int delay_off=300)
52 this.delay_on = delay_on;
53 this.delay_off = delay_off;
56 public void to_omhacks(ref Omhacks.Led led)
58 led.brightness = brightness;
59 Memory.copy(led.trigger, trigger, trigger.size());
65 public class Led : zavai.Resource, Object
67 protected Omhacks.Led led;
69 protected List<LedState> states;
71 public Led(string name) throws FileError
73 if (led.init(name) != 0)
74 throw new FileError.NOENT("led " + name + " not found");
75 states = new List<LedState>();
78 public void turn_off()
81 Memory.copy(led.trigger, "none", 5);
85 public void push_state(LedState state)
87 states.prepend(state);
88 state.to_omhacks(ref led);
92 public void pop_state(string name)
95 if (states == null) return;
97 // Track if the list head changed
98 weak List<LedState> old_top = states;
100 // Remove state "name" from the stack
101 for (weak List<LedState> i = states; i != null; i = i.next)
102 if (i.data.name == name)
104 states.delete_link(i);
108 // If the list head changed, put into action the new top state
109 if (states != old_top)
113 // Activate the new top
114 states.data.to_omhacks(ref led);
119 public void shutdown()
121 while (states != null)
122 states.delete_link(states);
127 public class AUXButton: zavai.Service
129 public signal bool event(ulong time, bool pressed);
133 // Listen to the button via X
134 input.hotkeys.hotkey += on_auxbutton;
135 input.hotkeys.grab(zavai.config.aux_button_keycode, 0, false);
136 input.hotkeys.request("auxbutton");
139 protected bool on_auxbutton(uint keycode, ulong time, bool pressed)
141 if (keycode == zavai.config.aux_button_keycode)
142 return event(time, pressed);
147 public Led aux = null;
148 public Led vibrator = null;
149 public AUXButton auxbutton = null;
153 auxbutton = new AUXButton();
156 aux = new Led("gta02-aux:red");
157 zavai.registry.register(aux);
159 zavai.log.info("No aux led found");
164 vibrator = new Led("neo1973:vibrator");
165 zavai.registry.register(vibrator);
167 zavai.log.info("No vibrator found");