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)
downloadrockbox-9da707955dcdefa1b7a55348937eb706a08039b5.tar.gz
rockbox-9da707955dcdefa1b7a55348937eb706a08039b5.zip
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 @@
40#include "talk.h" 40#include "talk.h"
41#include "filetree.h" 41#include "filetree.h"
42#include "dir.h" 42#include "dir.h"
43#include "presets.h"
43 44
44static int curr_preset = -1; 45static int curr_preset = -1;
45 46
@@ -50,7 +51,8 @@ void remember_frequency(void);
50void talk_freq(int freq, bool enqueue); 51void talk_freq(int freq, bool enqueue);
51 52
52#define MAX_PRESETS 64 53#define MAX_PRESETS 64
53static bool presets_loaded = false, presets_changed = false; 54static bool presets_loaded = false;
55static bool presets_changed = false;
54static struct fmstation presets[MAX_PRESETS]; 56static struct fmstation presets[MAX_PRESETS];
55 57
56static char filepreset[MAX_PATH]; /* preset filename variable */ 58static char filepreset[MAX_PATH]; /* preset filename variable */
@@ -72,14 +74,14 @@ const struct fmstation *radio_get_preset(int preset)
72 return &presets[preset]; 74 return &presets[preset];
73} 75}
74 76
75bool has_presets_changed(void) 77bool presets_have_changed(void)
76{ 78{
77 return presets_changed; 79 return presets_changed;
78} 80}
79 81
80 82
81/* Find a matching preset to freq */ 83/* Find a matching preset to freq */
82int find_preset(int freq) 84int preset_find(int freq)
83{ 85{
84 int i; 86 int i;
85 if(num_presets < 1) 87 if(num_presets < 1)
@@ -95,7 +97,7 @@ int find_preset(int freq)
95 97
96/* Return the closest preset encountered in the search direction with 98/* Return the closest preset encountered in the search direction with
97 wraparound. */ 99 wraparound. */
98int find_closest_preset(int freq, int direction) 100static int find_closest_preset(int freq, int direction)
99{ 101{
100 int i; 102 int i;
101 int lowpreset = 0; 103 int lowpreset = 0;
@@ -143,7 +145,7 @@ int find_closest_preset(int freq, int direction)
143 return closest; 145 return closest;
144} 146}
145 147
146void next_preset(int direction) 148void preset_next(int direction)
147{ 149{
148 if (num_presets < 1) 150 if (num_presets < 1)
149 return; 151 return;
@@ -160,13 +162,13 @@ void next_preset(int direction)
160 remember_frequency(); 162 remember_frequency();
161} 163}
162 164
163void set_current_preset(int preset) 165void preset_set_current(int preset)
164{ 166{
165 curr_preset = preset; 167 curr_preset = preset;
166} 168}
167 169
168/* Speak a preset by number or by spelling its name, depending on settings. */ 170/* Speak a preset by number or by spelling its name, depending on settings. */
169void talk_preset(int preset, bool fallback, bool enqueue) 171void preset_talk(int preset, bool fallback, bool enqueue)
170{ 172{
171 if (global_settings.talk_file == 1) /* number */ 173 if (global_settings.talk_file == 1) /* number */
172 talk_number(preset + 1, enqueue); 174 talk_number(preset + 1, enqueue);
@@ -270,7 +272,7 @@ const char* radio_get_preset_name(int preset)
270 return NULL; 272 return NULL;
271} 273}
272 274
273int radio_add_preset(void) 275int handle_radio_add_preset(void)
274{ 276{
275 char buf[MAX_FMPRESET_LEN + 1]; 277 char buf[MAX_FMPRESET_LEN + 1];
276 278
@@ -348,12 +350,12 @@ static int radio_delete_preset(void)
348 return 1; 350 return 1;
349} 351}
350 352
351int load_preset_list(void) 353int preset_list_load(void)
352{ 354{
353 return !rockbox_browse(FMPRESET_PATH, SHOW_FMR); 355 return !rockbox_browse(FMPRESET_PATH, SHOW_FMR);
354} 356}
355 357
356int save_preset_list(void) 358int preset_list_save(void)
357{ 359{
358 if(num_presets > 0) 360 if(num_presets > 0)
359 { 361 {
@@ -406,7 +408,7 @@ int save_preset_list(void)
406 return true; 408 return true;
407} 409}
408 410
409int clear_preset_list(void) 411int preset_list_clear(void)
410{ 412{
411 /* Clear all the preset entries */ 413 /* Clear all the preset entries */
412 memset(presets, 0, sizeof (presets)); 414 memset(presets, 0, sizeof (presets));
@@ -457,7 +459,7 @@ static const char* presets_get_name(int selected_item, void *data,
457static int presets_speak_name(int selected_item, void * data) 459static int presets_speak_name(int selected_item, void * data)
458{ 460{
459 (void)data; 461 (void)data;
460 talk_preset(selected_item, true, false); 462 preset_talk(selected_item, true, false);
461 return 0; 463 return 0;
462} 464}
463 465
@@ -498,7 +500,7 @@ int handle_radio_presets(void)
498 switch (action) 500 switch (action)
499 { 501 {
500 case ACTION_STD_MENU: 502 case ACTION_STD_MENU:
501 if (radio_add_preset()) 503 if (handle_radio_add_preset())
502 { 504 {
503 gui_synclist_set_nb_items(&lists, num_presets); 505 gui_synclist_set_nb_items(&lists, num_presets);
504 gui_synclist_select_item(&lists, num_presets - 1); 506 gui_synclist_select_item(&lists, num_presets - 1);
@@ -531,7 +533,7 @@ int handle_radio_presets(void)
531} 533}
532 534
533 535
534int scan_presets(void *viewports) 536int presets_scan(void *viewports)
535{ 537{
536 bool do_scan = true; 538 bool do_scan = true;
537 int i; 539 int i;
@@ -608,13 +610,13 @@ int scan_presets(void *viewports)
608void presets_save(void) 610void presets_save(void)
609{ 611{
610 if(filepreset[0] == '\0') 612 if(filepreset[0] == '\0')
611 save_preset_list(); 613 preset_list_save();
612 else 614 else
613 radio_save_presets(); 615 radio_save_presets();
614} 616}
615 617
616#ifdef HAVE_LCD_BITMAP 618#ifdef HAVE_LCD_BITMAP
617static inline void draw_veritcal_line_mark(struct screen * screen, 619static inline void draw_vertical_line_mark(struct screen * screen,
618 int x, int y, int h) 620 int x, int y, int h)
619{ 621{
620 screen->set_drawmode(DRMODE_COMPLEMENT); 622 screen->set_drawmode(DRMODE_COMPLEMENT);
@@ -635,7 +637,7 @@ void presets_draw_markers(struct screen *screen,
635 int freq = radio_get_preset(i)->frequency; 637 int freq = radio_get_preset(i)->frequency;
636 int diff = freq - region_data->freq_min; 638 int diff = freq - region_data->freq_min;
637 xi = x + (w * diff)/len; 639 xi = x + (w * diff)/len;
638 draw_veritcal_line_mark(screen, xi, y, h); 640 draw_vertical_line_mark(screen, xi, y, h);
639 } 641 }
640} 642}
641#endif 643#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 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 Bertrik Sikken
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22int handle_radio_presets(void);
23int handle_radio_add_preset(void);
24
25int presets_scan(void *viewports);
26bool presets_have_changed(void);
27void presets_save(void);
28
29int preset_list_load(void);
30int preset_list_save(void); // prompts for name of preset file and saves
31int preset_list_clear(void);
32
33void preset_next(int direction);
34void preset_set_current(int preset);
35int preset_find(int freq);
36void preset_talk(int preset, bool fallback, bool enqueue);
37
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 @@
73#if CONFIG_CODEC == SWCODEC 73#if CONFIG_CODEC == SWCODEC
74#include "playback.h" 74#include "playback.h"
75#endif 75#endif
76#include "presets.h"
76 77
77#if CONFIG_TUNER 78#if CONFIG_TUNER
78 79
@@ -138,23 +139,8 @@
138 139
139/* presets.c needs these so keep unstatic or redo the whole thing! */ 140/* presets.c needs these so keep unstatic or redo the whole thing! */
140int curr_freq; /* current frequency in Hz */ 141int curr_freq; /* current frequency in Hz */
141/* these are all in presets.c... someone PLEASE rework this ! */
142int handle_radio_presets(void);
143static bool radio_menu(void);
144int radio_add_preset(void);
145int save_preset_list(void);
146int load_preset_list(void);
147int clear_preset_list(void);
148void next_preset(int direction);
149void set_current_preset(int preset);
150int scan_presets(void *viewports);
151int find_preset(int freq);
152void radio_save_presets(void);
153bool has_presets_changed(void);
154void talk_preset(int preset, bool fallback, bool enqueue);
155void presets_save(void);
156
157 142
143static bool radio_menu(void);
158 144
159int radio_mode = RADIO_SCAN_MODE; 145int radio_mode = RADIO_SCAN_MODE;
160static int search_dir = 0; 146static int search_dir = 0;
@@ -363,7 +349,7 @@ void next_station(int direction)
363{ 349{
364 if (direction != 0 && radio_mode != RADIO_SCAN_MODE) 350 if (direction != 0 && radio_mode != RADIO_SCAN_MODE)
365 { 351 {
366 next_preset(direction); 352 preset_next(direction);
367 return; 353 return;
368 } 354 }
369 355
@@ -377,7 +363,7 @@ void next_station(int direction)
377 if (radio_status == FMRADIO_PLAYING) 363 if (radio_status == FMRADIO_PLAYING)
378 tuner_set(RADIO_MUTE, 0); 364 tuner_set(RADIO_MUTE, 0);
379 365
380 set_current_preset(find_preset(curr_freq)); 366 preset_set_current(preset_find(curr_freq));
381 remember_frequency(); 367 remember_frequency();
382} 368}
383 369
@@ -482,9 +468,9 @@ int radio_screen(void)
482#endif 468#endif
483 469
484 if(radio_preset_count() < 1 && yesno_pop(ID2P(LANG_FM_FIRST_AUTOSCAN))) 470 if(radio_preset_count() < 1 && yesno_pop(ID2P(LANG_FM_FIRST_AUTOSCAN)))
485 scan_presets(NULL); 471 presets_scan(NULL);
486 472
487 set_current_preset(find_preset(curr_freq)); 473 preset_set_current(preset_find(curr_freq));
488 if(radio_current_preset() != -1) 474 if(radio_current_preset() != -1)
489 radio_mode = RADIO_PRESET_MODE; 475 radio_mode = RADIO_PRESET_MODE;
490 476
@@ -501,7 +487,7 @@ int radio_screen(void)
501 487
502 if(tuner_set(RADIO_SCAN_FREQUENCY, curr_freq)) 488 if(tuner_set(RADIO_SCAN_FREQUENCY, curr_freq))
503 { 489 {
504 set_current_preset(find_preset(curr_freq)); 490 preset_set_current(preset_find(curr_freq));
505 remember_frequency(); 491 remember_frequency();
506 end_search(); 492 end_search();
507 talk = true; 493 talk = true;
@@ -535,7 +521,7 @@ int radio_screen(void)
535#endif 521#endif
536 { 522 {
537 done = true; 523 done = true;
538 if(has_presets_changed()) 524 if(presets_have_changed())
539 { 525 {
540 if(yesno_pop(ID2P(LANG_FM_SAVE_CHANGES))) 526 if(yesno_pop(ID2P(LANG_FM_SAVE_CHANGES)))
541 { 527 {
@@ -585,7 +571,7 @@ int radio_screen(void)
585 keep_playing = true; 571 keep_playing = true;
586 done = true; 572 done = true;
587 ret_val = GO_TO_ROOT; 573 ret_val = GO_TO_ROOT;
588 if(has_presets_changed()) 574 if(presets_have_changed())
589 { 575 {
590 if(yesno_pop(ID2P(LANG_FM_SAVE_CHANGES))) 576 if(yesno_pop(ID2P(LANG_FM_SAVE_CHANGES)))
591 { 577 {
@@ -610,7 +596,7 @@ int radio_screen(void)
610 search_dir = button == ACTION_STD_PREVREPEAT ? -1 : 1; 596 search_dir = button == ACTION_STD_PREVREPEAT ? -1 : 1;
611 if (radio_mode != RADIO_SCAN_MODE) 597 if (radio_mode != RADIO_SCAN_MODE)
612 { 598 {
613 next_preset(search_dir); 599 preset_next(search_dir);
614 end_search(); 600 end_search();
615 update_screen = true; 601 update_screen = true;
616 talk = true; 602 talk = true;
@@ -652,7 +638,7 @@ int radio_screen(void)
652 case ACTION_FM_MENU: 638 case ACTION_FM_MENU:
653 fms_fix_displays(FMS_EXIT); 639 fms_fix_displays(FMS_EXIT);
654 radio_menu(); 640 radio_menu();
655 set_current_preset(find_preset(curr_freq)); 641 preset_set_current(preset_find(curr_freq));
656 update_screen = true; 642 update_screen = true;
657 restore = true; 643 restore = true;
658 break; 644 break;
@@ -719,7 +705,7 @@ int radio_screen(void)
719 705
720#ifdef FM_NEXT_PRESET 706#ifdef FM_NEXT_PRESET
721 case ACTION_FM_NEXT_PRESET: 707 case ACTION_FM_NEXT_PRESET:
722 next_preset(1); 708 preset_next(1);
723 end_search(); 709 end_search();
724 update_screen = true; 710 update_screen = true;
725 talk = true; 711 talk = true;
@@ -728,7 +714,7 @@ int radio_screen(void)
728 714
729#ifdef FM_PREV_PRESET 715#ifdef FM_PREV_PRESET
730 case ACTION_FM_PREV_PRESET: 716 case ACTION_FM_PREV_PRESET:
731 next_preset(-1); 717 preset_next(-1);
732 end_search(); 718 end_search();
733 update_screen = true; 719 update_screen = true;
734 talk = true; 720 talk = true;
@@ -753,7 +739,7 @@ int radio_screen(void)
753 keep_playing = false; 739 keep_playing = false;
754 done = true; 740 done = true;
755 ret_val = GO_TO_ROOT; 741 ret_val = GO_TO_ROOT;
756 if(has_presets_changed()) 742 if(presets_have_changed())
757 { 743 {
758 if(yesno_pop(ID2P(LANG_FM_SAVE_CHANGES))) 744 if(yesno_pop(ID2P(LANG_FM_SAVE_CHANGES)))
759 { 745 {
@@ -762,7 +748,7 @@ int radio_screen(void)
762 } 748 }
763 749
764 /* Clear the preset list on exit. */ 750 /* Clear the preset list on exit. */
765 clear_preset_list(); 751 preset_list_clear();
766 } 752 }
767 break; 753 break;
768 } /*switch(button)*/ 754 } /*switch(button)*/
@@ -831,7 +817,7 @@ int radio_screen(void)
831 enqueue = true; 817 enqueue = true;
832 } 818 }
833 if (radio_current_preset() >= 0) 819 if (radio_current_preset() >= 0)
834 talk_preset(radio_current_preset(), radio_mode == RADIO_PRESET_MODE, 820 preset_talk(radio_current_preset(), radio_mode == RADIO_PRESET_MODE,
835 enqueue); 821 enqueue);
836 } 822 }
837 823
@@ -999,32 +985,23 @@ MENUITEM_FUNCTION(recsettings_item, 0, ID2P(LANG_RECORDING_SETTINGS),
999 fm_recording_settings, NULL, NULL, Icon_Recording); 985 fm_recording_settings, NULL, NULL, Icon_Recording);
1000#endif 986#endif
1001#ifndef FM_PRESET 987#ifndef FM_PRESET
1002int handle_radio_presets_menu(void)
1003{
1004 return handle_radio_presets();
1005}
1006MENUITEM_FUNCTION(radio_presets_item, 0, ID2P(LANG_PRESET), 988MENUITEM_FUNCTION(radio_presets_item, 0, ID2P(LANG_PRESET),
1007 handle_radio_presets_menu, NULL, NULL, Icon_NOICON); 989 handle_radio_presets, NULL, NULL, Icon_NOICON);
1008#endif 990#endif
1009#ifndef FM_PRESET_ADD 991#ifndef FM_PRESET_ADD
1010int handle_radio_addpreset_menu(void)
1011{
1012 return radio_add_preset();
1013}
1014MENUITEM_FUNCTION(radio_addpreset_item, 0, ID2P(LANG_FM_ADD_PRESET), 992MENUITEM_FUNCTION(radio_addpreset_item, 0, ID2P(LANG_FM_ADD_PRESET),
1015 radio_add_preset, NULL, NULL, Icon_NOICON); 993 handle_radio_add_preset, NULL, NULL, Icon_NOICON);
1016#endif 994#endif
1017 995
1018
1019MENUITEM_FUNCTION(presetload_item, 0, ID2P(LANG_FM_PRESET_LOAD), 996MENUITEM_FUNCTION(presetload_item, 0, ID2P(LANG_FM_PRESET_LOAD),
1020 load_preset_list, NULL, NULL, Icon_NOICON); 997 preset_list_load, NULL, NULL, Icon_NOICON);
1021MENUITEM_FUNCTION(presetsave_item, 0, ID2P(LANG_FM_PRESET_SAVE), 998MENUITEM_FUNCTION(presetsave_item, 0, ID2P(LANG_FM_PRESET_SAVE),
1022 save_preset_list, NULL, NULL, Icon_NOICON); 999 preset_list_save, NULL, NULL, Icon_NOICON);
1023MENUITEM_FUNCTION(presetclear_item, 0, ID2P(LANG_FM_PRESET_CLEAR), 1000MENUITEM_FUNCTION(presetclear_item, 0, ID2P(LANG_FM_PRESET_CLEAR),
1024 clear_preset_list, NULL, NULL, Icon_NOICON); 1001 preset_list_clear, NULL, NULL, Icon_NOICON);
1025MENUITEM_FUNCTION(scan_presets_item, MENU_FUNC_USEPARAM, 1002MENUITEM_FUNCTION(scan_presets_item, MENU_FUNC_USEPARAM,
1026 ID2P(LANG_FM_SCAN_PRESETS), 1003 ID2P(LANG_FM_SCAN_PRESETS),
1027 scan_presets, NULL, NULL, Icon_NOICON); 1004 presets_scan, NULL, NULL, Icon_NOICON);
1028 1005
1029MAKE_MENU(radio_settings_menu, ID2P(LANG_FM_MENU), NULL, 1006MAKE_MENU(radio_settings_menu, ID2P(LANG_FM_MENU), NULL,
1030 Icon_Radio_screen, 1007 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 {
34 34
35#if CONFIG_TUNER 35#if CONFIG_TUNER
36void radio_load_presets(char *filename); 36void radio_load_presets(char *filename);
37void radio_save_presets(void);
37void radio_init(void) INIT_ATTR; 38void radio_init(void) INIT_ATTR;
38int radio_screen(void); 39int radio_screen(void);
39void radio_start(void); 40void radio_start(void);