Prepare new maemo release
[maemo-rb.git] / apps / plugins / test_scanrate.c
blobb558e765c3a0e1c2d72cac570416c8d483ed93bc
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"
23 #include "lib/pluginlib_actions.h"
25 /* this set the context to use with PLA */
26 static const struct button_mapping *plugin_contexts[] = { pla_main_ctx };
27 #define SCANRATE_QUIT PLA_EXIT
28 #define SCANRATE_QUIT2 PLA_CANCEL
29 #define SCANRATE_FASTINC PLA_UP
30 #define SCANRATE_FASTINC_REPEAT PLA_UP_REPEAT
31 #define SCANRATE_FASTDEC PLA_DOWN
32 #define SCANRATE_FASTDEC_REPEAT PLA_DOWN_REPEAT
34 #ifdef HAVE_SCROLLWHEEL
35 #define SCANRATE_INC PLA_SCROLL_FWD
36 #define SCANRATE_INC_REPEAT PLA_SCROLL_FWD_REPEAT
37 #define SCANRATE_DEC PLA_SCROLL_BACK
38 #define SCANRATE_DEC_REPEAT PLA_SCROLL_BACK_REPEAT
39 #else
40 #define SCANRATE_INC PLA_RIGHT
41 #define SCANRATE_INC_REPEAT PLA_RIGHT_REPEAT
42 #define SCANRATE_DEC PLA_LEFT
43 #define SCANRATE_DEC_REPEAT PLA_LEFT_REPEAT
44 #endif /*HAVE_SCROLLWHEEL*/
46 /* Default refresh rates in 1/10 Hz */
47 #if defined ARCHOS_RECORDER || defined ARCHOS_FMRECORDER \
48 || defined ARCHOS_RECORDERV2 || defined ARCHOS_ONDIOFM \
49 || defined ARCHOS_ONDIOSP
50 #define DEFAULT_SCAN_RATE 670
51 #elif defined IAUDIO_M3
52 #define DEFAULT_SCAN_RATE 1500
53 #define HORIZ_SCAN /* LCD controller updates the panel sideways */
54 #define NEED_BOOST
55 #elif defined MPIO_HD200
56 #define DEFAULT_SCAN_RATE 1460
57 #define NEED_BOOST
58 #elif defined MPIO_HD300
59 #define DEFAULT_SCAN_RATE 730
60 #elif defined IAUDIO_M5
61 #define DEFAULT_SCAN_RATE 730
62 #elif defined IPOD_1G2G
63 #define DEFAULT_SCAN_RATE 960
64 #elif defined IPOD_MINI2G || defined IPOD_MINI \
65 || defined IPOD_3G || defined IPOD_4G
66 #define DEFAULT_SCAN_RATE 870
67 #elif defined IRIVER_H100_SERIES
68 #define DEFAULT_SCAN_RATE 700
69 #elif defined SANSA_CLIP
70 #define DEFAULT_SCAN_RATE 780
71 #elif defined SAMSUNG_YH920
72 #define DEFAULT_SCAN_RATE 700
73 #else
74 #define DEFAULT_SCAN_RATE 700
75 #warning Generic default scanrate
76 #endif
78 #ifdef HORIZ_SCAN
79 #define TEXT_X 0
80 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
81 #define BUF_WIDTH ((LCD_WIDTH+7)/8)
82 #define BUF_HEIGHT (LCD_HEIGHT/4)
83 #define TEXT_Y BUF_HEIGHT
84 #else
85 #define BUF_WIDTH (LCD_WIDTH)
86 #define BUF_HEIGHT (LCD_HEIGHT/8/4)
87 #define TEXT_Y (BUF_HEIGHT*8)
88 #endif
89 #else /* !HORIZ_SCAN */
90 #define TEXT_Y 0
91 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
92 #define BUF_WIDTH ((LCD_WIDTH+7)/8/4)
93 #define BUF_HEIGHT LCD_HEIGHT
94 #define TEXT_X (BUF_WIDTH*8)
95 #else
96 #define BUF_WIDTH (LCD_WIDTH/4)
97 #define BUF_HEIGHT (LCD_HEIGHT/8)
98 #define TEXT_X BUF_WIDTH
99 #endif
100 #endif /* !HORIZ_SCAN */
102 #if defined(CPU_PP) && defined(HAVE_ADJUSTABLE_CPU_FREQ)
103 #define NEED_BOOST
104 #endif
106 static unsigned char bitbuffer[2][BUF_HEIGHT][BUF_WIDTH];
107 static int curbuf = 0;
108 static int scan_rate = DEFAULT_SCAN_RATE;
109 static bool need_refresh = false;
111 static void timer_isr(void)
113 rb->lcd_blit_mono(bitbuffer[curbuf][0], 0, 0, BUF_WIDTH, BUF_HEIGHT, BUF_WIDTH);
114 curbuf = (curbuf + 1) & 1;
115 if (need_refresh)
117 rb->lcd_update_rect(TEXT_X, TEXT_Y, LCD_WIDTH-TEXT_X, 8);
118 need_refresh = false;
122 int plugin_main(void)
124 int button;
125 bool done = false;
126 bool change = true;
128 rb->lcd_setfont(FONT_SYSFIXED);
130 rb->lcd_putsxy(TEXT_X, TEXT_Y+12, "Adjust Frequ.");
131 rb->lcd_putsxy(TEXT_X, TEXT_Y+20, "so the block");
132 rb->lcd_putsxy(TEXT_X, TEXT_Y+28, "stops moving.");
133 #if (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) \
134 || (CONFIG_KEYPAD == IPOD_1G2G_PAD)
135 rb->lcd_putsxy(TEXT_X, TEXT_Y+40, "Scroll: Coarse");
136 #else
137 rb->lcd_putsxy(TEXT_X, TEXT_Y+40, "U/D: Coarse");
138 #endif
139 rb->lcd_putsxy(TEXT_X, TEXT_Y+48, "L/R: Fine");
140 rb->lcd_update();
142 rb->memset(bitbuffer[0], 0, sizeof(bitbuffer[0]));
143 rb->memset(bitbuffer[1], 0xff, sizeof(bitbuffer[1]));
144 #ifdef NEED_BOOST
145 rb->cpu_boost(true);
146 #endif
147 /* The actual frequency is twice the displayed value */
148 rb->timer_register(1, NULL, TIMER_FREQ * 5 / scan_rate,
149 timer_isr IF_COP(, CPU));
151 while (!done)
153 if (change)
155 /* The actual frequency is twice the displayed value */
156 rb->timer_set_period(TIMER_FREQ * 5 / scan_rate);
157 rb->lcd_putsxyf(TEXT_X, TEXT_Y, "f: %d.%d Hz", scan_rate / 10,
158 scan_rate % 10);
159 need_refresh = true;
160 change = false;
162 button = pluginlib_getaction(TIMEOUT_BLOCK, plugin_contexts,
163 ARRAYLEN(plugin_contexts));
164 switch (button)
166 case SCANRATE_FASTINC:
167 case SCANRATE_FASTINC_REPEAT:
168 scan_rate += 10;
169 change = true;
170 break;
172 case SCANRATE_FASTDEC:
173 case SCANRATE_FASTDEC_REPEAT:
174 scan_rate -= 10;
175 change = true;
176 break;
178 case SCANRATE_INC:
179 case SCANRATE_INC_REPEAT:
180 scan_rate++;
181 change = true;
182 break;
184 case SCANRATE_DEC:
185 case SCANRATE_DEC_REPEAT:
186 scan_rate--;
187 change = true;
188 break;
190 case SCANRATE_QUIT:
191 case SCANRATE_QUIT2:
192 done = true;
193 break;
196 rb->timer_unregister();
197 #ifdef NEED_BOOST
198 rb->cpu_boost(false);
199 #endif
201 rb->lcd_setfont(FONT_UI);
203 return PLUGIN_OK;
207 /* this is the plugin entry point */
208 enum plugin_status plugin_start(const void* parameter)
210 (void)parameter;
211 return plugin_main();