2 * app_aux - AUX button interaction
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
27 public class AUX: zavai.Service
29 protected Omhacks.Led auxled;
30 protected bool has_aux;
32 protected weak clock.AlarmTriggerInfo current_alarm = null;
36 Object(name: "ui.aux");
38 has_aux = (auxled.init("gta02-aux:red") == 0);
42 zavai.log.warning("aux: can notify alarm triggers");
43 clock.alarm_trigger_queue.triggered += on_alarm_trigger;
44 clock.alarm_trigger_queue.acked += on_alarm_done;
45 clock.alarm_trigger_queue.canceled += on_alarm_done;
47 zavai.log.warning("aux: no way to notify alarm triggers");
50 // Listen to the button via X
51 input.hotkeys.hotkey += on_auxbutton;
52 input.hotkeys.grab(zavai.config.aux_button_keycode, 0, false);
53 input.hotkeys.request("auxbutton");
56 protected bool on_auxbutton(uint keycode, ulong time, bool pressed)
58 if (keycode == zavai.config.aux_button_keycode)
62 zavai.log.debug("AUX button pressed");
63 if (current_alarm != null)
65 zavai.log.debug("HASCA");
66 clock.alarm_trigger_queue.ack(current_alarm);
70 zavai.log.debug("AUX button released");
76 public void on_alarm_trigger(clock.AlarmTriggerInfo info)
78 zavai.log.debug("Start blinking");
79 auxled.brightness = 256;
80 // FIXME: is there a better way? I hope there is a better way. Please
81 // tell me there is a better way.
83 for (int i = 0; ; ++i)
85 auxled.trigger[i] = (char)trig[i];
86 if (trig[i] == 0) break;
88 auxled.delay_on = 200;
89 auxled.delay_off = 300;
94 public void on_alarm_done(clock.AlarmTriggerInfo info)
96 zavai.log.debug("Stop blinking");
98 for (int i = 0; ; ++i)
100 auxled.trigger[i] = (char)trig[i];
101 if (trig[i] == 0) break;
103 auxled.brightness = 0;
105 current_alarm = null;
109 public AUX aux = null;