Some formatting fixes, reported by Alexander Levin
[kugel-rb.git] / apps / plugins / test_scanrate.c
blob5f1e3cacdfeaaf9732771187b5cba342371738e2
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2006 Jens Arnold
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "plugin.h"
24 #if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4) && !defined(SIMULATOR)
26 PLUGIN_HEADER
28 #if (CONFIG_KEYPAD == RECORDER_PAD) || (CONFIG_KEYPAD == ONDIO_PAD) \
29 || (CONFIG_KEYPAD == IRIVER_H100_PAD)
30 #define SCANRATE_DONE BUTTON_OFF
31 #define SCANRATE_FASTINC BUTTON_UP
32 #define SCANRATE_FASTDEC BUTTON_DOWN
33 #define SCANRATE_INC BUTTON_RIGHT
34 #define SCANRATE_DEC BUTTON_LEFT
36 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD) \
37 || (CONFIG_KEYPAD == MROBE100_PAD) \
38 || (CONFIG_KEYPAD == SANSA_CLIP_PAD)
39 #define SCANRATE_DONE BUTTON_POWER
40 #define SCANRATE_FASTINC BUTTON_UP
41 #define SCANRATE_FASTDEC BUTTON_DOWN
42 #define SCANRATE_INC BUTTON_RIGHT
43 #define SCANRATE_DEC BUTTON_LEFT
45 #elif CONFIG_KEYPAD == SANSA_FUZE_PAD
46 #define SCANRATE_DONE (BUTTON_HOME|BUTTON_REPEAT)
47 #define SCANRATE_FASTINC BUTTON_UP
48 #define SCANRATE_FASTDEC BUTTON_DOWN
49 #define SCANRATE_INC BUTTON_RIGHT
50 #define SCANRATE_DEC BUTTON_LEFT
52 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
53 #define SCANRATE_DONE BUTTON_RC_REC
54 #define SCANRATE_FASTINC BUTTON_RC_VOL_UP
55 #define SCANRATE_FASTDEC BUTTON_RC_VOL_DOWN
56 #define SCANRATE_INC BUTTON_RC_FF
57 #define SCANRATE_DEC BUTTON_RC_REW
59 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) \
60 || (CONFIG_KEYPAD == IPOD_1G2G_PAD)
61 #define SCANRATE_DONE BUTTON_MENU
62 #define SCANRATE_FASTINC BUTTON_SCROLL_FWD
63 #define SCANRATE_FASTDEC BUTTON_SCROLL_BACK
64 #define SCANRATE_INC BUTTON_RIGHT
65 #define SCANRATE_DEC BUTTON_LEFT
67 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
68 #define SCANRATE_DONE BUTTON_PLAY
69 #define SCANRATE_FASTINC BUTTON_FFWD
70 #define SCANRATE_FASTDEC BUTTON_REW
71 #define SCANRATE_INC BUTTON_UP
72 #define SCANRATE_DEC BUTTON_DOWN
74 #endif
76 /* Default refresh rates in 1/10 Hz */
77 #if defined ARCHOS_RECORDER || defined ARCHOS_FMRECORDER \
78 || defined ARCHOS_RECORDERV2 || defined ARCHOS_ONDIOFM \
79 || defined ARCHOS_ONDIOSP
80 #define DEFAULT_SCAN_RATE 670
81 #elif defined IAUDIO_M3
82 #define DEFAULT_SCAN_RATE 1500
83 #define HORIZ_SCAN /* LCD controller updates the panel sideways */
84 #define NEED_BOOST
85 #elif defined IAUDIO_M5
86 #define DEFAULT_SCAN_RATE 730
87 #elif defined IPOD_1G2G
88 #define DEFAULT_SCAN_RATE 960
89 #elif defined IPOD_MINI2G || defined IPOD_MINI \
90 || defined IPOD_3G || defined IPOD_4G
91 #define DEFAULT_SCAN_RATE 870
92 #elif defined IRIVER_H100_SERIES
93 #define DEFAULT_SCAN_RATE 700
94 #elif defined SANSA_CLIP
95 #define DEFAULT_SCAN_RATE 780
96 #elif defined SAMSUNG_YH920
97 #define DEFAULT_SCAN_RATE 700
98 #else
99 #define DEFAULT_SCAN_RATE 700
100 #warning Generic default scanrate
101 #endif
103 #ifdef HORIZ_SCAN
104 #define TEXT_X 0
105 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
106 #define BUF_WIDTH ((LCD_WIDTH+7)/8)
107 #define BUF_HEIGHT (LCD_HEIGHT/4)
108 #define TEXT_Y BUF_HEIGHT
109 #else
110 #define BUF_WIDTH (LCD_WIDTH)
111 #define BUF_HEIGHT (LCD_HEIGHT/8/4)
112 #define TEXT_Y (BUF_HEIGHT*8)
113 #endif
114 #else /* !HORIZ_SCAN */
115 #define TEXT_Y 0
116 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
117 #define BUF_WIDTH ((LCD_WIDTH+7)/8/4)
118 #define BUF_HEIGHT LCD_HEIGHT
119 #define TEXT_X (BUF_WIDTH*8)
120 #else
121 #define BUF_WIDTH (LCD_WIDTH/4)
122 #define BUF_HEIGHT (LCD_HEIGHT/8)
123 #define TEXT_X BUF_WIDTH
124 #endif
125 #endif /* !HORIZ_SCAN */
127 #if defined(CPU_PP) && defined(HAVE_ADJUSTABLE_CPU_FREQ)
128 #define NEED_BOOST
129 #endif
131 static unsigned char bitbuffer[2][BUF_HEIGHT][BUF_WIDTH];
132 static int curbuf = 0;
133 static int scan_rate = DEFAULT_SCAN_RATE;
134 static bool need_refresh = false;
136 static void timer_isr(void)
138 rb->lcd_blit_mono(bitbuffer[curbuf][0], 0, 0, BUF_WIDTH, BUF_HEIGHT, BUF_WIDTH);
139 curbuf = (curbuf + 1) & 1;
140 if (need_refresh)
142 rb->lcd_update_rect(TEXT_X, TEXT_Y, LCD_WIDTH-TEXT_X, 8);
143 need_refresh = false;
147 int plugin_main(void)
149 unsigned char buf[32];
150 int button;
151 bool done = false;
152 bool change = true;
154 rb->lcd_setfont(FONT_SYSFIXED);
156 rb->lcd_putsxy(TEXT_X, TEXT_Y+12, "Adjust Frequ.");
157 rb->lcd_putsxy(TEXT_X, TEXT_Y+20, "so the block");
158 rb->lcd_putsxy(TEXT_X, TEXT_Y+28, "stops moving.");
159 #if (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) \
160 || (CONFIG_KEYPAD == IPOD_1G2G_PAD)
161 rb->lcd_putsxy(TEXT_X, TEXT_Y+40, "Scroll: Coarse");
162 #else
163 rb->lcd_putsxy(TEXT_X, TEXT_Y+40, "U/D: Coarse");
164 #endif
165 rb->lcd_putsxy(TEXT_X, TEXT_Y+48, "L/R: Fine");
166 rb->lcd_update();
168 rb->memset(bitbuffer[0], 0, sizeof(bitbuffer[0]));
169 rb->memset(bitbuffer[1], 0xff, sizeof(bitbuffer[1]));
170 #ifdef NEED_BOOST
171 rb->cpu_boost(true);
172 #endif
173 /* The actual frequency is twice the displayed value */
174 rb->timer_register(1, NULL, TIMER_FREQ * 5 / scan_rate,
175 timer_isr IF_COP(, CPU));
177 while (!done)
179 if (change)
181 /* The actual frequency is twice the displayed value */
182 rb->timer_set_period(TIMER_FREQ * 5 / scan_rate);
183 rb->snprintf(buf, sizeof(buf), "f: %d.%d Hz", scan_rate / 10,
184 scan_rate % 10);
185 rb->lcd_putsxy(TEXT_X, TEXT_Y, buf);
186 need_refresh = true;
187 change = false;
189 button = rb->button_get(true);
190 switch (button)
192 case SCANRATE_FASTINC:
193 case SCANRATE_FASTINC|BUTTON_REPEAT:
194 scan_rate += 10;
195 change = true;
196 break;
198 case SCANRATE_FASTDEC:
199 case SCANRATE_FASTDEC|BUTTON_REPEAT:
200 scan_rate -= 10;
201 change = true;
202 break;
204 case SCANRATE_INC:
205 case SCANRATE_INC|BUTTON_REPEAT:
206 scan_rate++;
207 change = true;
208 break;
210 case SCANRATE_DEC:
211 case SCANRATE_DEC|BUTTON_REPEAT:
212 scan_rate--;
213 change = true;
214 break;
216 case SCANRATE_DONE:
217 done = true;
218 break;
221 rb->timer_unregister();
222 #ifdef NEED_BOOST
223 rb->cpu_boost(false);
224 #endif
226 rb->lcd_setfont(FONT_UI);
228 return PLUGIN_OK;
232 /* this is the plugin entry point */
233 enum plugin_status plugin_start(const void* parameter)
235 (void)parameter;
236 return plugin_main();
239 #endif