blob: 6f6b0f914fb6dd318c33ee4cfd73fd709cf953ce [file] [log] [blame]
Linus Nielsen Feltzingafd74212004-07-02 07:43:49 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
11 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
Linus Nielsen Feltzingafd74212004-07-02 07:43:49 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
Linus Nielsen Feltzingd3fde762005-08-16 06:50:25 +000021#include <stdbool.h>
Jonathan Gordona5d8d212010-05-12 11:44:09 +000022#include <stdlib.h>
Linus Nielsen Feltzingd3fde762005-08-16 06:50:25 +000023#include "config.h"
Linus Nielsen Feltzingafd74212004-07-02 07:43:49 +000024#include "debug.h"
Linus Nielsen Feltzingd3fde762005-08-16 06:50:25 +000025#include "tuner.h"
Linus Nielsen Feltzingafd74212004-07-02 07:43:49 +000026
Jens Arnoldc6522182007-02-18 08:46:12 +000027#if CONFIG_TUNER
Linus Nielsen Feltzingafd74212004-07-02 07:43:49 +000028
Linus Nielsen Feltzingd3fde762005-08-16 06:50:25 +000029static int frequency = 0;
30static bool mono = false;
Linus Nielsen Feltzingafd74212004-07-02 07:43:49 +000031
Michael Sevakisd89eba12007-06-06 19:39:59 +000032static bool powered = false;
Michael Sevakisd89eba12007-06-06 19:39:59 +000033
Michael Sevakis680afaf2007-07-14 13:41:59 +000034void tuner_init(void)
35{
36}
37
Michael Sevakis7d759f62007-07-14 11:20:31 +000038int tuner_set(int setting, int value)
Linus Nielsen Feltzingafd74212004-07-02 07:43:49 +000039{
Linus Nielsen Feltzingd3fde762005-08-16 06:50:25 +000040 switch(setting)
Linus Nielsen Feltzingafd74212004-07-02 07:43:49 +000041 {
Linus Nielsen Feltzingd3fde762005-08-16 06:50:25 +000042 case RADIO_SLEEP:
43 break;
44
45 case RADIO_FREQUENCY:
46 frequency = value;
47 break;
48
Michael Sevakisa2ee6a62007-03-16 14:40:40 +000049 case RADIO_SCAN_FREQUENCY:
50 frequency = value;
51 break;
52
Linus Nielsen Feltzingd3fde762005-08-16 06:50:25 +000053 case RADIO_MUTE:
54 break;
55
56 case RADIO_FORCE_MONO:
Bertrik Sikken5c4ef782010-01-01 22:47:25 +000057 mono = (value != 0);
Linus Nielsen Feltzingd3fde762005-08-16 06:50:25 +000058 break;
59
60 default:
Michael Sevakisa2ee6a62007-03-16 14:40:40 +000061 return -1;
Linus Nielsen Feltzingafd74212004-07-02 07:43:49 +000062 }
Michael Sevakisa2ee6a62007-03-16 14:40:40 +000063
64 return 1;
Linus Nielsen Feltzingafd74212004-07-02 07:43:49 +000065}
66
Michael Sevakis7d759f62007-07-14 11:20:31 +000067int tuner_get(int setting)
Linus Nielsen Feltzingafd74212004-07-02 07:43:49 +000068{
Linus Nielsen Feltzingd3fde762005-08-16 06:50:25 +000069 int val = 0;
Jonathan Gordon1ce7ba42010-11-18 11:47:42 +000070#ifdef HAVE_RADIO_RSSI
71 static int rssi = 0, rssidiff = 2;
72#endif
Linus Nielsen Feltzingd3fde762005-08-16 06:50:25 +000073
74 switch(setting)
75 {
76 case RADIO_PRESENT:
77 val = 1; /* true */
78 break;
79
80 case RADIO_TUNED:
81 if(frequency == 99500000)
82 val = 1;
83 break;
84
85 case RADIO_STEREO:
86 if(frequency == 99500000)
87 val = mono?0:1;
88 break;
Jonathan Gordon1ce7ba42010-11-18 11:47:42 +000089
90#ifdef HAVE_RADIO_RSSI
91 case RADIO_RSSI_MIN:
92 val = 5;
93 break;
94 case RADIO_RSSI_MAX:
95 val = 75;
96 break;
97 case RADIO_RSSI:
98 rssi += rssidiff;
99 if (rssi >= 75)
100 {
101 rssi = 75;
102 rssidiff = -2;
103 }
104 else if (rssi < 5)
105 {
106 rssi = 5;
107 rssidiff = 2;
108 }
109 val = rssi;
110 break;
111#endif
Linus Nielsen Feltzingd3fde762005-08-16 06:50:25 +0000112
113 case RADIO_ALL: /* debug query */
114 break;
115 }
116 return val;
Linus Nielsen Feltzingafd74212004-07-02 07:43:49 +0000117}
118
Michael Sevakis7d759f62007-07-14 11:20:31 +0000119bool tuner_power(bool status)
Michael Sevakisd89eba12007-06-06 19:39:59 +0000120{
121 bool oldstatus = powered;
122 powered = status;
123 return oldstatus;
124}
Michael Sevakisd89eba12007-06-06 19:39:59 +0000125
Jonathan Gordona5d8d212010-05-12 11:44:09 +0000126#ifdef HAVE_RDS_CAP
127char* tuner_get_rds_info(int setting)
128{
129 char *text = NULL;
130
131 switch(setting)
132 {
133 case RADIO_RDS_NAME:
134 text = "Rockbox Radio";
135 break;
136
137 case RADIO_RDS_TEXT:
138 text = "http://www.rockbox.org" ;
139 break;
140 }
141 return text;
142}
143#endif
Linus Nielsen Feltzingafd74212004-07-02 07:43:49 +0000144#endif