2 * Copyright (C) 12 Jun 2003 Tomas Cermak
4 * This file is part of wmradio program.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include <sys/types.h>
41 #include "stationnames.h"
48 #include "gnome_applet_envelope.h"
50 #include "wm_envelope.h"
52 static int min_freq
= 8750, max_freq
= 10800;
56 RadioInfo
*wmradio_radio_info(void)
61 void wmradio_init_radio_info(void) {
63 radio_info
.current_station
= 0;
64 radio_info
.dont_quit_mode
= 0;
69 radio_info
.radiofd
= open(rc_get_variable(SECTION_CONFIG
,"device","/dev/radio"),O_RDONLY
);
70 return radio_info
.radiofd
>=0;
75 if(radio_info
.radiofd
!= -1) close(radio_info
.radiofd
);
78 void radio_refresh_freq (void) {
81 radio_setfreq(radio_info
.radiofd
,radio_info
.current_freq
);
82 if(rc_get_variable_as_int(SECTION_CONFIG
,"osd",0)) {
83 sprintf(str
, "%.2i FM", radio_info
.current_freq
);
88 void tuned_to_preset_station(void)
93 x
= radio_info
.current_freq
;
94 for(i
= 0; i
<6; i
++) {
97 skin_select_station(i
);
103 void tune_plus(int fine_tuning
)
106 radio_info
.current_freq
+= 1;
108 radio_info
.current_freq
+= 10;
110 if(radio_info
.current_freq
>max_freq
) radio_info
.current_freq
= min_freq
;
111 radio_refresh_freq();
114 void tune_minus(int fine_tuning
)
117 radio_info
.current_freq
-= 1;
119 radio_info
.current_freq
-= 10;
121 if(radio_info
.current_freq
<min_freq
) radio_info
.current_freq
= max_freq
;
122 radio_refresh_freq();
125 void wmradio_scan(int start
)
127 static char starting
= 0;
132 starting
= radio_info
.scan_in_progress
= 1;
135 radio_info
.scan_in_progress
= 0;
136 tuned_to_preset_station();
138 if(!radio_info
.scan_in_progress
) return;
141 signal
= radio_getsignal(radio_info
.radiofd
);
143 if( signal
<2 ) starting
= 0;
146 radio_info
.scan_in_progress
= 0;
147 tuned_to_preset_station();
152 void wmradio_next_station(void)
154 radio_info
.current_freq
= station_next_freq(radio_info
.current_freq
);
155 radio_refresh_freq();
158 void wmradio_prev_station(void)
160 radio_info
.current_freq
= station_prev_freq(radio_info
.current_freq
);
161 radio_refresh_freq();
164 #define MOD(A,B) ((A)<0)? (B)+((A)%(B)) : (A)%(B)
166 void wmradio_command(RadioCommand command
, int value
) {
169 if( (value
&& radio_info
.dont_quit_mode
)
170 || (!value
&& !radio_info
.dont_quit_mode
)){
171 if (radio_info
.is_on
) {
172 radio_mute(radio_info
.radiofd
);
175 /* rc_save_config(); */
179 if (radio_info
.is_on
) {
180 if(rc_get_variable_as_int(SECTION_CONFIG
,"osd",0)) {
183 radio_mute(radio_info
.radiofd
);
185 skin_switch_radio(SKIN_OFF
);
186 radio_info
.is_on
= 0;
187 /* rc_save_config(); */
190 radio_refresh_freq();
191 radio_unmute(radio_info
.radiofd
);
192 skin_switch_radio(SKIN_ON
);
193 radio_info
.is_on
= 1;
195 printf("wmradio: can't open radio device\n");
197 /* those next lines are for tests on my notebook */
198 /* without /dev/rario */
199 printf(" but radio is compiled with ONLY_TEST\n");
200 radio_refresh_freq();
201 radio_unmute(radio_info
.radiofd
);
202 skin_switch_radio(SKIN_ON
);
203 radio_info
.is_on
= 1;
204 #endif /* ONLY_TEST */
209 if(radio_info
.is_on
) {
211 skin_unselect_button();
212 tuned_to_preset_station();
216 if(radio_info
.is_on
) {
218 skin_unselect_button();
219 tuned_to_preset_station();
223 if(radio_info
.is_on
){
224 radio_info
.current_station
= value
;
225 radio_info
.current_freq
= rc_get_freq(value
);
226 radio_refresh_freq();
227 skin_select_station(value
);
231 if(radio_info
.is_on
){
232 rc_set_freq(value
,radio_info
.current_freq
);
233 skin_select_station(value
);
238 if(radio_info
.is_on
){
239 wmradio_scan(SCAN_START
);
240 skin_unselect_button();
244 if(radio_info
.is_on
){
245 wmradio_prev_station();
246 skin_unselect_button();
247 tuned_to_preset_station();
251 if(radio_info
.is_on
){
252 wmradio_next_station();
253 skin_unselect_button();
254 tuned_to_preset_station();
260 radio_info
.dont_quit_mode
= rc_get_variable_as_int(SECTION_CONFIG
,"dont-quit-mode",0);
265 void wmradio_handle_event(RadioEvent
*e
)
269 /* int stations[] = {5829,5830,5831,5824,5825,5826};*/
273 video_draw(radio_info
.current_freq
,radio_getstereo(radio_info
.radiofd
));
276 if(radio_info
.is_on
) radio_mute(radio_info
.radiofd
);
278 /* rc_save_config(); */
281 case REVENT_BUTTON_PRESS
:
282 skin_mouse_event(e
->x
,e
-> y
,e
->button
,1);
283 video_draw(radio_info
.current_freq
,radio_getstereo(radio_info
.radiofd
));
286 wmradio_scan(SCAN_NO_CHANGE
);
287 video_draw(radio_info
.current_freq
,radio_getstereo(radio_info
.radiofd
));
289 case REVENT_BUTTON_RELEASE
:
290 setlocale(LC_ALL
,"C");
291 wmradio_scan(SCAN_STOP
);
292 i
= skin_mouse_event(e
->x
, e
->y
,e
->button
, 0);
294 if( (e
->button
== 4 || e
->button
== 5) ) {
296 /* this is not mouse wheel */
300 wmradio_command(POWER_SWITCH
, e
->control
);
303 if(e
->shift
) { wmradio_command(TUNE_NAME_PREV
, e
->control
); }
304 else { wmradio_command(TUNE_MINUS
, e
->control
); }
307 if(e
->shift
) { wmradio_command(TUNE_NAME_NEXT
, e
->control
); }
308 else { wmradio_command(TUNE_PLUS
, e
->control
); }
311 wmradio_command(SCAN
, 0);
332 if(presetindex
>= 0) {
334 wmradio_command(SAVE_PRESET
,presetindex
);
336 wmradio_command(SET_PRESET
,presetindex
);
338 radio_info
.current_station
= presetindex
;
342 video_draw(radio_info
.current_freq
,
343 radio_getstereo(radio_info
.radiofd
));
345 case REVENT_SCROLL_UP
:
346 skin_mouse_event(e
->x
, e
->y
,e
->button
, 1);
347 i
= skin_mouse_event(e
->x
, e
->y
,e
->button
, 0);
350 wmradio_command(TUNE_MINUS
, e
->control
);
352 wmradio_command(TUNE_NAME_PREV
, e
->control
);
355 wmradio_command(SET_PRESET
,
356 MOD(radio_info
.current_station
-1, 6));
358 case REVENT_SCROLL_DOWN
:
359 skin_mouse_event(e
->x
, e
->y
,e
->button
, 1);
360 i
= skin_mouse_event(e
->x
, e
->y
,e
->button
, 0);
363 wmradio_command(TUNE_PLUS
, e
->control
);
365 wmradio_command(TUNE_NAME_NEXT
, e
->control
);
368 wmradio_command(SET_PRESET
,
369 MOD(radio_info
.current_station
+1, 6));
375 int wmradio_init(void)
377 if (rc_get_variable_as_int(SECTION_CONFIG
,"osd",0) ){
378 if (! osd_init("wmradio",
379 rc_get_variable(SECTION_CONFIG
,"osd-font","*-courier-*"),
380 rc_get_variable(SECTION_CONFIG
,"osd-color","green"),
381 rc_get_variable_as_int(SECTION_CONFIG
,"osd-position",10),
382 rc_get_variable_as_int(SECTION_CONFIG
,"osd-position",10),
383 rc_get_variable_as_int(SECTION_CONFIG
,"osd-shadow-offset",5),
384 rc_get_variable_as_int(SECTION_CONFIG
,"osd-timeout",3)
387 printf("osd init failed\n");
388 rc_set_variable_as_int(SECTION_CONFIG
,"osd",0);
392 skin_switch_radio(SKIN_OFF
);
393 radio_info
.is_on
= 0;
394 radio_info
.dont_quit_mode
= rc_get_variable_as_int(SECTION_CONFIG
,"dont-quit-mode",1);
395 radio_info
.current_freq
= rc_get_freq(radio_info
.current_station
);
396 if(! rc_get_variable_as_int(SECTION_CONFIG
,"start-muted",1) ) {
398 radio_setfreq(radio_info
.radiofd
,radio_info
.current_freq
);
399 radio_unmute(radio_info
.radiofd
);
400 skin_switch_radio(SKIN_ON
);
401 radio_info
.is_on
= 1;
403 printf("wmradio: can't open radio device\n");
404 radio_info
.is_on
= 0;
410 void wmradio_done(void)