Linus Nielsen Feltzing | afd7421 | 2004-07-02 07:43:49 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2002 by Linus Nielsen Feltzing |
| 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame] | 12 | * 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 Feltzing | afd7421 | 2004-07-02 07:43:49 +0000 | [diff] [blame] | 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
Linus Nielsen Feltzing | d3fde76 | 2005-08-16 06:50:25 +0000 | [diff] [blame] | 21 | #include <stdbool.h> |
Jonathan Gordon | a5d8d21 | 2010-05-12 11:44:09 +0000 | [diff] [blame] | 22 | #include <stdlib.h> |
Linus Nielsen Feltzing | d3fde76 | 2005-08-16 06:50:25 +0000 | [diff] [blame] | 23 | #include "config.h" |
Linus Nielsen Feltzing | afd7421 | 2004-07-02 07:43:49 +0000 | [diff] [blame] | 24 | #include "debug.h" |
Linus Nielsen Feltzing | d3fde76 | 2005-08-16 06:50:25 +0000 | [diff] [blame] | 25 | #include "tuner.h" |
Linus Nielsen Feltzing | afd7421 | 2004-07-02 07:43:49 +0000 | [diff] [blame] | 26 | |
Jens Arnold | c652218 | 2007-02-18 08:46:12 +0000 | [diff] [blame] | 27 | #if CONFIG_TUNER |
Linus Nielsen Feltzing | afd7421 | 2004-07-02 07:43:49 +0000 | [diff] [blame] | 28 | |
Linus Nielsen Feltzing | d3fde76 | 2005-08-16 06:50:25 +0000 | [diff] [blame] | 29 | static int frequency = 0; |
| 30 | static bool mono = false; |
Linus Nielsen Feltzing | afd7421 | 2004-07-02 07:43:49 +0000 | [diff] [blame] | 31 | |
Michael Sevakis | d89eba1 | 2007-06-06 19:39:59 +0000 | [diff] [blame] | 32 | static bool powered = false; |
Michael Sevakis | d89eba1 | 2007-06-06 19:39:59 +0000 | [diff] [blame] | 33 | |
Michael Sevakis | 680afaf | 2007-07-14 13:41:59 +0000 | [diff] [blame] | 34 | void tuner_init(void) |
| 35 | { |
| 36 | } |
| 37 | |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 38 | int tuner_set(int setting, int value) |
Linus Nielsen Feltzing | afd7421 | 2004-07-02 07:43:49 +0000 | [diff] [blame] | 39 | { |
Linus Nielsen Feltzing | d3fde76 | 2005-08-16 06:50:25 +0000 | [diff] [blame] | 40 | switch(setting) |
Linus Nielsen Feltzing | afd7421 | 2004-07-02 07:43:49 +0000 | [diff] [blame] | 41 | { |
Linus Nielsen Feltzing | d3fde76 | 2005-08-16 06:50:25 +0000 | [diff] [blame] | 42 | case RADIO_SLEEP: |
| 43 | break; |
| 44 | |
| 45 | case RADIO_FREQUENCY: |
| 46 | frequency = value; |
| 47 | break; |
| 48 | |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 49 | case RADIO_SCAN_FREQUENCY: |
| 50 | frequency = value; |
| 51 | break; |
| 52 | |
Linus Nielsen Feltzing | d3fde76 | 2005-08-16 06:50:25 +0000 | [diff] [blame] | 53 | case RADIO_MUTE: |
| 54 | break; |
| 55 | |
| 56 | case RADIO_FORCE_MONO: |
Bertrik Sikken | 5c4ef78 | 2010-01-01 22:47:25 +0000 | [diff] [blame] | 57 | mono = (value != 0); |
Linus Nielsen Feltzing | d3fde76 | 2005-08-16 06:50:25 +0000 | [diff] [blame] | 58 | break; |
| 59 | |
| 60 | default: |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 61 | return -1; |
Linus Nielsen Feltzing | afd7421 | 2004-07-02 07:43:49 +0000 | [diff] [blame] | 62 | } |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 63 | |
| 64 | return 1; |
Linus Nielsen Feltzing | afd7421 | 2004-07-02 07:43:49 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 67 | int tuner_get(int setting) |
Linus Nielsen Feltzing | afd7421 | 2004-07-02 07:43:49 +0000 | [diff] [blame] | 68 | { |
Linus Nielsen Feltzing | d3fde76 | 2005-08-16 06:50:25 +0000 | [diff] [blame] | 69 | int val = 0; |
Jonathan Gordon | 1ce7ba4 | 2010-11-18 11:47:42 +0000 | [diff] [blame] | 70 | #ifdef HAVE_RADIO_RSSI |
| 71 | static int rssi = 0, rssidiff = 2; |
| 72 | #endif |
Linus Nielsen Feltzing | d3fde76 | 2005-08-16 06:50:25 +0000 | [diff] [blame] | 73 | |
| 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 Gordon | 1ce7ba4 | 2010-11-18 11:47:42 +0000 | [diff] [blame] | 89 | |
| 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 Feltzing | d3fde76 | 2005-08-16 06:50:25 +0000 | [diff] [blame] | 112 | |
| 113 | case RADIO_ALL: /* debug query */ |
| 114 | break; |
| 115 | } |
| 116 | return val; |
Linus Nielsen Feltzing | afd7421 | 2004-07-02 07:43:49 +0000 | [diff] [blame] | 117 | } |
| 118 | |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 119 | bool tuner_power(bool status) |
Michael Sevakis | d89eba1 | 2007-06-06 19:39:59 +0000 | [diff] [blame] | 120 | { |
| 121 | bool oldstatus = powered; |
| 122 | powered = status; |
| 123 | return oldstatus; |
| 124 | } |
Michael Sevakis | d89eba1 | 2007-06-06 19:39:59 +0000 | [diff] [blame] | 125 | |
Jonathan Gordon | a5d8d21 | 2010-05-12 11:44:09 +0000 | [diff] [blame] | 126 | #ifdef HAVE_RDS_CAP |
| 127 | char* 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 Feltzing | afd7421 | 2004-07-02 07:43:49 +0000 | [diff] [blame] | 144 | #endif |