/*
- * leds - Leds/buttons support
+ * leds - Leds support
*
* Copyright (C) 2010 Enrico Zini <enrico@enricozini.org>
*
}
}
-public class Vibrator : zavai.Resource, Object
+public class Led : zavai.Resource, Object
{
- protected Omhacks.Led vibrator;
+ protected Omhacks.Led led;
protected List<LedState> states;
- public Vibrator() throws FileError
+ public Led(string name) throws FileError
{
- if (vibrator.init("neo1973:vibrator") != 0)
- throw new FileError.NOENT("vibrator not found");
-
+ if (led.init(name) != 0)
+ throw new FileError.NOENT("led " + name + " not found");
states = new List<LedState>();
}
public void turn_off()
{
- vibrator.brightness = 0;
- Memory.copy(vibrator.trigger, "none", 5);
- vibrator.set();
+ led.brightness = 0;
+ Memory.copy(led.trigger, "none", 5);
+ led.set();
}
public void push_state(LedState state)
{
states.prepend(state);
- state.to_omhacks(ref vibrator);
- vibrator.set();
+ state.to_omhacks(ref led);
+ led.set();
}
public void pop_state(string name)
turn_off();
else {
// Activate the new top
- states.data.to_omhacks(ref vibrator);
- vibrator.set();
+ states.data.to_omhacks(ref led);
+ led.set();
}
}
}
}
-public class AUX: zavai.Service
+public class AUXButton: zavai.Service
{
- protected Omhacks.Led auxled;
- protected bool has_aux;
-
- protected weak clock.AlarmTriggerInfo current_alarm = null;
+ public signal bool event(ulong time, bool pressed);
- public AUX()
+ public AUXButton()
{
- Object(name: "ui.aux");
-
- has_aux = (auxled.init("gta02-aux:red") == 0);
-
- if (has_aux)
- {
- zavai.log.warning("aux: can notify alarm triggers");
- clock.alarm_trigger_queue.triggered += on_alarm_trigger;
- clock.alarm_trigger_queue.acked += on_alarm_done;
- clock.alarm_trigger_queue.canceled += on_alarm_done;
- } else {
- zavai.log.warning("aux: no way to notify alarm triggers");
- }
-
// Listen to the button via X
input.hotkeys.hotkey += on_auxbutton;
input.hotkeys.grab(zavai.config.aux_button_keycode, 0, false);
protected bool on_auxbutton(uint keycode, ulong time, bool pressed)
{
if (keycode == zavai.config.aux_button_keycode)
- {
- if (pressed)
- {
- zavai.log.debug("AUX button pressed");
- if (current_alarm != null)
- {
- zavai.log.debug("HASCA");
- clock.alarm_trigger_queue.ack(current_alarm);
- }
- }
- else
- zavai.log.debug("AUX button released");
- return true;
- }
+ return event(time, pressed);
return false;
}
-
- public void on_alarm_trigger(clock.AlarmTriggerInfo info)
- {
- zavai.log.debug("Start blinking");
- auxled.brightness = 256;
- // FIXME: is there a better way? I hope there is a better way. Please
- // tell me there is a better way.
- var trig = "timer";
- for (int i = 0; ; ++i)
- {
- auxled.trigger[i] = (char)trig[i];
- if (trig[i] == 0) break;
- }
- auxled.delay_on = 200;
- auxled.delay_off = 300;
- auxled.set();
- current_alarm = info;
- }
-
- public void on_alarm_done(clock.AlarmTriggerInfo info)
- {
- zavai.log.debug("Stop blinking");
- var trig = "none";
- for (int i = 0; ; ++i)
- {
- auxled.trigger[i] = (char)trig[i];
- if (trig[i] == 0) break;
- }
- auxled.brightness = 0;
- auxled.set();
- current_alarm = null;
- }
}
-public AUX aux = null;
-public Vibrator vibrator = null;
+public Led aux = null;
+public Led vibrator = null;
+public AUXButton auxbutton = null;
public void init()
{
- aux = new AUX();
+ auxbutton = new AUXButton();
+
+ try {
+ aux = new Led("gta02-aux:red");
+ zavai.registry.register(aux);
+ } catch (Error e) {
+ zavai.log.info("No aux led found");
+ aux = null;
+ }
+
try {
- vibrator = new Vibrator();
+ vibrator = new Led("neo1973:vibrator");
zavai.registry.register(vibrator);
} catch (Error e) {
zavai.log.info("No vibrator found");