From 3fbc3f186f8f7817be2ecbdcc7117bd294bb7d88 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Mon, 13 Feb 2012 20:16:32 +0100 Subject: add signal monitoring support --- signal.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 signal.c (limited to 'signal.c') diff --git a/signal.c b/signal.c new file mode 100644 index 0000000..3618e34 --- /dev/null +++ b/signal.c @@ -0,0 +1,73 @@ +/* + * fmrxd - a daemon to enable and multiplex access to the N950/N9 radio tuner + * Copyright (C) 2011 Javier S. Pedro + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "fmrxd.h" + +#include +#include + +static guint signal_timer_id = 0; +static uint16_t last_signal_level = 0; + +static void signal_update() +{ + uint16_t new_signal_level = tuner_get_signal(); + if (new_signal_level != last_signal_level) { + server_notify_signal(new_signal_level); + last_signal_level = new_signal_level; + } +} + +static gboolean signal_poll(gpointer user_data) +{ + if (!signal_timer_id) return FALSE; + signal_update(); + return TRUE; +} + +static gboolean signal_refresh(gpointer user_data) +{ + if (!signal_timer_id) return FALSE; + signal_update(); + return FALSE; +} + +bool configure_signal(bool on) +{ + if (on) { + if (!signal_timer_id) { + signal_timer_id = g_timeout_add_seconds(SIGNAL_POLL_INTERVAL, signal_poll, NULL); + } + } else { + if (signal_timer_id) { + g_source_remove(signal_timer_id); + signal_timer_id = 0; + } + } + + return true; +} + +void signal_reset() +{ + last_signal_level = 0; + if (signal_timer_id) { + g_timeout_add(SIGNAL_REFRESH_DELAY, signal_refresh, NULL); + } +} -- cgit v1.2.3