2004-07-02 07:43:49 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 by Linus Nielsen Feltzing
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* 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.
|
2004-07-02 07:43:49 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2005-08-16 06:50:25 +00:00
|
|
|
#include <stdbool.h>
|
2010-05-12 11:44:09 +00:00
|
|
|
#include <stdlib.h>
|
2005-08-16 06:50:25 +00:00
|
|
|
#include "config.h"
|
2004-07-02 07:43:49 +00:00
|
|
|
#include "debug.h"
|
2005-08-16 06:50:25 +00:00
|
|
|
#include "tuner.h"
|
2017-02-12 04:16:39 +00:00
|
|
|
#ifdef HAVE_RDS_CAP
|
|
|
|
#include <strlcpy.h>
|
|
|
|
#include "system.h"
|
|
|
|
#include "rds.h"
|
|
|
|
#endif
|
2004-07-02 07:43:49 +00:00
|
|
|
|
2007-02-18 08:46:12 +00:00
|
|
|
#if CONFIG_TUNER
|
2004-07-02 07:43:49 +00:00
|
|
|
|
2005-08-16 06:50:25 +00:00
|
|
|
static int frequency = 0;
|
|
|
|
static bool mono = false;
|
2004-07-02 07:43:49 +00:00
|
|
|
|
2007-06-06 19:39:59 +00:00
|
|
|
static bool powered = false;
|
|
|
|
|
2007-07-14 13:41:59 +00:00
|
|
|
void tuner_init(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-07-14 11:20:31 +00:00
|
|
|
int tuner_set(int setting, int value)
|
2004-07-02 07:43:49 +00:00
|
|
|
{
|
2005-08-16 06:50:25 +00:00
|
|
|
switch(setting)
|
2004-07-02 07:43:49 +00:00
|
|
|
{
|
2005-08-16 06:50:25 +00:00
|
|
|
case RADIO_SLEEP:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RADIO_FREQUENCY:
|
|
|
|
frequency = value;
|
|
|
|
break;
|
|
|
|
|
2007-03-16 14:40:40 +00:00
|
|
|
case RADIO_SCAN_FREQUENCY:
|
|
|
|
frequency = value;
|
|
|
|
break;
|
|
|
|
|
2005-08-16 06:50:25 +00:00
|
|
|
case RADIO_MUTE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RADIO_FORCE_MONO:
|
2010-01-01 22:47:25 +00:00
|
|
|
mono = (value != 0);
|
2005-08-16 06:50:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2007-03-16 14:40:40 +00:00
|
|
|
return -1;
|
2004-07-02 07:43:49 +00:00
|
|
|
}
|
2007-03-16 14:40:40 +00:00
|
|
|
|
|
|
|
return 1;
|
2004-07-02 07:43:49 +00:00
|
|
|
}
|
|
|
|
|
2007-07-14 11:20:31 +00:00
|
|
|
int tuner_get(int setting)
|
2004-07-02 07:43:49 +00:00
|
|
|
{
|
2005-08-16 06:50:25 +00:00
|
|
|
int val = 0;
|
2010-11-18 11:47:42 +00:00
|
|
|
#ifdef HAVE_RADIO_RSSI
|
|
|
|
static int rssi = 0, rssidiff = 2;
|
|
|
|
#endif
|
2005-08-16 06:50:25 +00:00
|
|
|
|
|
|
|
switch(setting)
|
|
|
|
{
|
|
|
|
case RADIO_PRESENT:
|
|
|
|
val = 1; /* true */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RADIO_TUNED:
|
|
|
|
if(frequency == 99500000)
|
|
|
|
val = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RADIO_STEREO:
|
|
|
|
if(frequency == 99500000)
|
|
|
|
val = mono?0:1;
|
|
|
|
break;
|
2010-11-18 11:47:42 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_RADIO_RSSI
|
|
|
|
case RADIO_RSSI_MIN:
|
|
|
|
val = 5;
|
|
|
|
break;
|
|
|
|
case RADIO_RSSI_MAX:
|
|
|
|
val = 75;
|
|
|
|
break;
|
|
|
|
case RADIO_RSSI:
|
|
|
|
rssi += rssidiff;
|
|
|
|
if (rssi >= 75)
|
|
|
|
{
|
|
|
|
rssi = 75;
|
|
|
|
rssidiff = -2;
|
|
|
|
}
|
|
|
|
else if (rssi < 5)
|
|
|
|
{
|
|
|
|
rssi = 5;
|
|
|
|
rssidiff = 2;
|
|
|
|
}
|
|
|
|
val = rssi;
|
|
|
|
break;
|
|
|
|
#endif
|
2005-08-16 06:50:25 +00:00
|
|
|
|
|
|
|
case RADIO_ALL: /* debug query */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return val;
|
2004-07-02 07:43:49 +00:00
|
|
|
}
|
|
|
|
|
2007-07-14 11:20:31 +00:00
|
|
|
bool tuner_power(bool status)
|
2007-06-06 19:39:59 +00:00
|
|
|
{
|
|
|
|
bool oldstatus = powered;
|
|
|
|
powered = status;
|
|
|
|
return oldstatus;
|
|
|
|
}
|
|
|
|
|
2010-05-12 11:44:09 +00:00
|
|
|
#ifdef HAVE_RDS_CAP
|
2017-02-12 04:16:39 +00:00
|
|
|
size_t tuner_get_rds_info(int setting, void *dst, size_t dstsize)
|
2010-05-12 11:44:09 +00:00
|
|
|
{
|
2017-02-12 04:16:39 +00:00
|
|
|
/* TODO: integrate this into tuner_get/set */
|
|
|
|
static const unsigned char info_id_tbl[] =
|
2010-05-12 11:44:09 +00:00
|
|
|
{
|
2017-02-12 04:16:39 +00:00
|
|
|
[RADIO_RDS_NAME] = RDS_INFO_PS,
|
|
|
|
[RADIO_RDS_TEXT] = RDS_INFO_RT,
|
|
|
|
[RADIO_RDS_PROGRAM_INFO] = RDS_INFO_PI,
|
|
|
|
[RADIO_RDS_CURRENT_TIME] = RDS_INFO_CT,
|
|
|
|
};
|
2010-05-12 11:44:09 +00:00
|
|
|
|
2017-02-12 04:16:39 +00:00
|
|
|
if ((unsigned int)setting >= ARRAYLEN(info_id_tbl))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (info_id_tbl[setting])
|
|
|
|
{
|
|
|
|
case RDS_INFO_PI:
|
|
|
|
if (dstsize >= sizeof (uint16_t)) {
|
|
|
|
*(uint16_t *)dst = 0;
|
|
|
|
}
|
|
|
|
dstsize = sizeof (uint16_t);
|
|
|
|
break;
|
|
|
|
case RDS_INFO_PS:
|
|
|
|
dstsize = strlcpy(dst, "Rockbox Radio", dstsize);
|
|
|
|
break;
|
|
|
|
case RDS_INFO_RT:
|
|
|
|
dstsize = strlcpy(dst, "http://www.rockbox.org", dstsize);
|
|
|
|
break;
|
|
|
|
case RDS_INFO_CT:
|
|
|
|
if (dstsize >= sizeof (time_t)) {
|
|
|
|
*(time_t *)dst = 0;
|
|
|
|
}
|
|
|
|
dstsize = sizeof (time_t);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
dstsize = 0;
|
2010-05-12 11:44:09 +00:00
|
|
|
}
|
2017-02-12 04:16:39 +00:00
|
|
|
|
|
|
|
return dstsize;
|
2010-05-12 11:44:09 +00:00
|
|
|
}
|
2017-02-12 04:16:39 +00:00
|
|
|
#endif /* HAVE_RDS_CAP */
|
|
|
|
#endif /* CONFIG_TUNER */
|