/* * audio - audio resource for zavai * * Copyright (C) 2009--2010 Enrico Zini * * 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 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ using GLib; namespace zavai { namespace audio { public class Audio: zavai.Service { protected Omhacks.Led vibrator; protected bool has_vibrator; /* protected dynamic DBus.Object audiodev; protected dynamic DBus.Object vibdev; */ public Audio() { Object(name: "audio"); has_vibrator = (vibrator.init("neo1973:vibrator") == 0); /* audiodev = zavai.registry.sbus.get_object( "org.freesmartphone.odeviced", "/org/freesmartphone/Device/Audio", "org.freesmartphone.Device.Audio"); vibdev = zavai.registry.sbus.get_object( "org.freesmartphone.odeviced", "/org/freesmartphone/Device/LED/neo1973_vibrator", "org.freesmartphone.Device.LED"); */ if (has_vibrator) { zavai.log.warning("audio: 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("audio: no way to notify alarm triggers"); } } public void on_alarm_trigger(clock.AlarmTriggerInfo info) { zavai.log.debug("Start vibrator"); vibrator.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) { vibrator.trigger[i] = (char)trig[i]; if (trig[i] == 0) break; } vibrator.delay_on = 200; vibrator.delay_off = 300; vibrator.set(); } public void on_alarm_done(clock.AlarmTriggerInfo info) { zavai.log.debug("Stop vibrator"); var trig = "none"; for (int i = 0; ; ++i) { vibrator.trigger[i] = (char)trig[i]; if (trig[i] == 0) break; } vibrator.brightness = 0; vibrator.set(); } /* public void notify_alarm(zavai.clock.Alarm a) { // Wiggle screen to turn on backlight zavai.ui.power.backlight.wiggle(); try { // Method does not exist in this frameworkd vibdev.BlinkSeconds(5, 500, 200); } catch (Error e) { zavai.log.error("Cannot blink vibrator: " + e.message); } // TODO: play music? } */ } public Audio audio = null; public void init() { audio = new Audio(); } } }