summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBertrik Sikken <bertrik@sikken.nl>2010-07-06 15:10:11 +0000
committerBertrik Sikken <bertrik@sikken.nl>2010-07-06 15:10:11 +0000
commit9da707955dcdefa1b7a55348937eb706a08039b5 (patch)
treed86bd8e30f4f511a808dc67c37559d6c020ad7bb
parent1c3ae928150df9b983c1d1456b53139d3ee986fe (diff)
Clean up naming of radio preset functions and move global radio preset methods into apps/radio/presets.h
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27309 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/radio/presets.c36
-rw-r--r--apps/radio/presets.h37
-rw-r--r--apps/radio/radio.c67
-rw-r--r--apps/radio/radio.h1
4 files changed, 79 insertions, 62 deletions
diff --git a/apps/radio/presets.c b/apps/radio/presets.c
index ea1d4022da..aa265bcc74 100644
--- a/apps/radio/presets.c
+++ b/apps/radio/presets.c
@@ -40,6 +40,7 @@
#include "talk.h"
#include "filetree.h"
#include "dir.h"
+#include "presets.h"
static int curr_preset = -1;
@@ -50,7 +51,8 @@ void remember_frequency(void);
void talk_freq(int freq, bool enqueue);
#define MAX_PRESETS 64
-static bool presets_loaded = false, presets_changed = false;
+static bool presets_loaded = false;
+static bool presets_changed = false;
static struct fmstation presets[MAX_PRESETS];
static char filepreset[MAX_PATH]; /* preset filename variable */
@@ -72,14 +74,14 @@ const struct fmstation *radio_get_preset(int preset)
return &presets[preset];
}
-bool has_presets_changed(void)
+bool presets_have_changed(void)
{
return presets_changed;
}
/* Find a matching preset to freq */
-int find_preset(int freq)
+int preset_find(int freq)
{
int i;
if(num_presets < 1)
@@ -95,7 +97,7 @@ int find_preset(int freq)
/* Return the closest preset encountered in the search direction with
wraparound. */
-int find_closest_preset(int freq, int direction)
+static int find_closest_preset(int freq, int direction)
{
int i;
int lowpreset = 0;
@@ -143,7 +145,7 @@ int find_closest_preset(int freq, int direction)
return closest;
}
-void next_preset(int direction)
+void preset_next(int direction)
{
if (num_presets < 1)
return;
@@ -160,13 +162,13 @@ void next_preset(int direction)
remember_frequency();
}
-void set_current_preset(int preset)
+void preset_set_current(int preset)
{
curr_preset = preset;
}
/* Speak a preset by number or by spelling its name, depending on settings. */
-void talk_preset(int preset, bool fallback, bool enqueue)
+void preset_talk(int preset, bool fallback, bool enqueue)
{
if (global_settings.talk_file == 1) /* number */
talk_number(preset + 1, enqueue);
@@ -270,7 +272,7 @@ const char* radio_get_preset_name(int preset)
return NULL;
}
-int radio_add_preset(void)
+int handle_radio_add_preset(void)
{
char buf[MAX_FMPRESET_LEN + 1];
@@ -348,12 +350,12 @@ static int radio_delete_preset(void)
return 1;
}
-int load_preset_list(void)
+int preset_list_load(void)
{
return !rockbox_browse(FMPRESET_PATH, SHOW_FMR);
}
-int save_preset_list(void)
+int preset_list_save(void)
{
if(num_presets > 0)
{
@@ -406,7 +408,7 @@ int save_preset_list(void)
return true;
}
-int clear_preset_list(void)
+int preset_list_clear(void)
{
/* Clear all the preset entries */
memset(presets, 0, sizeof (presets));
@@ -457,7 +459,7 @@ static const char* presets_get_name(int selected_item, void *data,
static int presets_speak_name(int selected_item, void * data)
{
(void)data;
- talk_preset(selected_item, true, false);
+ preset_talk(selected_item, true, false);
return 0;
}
@@ -498,7 +500,7 @@ int handle_radio_presets(void)
switch (action)
{
case ACTION_STD_MENU:
- if (radio_add_preset())
+ if (handle_radio_add_preset())
{
gui_synclist_set_nb_items(&lists, num_presets);
gui_synclist_select_item(&lists, num_presets - 1);
@@ -531,7 +533,7 @@ int handle_radio_presets(void)
}
-int scan_presets(void *viewports)
+int presets_scan(void *viewports)
{
bool do_scan = true;
int i;
@@ -608,13 +610,13 @@ int scan_presets(void *viewports)
void presets_save(void)
{
if(filepreset[0] == '\0')
- save_preset_list();
+ preset_list_save();
else
radio_save_presets();
}
#ifdef HAVE_LCD_BITMAP
-static inline void draw_veritcal_line_mark(struct screen * screen,
+static inline void draw_vertical_line_mark(struct screen * screen,
int x, int y, int h)
{
screen->set_drawmode(DRMODE_COMPLEMENT);
@@ -635,7 +637,7 @@ void presets_draw_markers(struct screen *screen,
int freq = radio_get_preset(i)->frequency;
int diff = freq - region_data->freq_min;
xi = x + (w * diff)/len;
- draw_veritcal_line_mark(screen, xi, y, h);
+ draw_vertical_line_mark(screen, xi, y, h);
}
}
#endif
diff --git a/apps/radio/presets.h b/apps/radio/presets.h
new file mode 100644
index 0000000000..7640bdfb15
--- /dev/null
+++ b/apps/radio/presets.h
@@ -0,0 +1,37 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2010 Bertrik Sikken
+ *
+ * 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 software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+int handle_radio_presets(void);
+int handle_radio_add_preset(void);
+
+int presets_scan(void *viewports);
+bool presets_have_changed(void);
+void presets_save(void);
+
+int preset_list_load(void);
+int preset_list_save(void); // prompts for name of preset file and saves
+int preset_list_clear(void);
+
+void preset_next(int direction);
+void preset_set_current(int preset);
+int preset_find(int freq);
+void preset_talk(int preset, bool fallback, bool enqueue);
+
diff --git a/apps/radio/radio.c b/apps/radio/radio.c
index f5a5b5f8de..b67506200b 100644
--- a/apps/radio/radio.c
+++ b/apps/radio/radio.c
@@ -73,6 +73,7 @@
#if CONFIG_CODEC == SWCODEC
#include "playback.h"
#endif
+#include "presets.h"
#if CONFIG_TUNER
@@ -138,23 +139,8 @@
/* presets.c needs these so keep unstatic or redo the whole thing! */
int curr_freq; /* current frequency in Hz */
-/* these are all in presets.c... someone PLEASE rework this ! */
-int handle_radio_presets(void);
-static bool radio_menu(void);
-int radio_add_preset(void);
-int save_preset_list(void);
-int load_preset_list(void);
-int clear_preset_list(void);
-void next_preset(int direction);
-void set_current_preset(int preset);
-int scan_presets(void *viewports);
-int find_preset(int freq);
-void radio_save_presets(void);
-bool has_presets_changed(void);
-void talk_preset(int preset, bool fallback, bool enqueue);
-void presets_save(void);
-
+static bool radio_menu(void);
int radio_mode = RADIO_SCAN_MODE;
static int search_dir = 0;
@@ -363,7 +349,7 @@ void next_station(int direction)
{
if (direction != 0 && radio_mode != RADIO_SCAN_MODE)
{
- next_preset(direction);
+ preset_next(direction);
return;
}
@@ -377,7 +363,7 @@ void next_station(int direction)
if (radio_status == FMRADIO_PLAYING)
tuner_set(RADIO_MUTE, 0);
- set_current_preset(find_preset(curr_freq));
+ preset_set_current(preset_find(curr_freq));
remember_frequency();
}
@@ -482,9 +468,9 @@ int radio_screen(void)
#endif
if(radio_preset_count() < 1 && yesno_pop(ID2P(LANG_FM_FIRST_AUTOSCAN)))
- scan_presets(NULL);
+ presets_scan(NULL);
- set_current_preset(find_preset(curr_freq));
+ preset_set_current(preset_find(curr_freq));
if(radio_current_preset() != -1)
radio_mode = RADIO_PRESET_MODE;
@@ -501,7 +487,7 @@ int radio_screen(void)
if(tuner_set(RADIO_SCAN_FREQUENCY, curr_freq))
{
- set_current_preset(find_preset(curr_freq));
+ preset_set_current(preset_find(curr_freq));
remember_frequency();
end_search();
talk = true;
@@ -535,7 +521,7 @@ int radio_screen(void)
#endif
{
done = true;
- if(has_presets_changed())
+ if(presets_have_changed())
{
if(yesno_pop(ID2P(LANG_FM_SAVE_CHANGES)))
{
@@ -585,7 +571,7 @@ int radio_screen(void)
keep_playing = true;
done = true;
ret_val = GO_TO_ROOT;
- if(has_presets_changed())
+ if(presets_have_changed())
{
if(yesno_pop(ID2P(LANG_FM_SAVE_CHANGES)))
{
@@ -610,7 +596,7 @@ int radio_screen(void)
search_dir = button == ACTION_STD_PREVREPEAT ? -1 : 1;
if (radio_mode != RADIO_SCAN_MODE)
{
- next_preset(search_dir);
+ preset_next(search_dir);
end_search();
update_screen = true;
talk = true;
@@ -652,7 +638,7 @@ int radio_screen(void)
case ACTION_FM_MENU:
fms_fix_displays(FMS_EXIT);
radio_menu();
- set_current_preset(find_preset(curr_freq));
+ preset_set_current(preset_find(curr_freq));
update_screen = true;
restore = true;
break;
@@ -719,7 +705,7 @@ int radio_screen(void)
#ifdef FM_NEXT_PRESET
case ACTION_FM_NEXT_PRESET:
- next_preset(1);
+ preset_next(1);
end_search();
update_screen = true;
talk = true;
@@ -728,7 +714,7 @@ int radio_screen(void)
#ifdef FM_PREV_PRESET
case ACTION_FM_PREV_PRESET:
- next_preset(-1);
+ preset_next(-1);
end_search();
update_screen = true;
talk = true;
@@ -753,7 +739,7 @@ int radio_screen(void)
keep_playing = false;
done = true;
ret_val = GO_TO_ROOT;
- if(has_presets_changed())
+ if(presets_have_changed())
{
if(yesno_pop(ID2P(LANG_FM_SAVE_CHANGES)))
{
@@ -762,7 +748,7 @@ int radio_screen(void)
}
/* Clear the preset list on exit. */
- clear_preset_list();
+ preset_list_clear();
}
break;
} /*switch(button)*/
@@ -831,7 +817,7 @@ int radio_screen(void)
enqueue = true;
}
if (radio_current_preset() >= 0)
- talk_preset(radio_current_preset(), radio_mode == RADIO_PRESET_MODE,
+ preset_talk(radio_current_preset(), radio_mode == RADIO_PRESET_MODE,
enqueue);
}
@@ -999,32 +985,23 @@ MENUITEM_FUNCTION(recsettings_item, 0, ID2P(LANG_RECORDING_SETTINGS),
fm_recording_settings, NULL, NULL, Icon_Recording);
#endif
#ifndef FM_PRESET
-int handle_radio_presets_menu(void)
-{
- return handle_radio_presets();
-}
MENUITEM_FUNCTION(radio_presets_item, 0, ID2P(LANG_PRESET),
- handle_radio_presets_menu, NULL, NULL, Icon_NOICON);
+ handle_radio_presets, NULL, NULL, Icon_NOICON);
#endif
#ifndef FM_PRESET_ADD
-int handle_radio_addpreset_menu(void)
-{
- return radio_add_preset();
-}
MENUITEM_FUNCTION(radio_addpreset_item, 0, ID2P(LANG_FM_ADD_PRESET),
- radio_add_preset, NULL, NULL, Icon_NOICON);
+ handle_radio_add_preset, NULL, NULL, Icon_NOICON);
#endif
-
MENUITEM_FUNCTION(presetload_item, 0, ID2P(LANG_FM_PRESET_LOAD),
- load_preset_list, NULL, NULL, Icon_NOICON);
+ preset_list_load, NULL, NULL, Icon_NOICON);
MENUITEM_FUNCTION(presetsave_item, 0, ID2P(LANG_FM_PRESET_SAVE),
- save_preset_list, NULL, NULL, Icon_NOICON);
+ preset_list_save, NULL, NULL, Icon_NOICON);
MENUITEM_FUNCTION(presetclear_item, 0, ID2P(LANG_FM_PRESET_CLEAR),
- clear_preset_list, NULL, NULL, Icon_NOICON);
+ preset_list_clear, NULL, NULL, Icon_NOICON);
MENUITEM_FUNCTION(scan_presets_item, MENU_FUNC_USEPARAM,
ID2P(LANG_FM_SCAN_PRESETS),
- scan_presets, NULL, NULL, Icon_NOICON);
+ presets_scan, NULL, NULL, Icon_NOICON);
MAKE_MENU(radio_settings_menu, ID2P(LANG_FM_MENU), NULL,
Icon_Radio_screen,
diff --git a/apps/radio/radio.h b/apps/radio/radio.h
index 01afdc5a25..7c263ce218 100644
--- a/apps/radio/radio.h
+++ b/apps/radio/radio.h
@@ -34,6 +34,7 @@ enum {
#if CONFIG_TUNER
void radio_load_presets(char *filename);
+void radio_save_presets(void);
void radio_init(void) INIT_ATTR;
int radio_screen(void);
void radio_start(void);