blob: 667da6abaaf18bf8530897d6847ddedd2a8c2488 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
/*
* fmrxd - a daemon to enable and multiplex access to the N950/N9 radio tuner
* Copyright (C) 2011 Javier S. Pedro <maemo@javispedro.com>
*
* 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 <glib.h>
#include <linux/videodev2.h>
static guint signal_timer_id = 0;
static uint16_t last_signal_level = 0;
static void signal_update()
{
uint16_t new_signal_level;
#if WORKAROUND_BAD_WL1273_SIGNAL
/* rssi is a value from -128 to +127. */
new_signal_level = (tuner_get_signal() + 128) * 257;
#else
/* rssi is a value from 0 to 65535. */
new_signal_level = tuner_get_signal();
#endif
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);
}
}
|