Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 10 | * Oscilloscope, with many different modes of operation. |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 11 | * |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 12 | * Copyright (C) 2004-2006 Jens Arnold |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 13 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 14 | * This program is free software; you can redistribute it and/or |
| 15 | * modify it under the terms of the GNU General Public License |
| 16 | * as published by the Free Software Foundation; either version 2 |
| 17 | * of the License, or (at your option) any later version. |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 18 | * |
| 19 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 20 | * KIND, either express or implied. |
| 21 | * |
| 22 | ****************************************************************************/ |
| 23 | |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 24 | #include "plugin.h" |
Peter D'Hoye | cb53e3c | 2007-08-15 12:42:09 +0000 | [diff] [blame] | 25 | #include "helper.h" |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 26 | |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 27 | #ifdef HAVE_LCD_BITMAP |
Jens Arnold | 19b45a4 | 2006-03-08 01:14:46 +0000 | [diff] [blame] | 28 | #include "xlcd.h" |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 29 | #include "configfile.h" |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 30 | |
Jens Arnold | a36b1d4 | 2006-01-15 18:20:18 +0000 | [diff] [blame] | 31 | PLUGIN_HEADER |
| 32 | |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 33 | /* variable button definitions */ |
| 34 | #if CONFIG_KEYPAD == RECORDER_PAD |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 35 | #define OSCILLOSCOPE_QUIT BUTTON_OFF |
| 36 | #define OSCILLOSCOPE_DRAWMODE BUTTON_F1 |
| 37 | #define OSCILLOSCOPE_ADVMODE BUTTON_F2 |
| 38 | #define OSCILLOSCOPE_ORIENTATION BUTTON_F3 |
| 39 | #define OSCILLOSCOPE_PAUSE BUTTON_PLAY |
| 40 | #define OSCILLOSCOPE_SPEED_UP BUTTON_RIGHT |
| 41 | #define OSCILLOSCOPE_SPEED_DOWN BUTTON_LEFT |
| 42 | #define OSCILLOSCOPE_VOL_UP BUTTON_UP |
| 43 | #define OSCILLOSCOPE_VOL_DOWN BUTTON_DOWN |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 44 | |
Dave Chapman | d64e626 | 2007-01-14 13:48:09 +0000 | [diff] [blame] | 45 | #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD |
| 46 | #define OSCILLOSCOPE_QUIT BUTTON_OFF |
| 47 | #define OSCILLOSCOPE_DRAWMODE BUTTON_F1 |
| 48 | #define OSCILLOSCOPE_ADVMODE BUTTON_F2 |
| 49 | #define OSCILLOSCOPE_ORIENTATION BUTTON_F3 |
| 50 | #define OSCILLOSCOPE_PAUSE BUTTON_SELECT |
| 51 | #define OSCILLOSCOPE_SPEED_UP BUTTON_RIGHT |
| 52 | #define OSCILLOSCOPE_SPEED_DOWN BUTTON_LEFT |
| 53 | #define OSCILLOSCOPE_VOL_UP BUTTON_UP |
| 54 | #define OSCILLOSCOPE_VOL_DOWN BUTTON_DOWN |
| 55 | |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 56 | #elif CONFIG_KEYPAD == ONDIO_PAD |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 57 | #define OSCILLOSCOPE_QUIT BUTTON_OFF |
| 58 | #define OSCILLOSCOPE_DRAWMODE_PRE BUTTON_MENU |
| 59 | #define OSCILLOSCOPE_DRAWMODE (BUTTON_MENU | BUTTON_REL) |
| 60 | #define OSCILLOSCOPE_ADVMODE (BUTTON_MENU | BUTTON_RIGHT) |
| 61 | #define OSCILLOSCOPE_ORIENTATION (BUTTON_MENU | BUTTON_LEFT) |
| 62 | #define OSCILLOSCOPE_PAUSE (BUTTON_MENU | BUTTON_OFF) |
| 63 | #define OSCILLOSCOPE_SPEED_UP BUTTON_RIGHT |
| 64 | #define OSCILLOSCOPE_SPEED_DOWN BUTTON_LEFT |
| 65 | #define OSCILLOSCOPE_VOL_UP BUTTON_UP |
| 66 | #define OSCILLOSCOPE_VOL_DOWN BUTTON_DOWN |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 67 | |
| 68 | #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD) |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 69 | #define OSCILLOSCOPE_QUIT BUTTON_OFF |
| 70 | #define OSCILLOSCOPE_DRAWMODE BUTTON_SELECT |
| 71 | #define OSCILLOSCOPE_ADVMODE BUTTON_MODE |
| 72 | #define OSCILLOSCOPE_ORIENTATION BUTTON_REC |
| 73 | #define OSCILLOSCOPE_PAUSE BUTTON_ON |
| 74 | #define OSCILLOSCOPE_SPEED_UP BUTTON_RIGHT |
| 75 | #define OSCILLOSCOPE_SPEED_DOWN BUTTON_LEFT |
| 76 | #define OSCILLOSCOPE_VOL_UP BUTTON_UP |
| 77 | #define OSCILLOSCOPE_VOL_DOWN BUTTON_DOWN |
Kevin Ferrare | 0e027bd | 2006-06-30 16:43:47 +0000 | [diff] [blame] | 78 | #define OSCILLOSCOPE_RC_QUIT BUTTON_RC_STOP |
Jens Arnold | 61e798f | 2007-04-09 17:03:48 +0000 | [diff] [blame] | 79 | |
Jens Arnold | b701322 | 2007-07-27 09:57:27 +0000 | [diff] [blame] | 80 | #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \ |
| 81 | (CONFIG_KEYPAD == IPOD_1G2G_PAD) |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 82 | #define OSCILLOSCOPE_QUIT (BUTTON_SELECT | BUTTON_MENU) |
| 83 | #define OSCILLOSCOPE_DRAWMODE (BUTTON_SELECT | BUTTON_PLAY) |
| 84 | #define OSCILLOSCOPE_ADVMODE (BUTTON_SELECT | BUTTON_RIGHT) |
| 85 | #define OSCILLOSCOPE_ORIENTATION (BUTTON_SELECT | BUTTON_LEFT) |
| 86 | #define OSCILLOSCOPE_PAUSE BUTTON_PLAY |
| 87 | #define OSCILLOSCOPE_SPEED_UP BUTTON_RIGHT |
| 88 | #define OSCILLOSCOPE_SPEED_DOWN BUTTON_LEFT |
| 89 | #define OSCILLOSCOPE_VOL_UP BUTTON_SCROLL_FWD |
| 90 | #define OSCILLOSCOPE_VOL_DOWN BUTTON_SCROLL_BACK |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 91 | |
| 92 | #elif (CONFIG_KEYPAD == GIGABEAT_PAD) |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 93 | #define OSCILLOSCOPE_QUIT BUTTON_POWER |
| 94 | #define OSCILLOSCOPE_DRAWMODE BUTTON_SELECT |
| 95 | #define OSCILLOSCOPE_ADVMODE BUTTON_DOWN |
| 96 | #define OSCILLOSCOPE_ORIENTATION BUTTON_UP |
| 97 | #define OSCILLOSCOPE_PAUSE BUTTON_A |
| 98 | #define OSCILLOSCOPE_SPEED_UP BUTTON_RIGHT |
| 99 | #define OSCILLOSCOPE_SPEED_DOWN BUTTON_LEFT |
| 100 | #define OSCILLOSCOPE_VOL_UP BUTTON_VOL_UP |
| 101 | #define OSCILLOSCOPE_VOL_DOWN BUTTON_VOL_DOWN |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 102 | |
Barry Wardell | 24f4a2a | 2006-10-26 13:38:09 +0000 | [diff] [blame] | 103 | #elif (CONFIG_KEYPAD == SANSA_E200_PAD) |
| 104 | #define OSCILLOSCOPE_QUIT BUTTON_POWER |
| 105 | #define OSCILLOSCOPE_DRAWMODE BUTTON_SELECT |
| 106 | #define OSCILLOSCOPE_ADVMODE BUTTON_DOWN |
| 107 | #define OSCILLOSCOPE_ORIENTATION BUTTON_UP |
| 108 | #define OSCILLOSCOPE_PAUSE BUTTON_REC |
| 109 | #define OSCILLOSCOPE_SPEED_UP BUTTON_RIGHT |
| 110 | #define OSCILLOSCOPE_SPEED_DOWN BUTTON_LEFT |
Jonathan Gordon | 81ba146 | 2008-01-10 08:08:31 +0000 | [diff] [blame] | 111 | #define OSCILLOSCOPE_VOL_UP BUTTON_SCROLL_FWD |
| 112 | #define OSCILLOSCOPE_VOL_DOWN BUTTON_SCROLL_BACK |
Barry Wardell | 24f4a2a | 2006-10-26 13:38:09 +0000 | [diff] [blame] | 113 | |
Marianne Arnold | 12ddb8e | 2007-09-20 10:49:48 +0000 | [diff] [blame] | 114 | #elif (CONFIG_KEYPAD == SANSA_C200_PAD) |
| 115 | #define OSCILLOSCOPE_QUIT BUTTON_POWER |
| 116 | #define OSCILLOSCOPE_DRAWMODE BUTTON_SELECT |
| 117 | #define OSCILLOSCOPE_ADVMODE BUTTON_DOWN |
| 118 | #define OSCILLOSCOPE_ORIENTATION BUTTON_UP |
| 119 | #define OSCILLOSCOPE_PAUSE BUTTON_REC |
| 120 | #define OSCILLOSCOPE_SPEED_UP BUTTON_RIGHT |
| 121 | #define OSCILLOSCOPE_SPEED_DOWN BUTTON_LEFT |
| 122 | #define OSCILLOSCOPE_VOL_UP BUTTON_VOL_UP |
| 123 | #define OSCILLOSCOPE_VOL_DOWN BUTTON_VOL_DOWN |
| 124 | |
Jens Arnold | 85a226d | 2007-03-16 23:02:39 +0000 | [diff] [blame] | 125 | #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 126 | #define OSCILLOSCOPE_QUIT BUTTON_POWER |
| 127 | #define OSCILLOSCOPE_DRAWMODE_PRE BUTTON_SELECT |
| 128 | #define OSCILLOSCOPE_DRAWMODE (BUTTON_SELECT | BUTTON_REL) |
| 129 | #define OSCILLOSCOPE_ADVMODE BUTTON_REC |
Jens Arnold | 61e798f | 2007-04-09 17:03:48 +0000 | [diff] [blame] | 130 | #define OSCILLOSCOPE_ORIENTATION_PRE BUTTON_SELECT |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 131 | #define OSCILLOSCOPE_ORIENTATION (BUTTON_SELECT | BUTTON_REPEAT) |
| 132 | #define OSCILLOSCOPE_PAUSE BUTTON_PLAY |
| 133 | #define OSCILLOSCOPE_SPEED_UP BUTTON_RIGHT |
| 134 | #define OSCILLOSCOPE_SPEED_DOWN BUTTON_LEFT |
| 135 | #define OSCILLOSCOPE_VOL_UP BUTTON_UP |
| 136 | #define OSCILLOSCOPE_VOL_DOWN BUTTON_DOWN |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 137 | |
Daniel Stenberg | 1e88be5 | 2006-08-03 20:17:25 +0000 | [diff] [blame] | 138 | #elif CONFIG_KEYPAD == IRIVER_H10_PAD |
| 139 | #define OSCILLOSCOPE_QUIT BUTTON_POWER |
| 140 | #define OSCILLOSCOPE_DRAWMODE_PRE BUTTON_REW |
| 141 | #define OSCILLOSCOPE_DRAWMODE (BUTTON_REW | BUTTON_REL) |
| 142 | #define OSCILLOSCOPE_ADVMODE BUTTON_FF |
Jens Arnold | 61e798f | 2007-04-09 17:03:48 +0000 | [diff] [blame] | 143 | #define OSCILLOSCOPE_ORIENTATION_PRE BUTTON_REW |
Daniel Stenberg | 1e88be5 | 2006-08-03 20:17:25 +0000 | [diff] [blame] | 144 | #define OSCILLOSCOPE_ORIENTATION (BUTTON_REW | BUTTON_REPEAT) |
| 145 | #define OSCILLOSCOPE_PAUSE BUTTON_PLAY |
| 146 | #define OSCILLOSCOPE_SPEED_UP BUTTON_RIGHT |
| 147 | #define OSCILLOSCOPE_SPEED_DOWN BUTTON_LEFT |
| 148 | #define OSCILLOSCOPE_VOL_UP BUTTON_SCROLL_UP |
| 149 | #define OSCILLOSCOPE_VOL_DOWN BUTTON_SCROLL_DOWN |
| 150 | |
Will Robertson | 8215b34 | 2008-02-17 12:23:02 +0000 | [diff] [blame] | 151 | #elif CONFIG_KEYPAD == GIGABEAT_S_PAD |
| 152 | #define OSCILLOSCOPE_QUIT BUTTON_BACK |
| 153 | #define OSCILLOSCOPE_DRAWMODE BUTTON_PREV |
| 154 | #define OSCILLOSCOPE_ADVMODE BUTTON_NEXT |
| 155 | #define OSCILLOSCOPE_ORIENTATION BUTTON_MENU |
| 156 | #define OSCILLOSCOPE_PAUSE BUTTON_PLAY |
| 157 | #define OSCILLOSCOPE_SPEED_UP BUTTON_RIGHT |
| 158 | #define OSCILLOSCOPE_SPEED_DOWN BUTTON_LEFT |
| 159 | #define OSCILLOSCOPE_VOL_UP BUTTON_VOL_UP |
| 160 | #define OSCILLOSCOPE_VOL_DOWN BUTTON_VOL_DOWN |
| 161 | |
Robert Kukla | d6c8b57 | 2008-03-01 22:55:09 +0000 | [diff] [blame] | 162 | #elif (CONFIG_KEYPAD == MROBE100_PAD) |
| 163 | #define OSCILLOSCOPE_QUIT BUTTON_POWER |
| 164 | #define OSCILLOSCOPE_DRAWMODE BUTTON_SELECT |
| 165 | #define OSCILLOSCOPE_ADVMODE BUTTON_MENU |
| 166 | #define OSCILLOSCOPE_ORIENTATION BUTTON_PLAY |
| 167 | #define OSCILLOSCOPE_PAUSE BUTTON_DISPLAY |
| 168 | #define OSCILLOSCOPE_SPEED_UP BUTTON_RIGHT |
| 169 | #define OSCILLOSCOPE_SPEED_DOWN BUTTON_LEFT |
| 170 | #define OSCILLOSCOPE_VOL_UP BUTTON_UP |
| 171 | #define OSCILLOSCOPE_VOL_DOWN BUTTON_DOWN |
Will Robertson | 8215b34 | 2008-02-17 12:23:02 +0000 | [diff] [blame] | 172 | |
Jens Arnold | 29361ab | 2008-03-22 10:24:28 +0000 | [diff] [blame] | 173 | #elif CONFIG_KEYPAD == IAUDIO_M3_PAD |
| 174 | #define OSCILLOSCOPE_QUIT BUTTON_RC_REC |
| 175 | #define OSCILLOSCOPE_DRAWMODE_PRE BUTTON_RC_MODE |
| 176 | #define OSCILLOSCOPE_DRAWMODE (BUTTON_RC_MODE|BUTTON_REL) |
| 177 | #define OSCILLOSCOPE_ADVMODE BUTTON_RC_MENU |
| 178 | #define OSCILLOSCOPE_ORIENTATION_PRE BUTTON_RC_MODE |
| 179 | #define OSCILLOSCOPE_ORIENTATION (BUTTON_RC_MODE|BUTTON_REPEAT) |
| 180 | #define OSCILLOSCOPE_PAUSE BUTTON_RC_PLAY |
| 181 | #define OSCILLOSCOPE_SPEED_UP BUTTON_RC_FF |
| 182 | #define OSCILLOSCOPE_SPEED_DOWN BUTTON_RC_REW |
| 183 | #define OSCILLOSCOPE_VOL_UP BUTTON_RC_VOL_UP |
| 184 | #define OSCILLOSCOPE_VOL_DOWN BUTTON_RC_VOL_DOWN |
| 185 | |
Rob Purchase | 554d7ed | 2008-03-22 22:03:34 +0000 | [diff] [blame] | 186 | #elif CONFIG_KEYPAD == COWOND2_PAD |
| 187 | #define OSCILLOSCOPE_QUIT BUTTON_POWER |
Rob Purchase | 554d7ed | 2008-03-22 22:03:34 +0000 | [diff] [blame] | 188 | #define OSCILLOSCOPE_VOL_UP BUTTON_PLUS |
| 189 | #define OSCILLOSCOPE_VOL_DOWN BUTTON_MINUS |
| 190 | |
Robert Kukla | d6c8b57 | 2008-03-01 22:55:09 +0000 | [diff] [blame] | 191 | #else |
| 192 | #error No keymap defined! |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 193 | #endif |
| 194 | |
Rob Purchase | 297e050 | 2008-04-27 15:30:19 +0000 | [diff] [blame] | 195 | #ifdef HAVE_TOUCHPAD |
| 196 | #ifndef OSCILLOSCOPE_QUIT |
| 197 | #define OSCILLOSCOPE_QUIT BUTTON_TOPLEFT |
| 198 | #endif |
| 199 | #ifndef OSCILLOSCOPE_DRAWMODE |
| 200 | #define OSCILLOSCOPE_DRAWMODE BUTTON_TOPMIDDLE |
| 201 | #endif |
| 202 | #ifndef OSCILLOSCOPE_ADVMODE |
| 203 | #define OSCILLOSCOPE_ADVMODE BUTTON_BOTTOMMIDDLE |
| 204 | #endif |
| 205 | #ifndef OSCILLOSCOPE_ORIENTATION |
| 206 | #define OSCILLOSCOPE_ORIENTATION BUTTON_BOTTOMLEFT |
| 207 | #endif |
| 208 | #ifndef OSCILLOSCOPE_PAUSE |
| 209 | #define OSCILLOSCOPE_PAUSE BUTTON_CENTER |
| 210 | #endif |
| 211 | #ifndef OSCILLOSCOPE_SPEED_UP |
| 212 | #define OSCILLOSCOPE_SPEED_UP BUTTON_MIDRIGHT |
| 213 | #endif |
| 214 | #ifndef OSCILLOSCOPE_SPEED_DOWN |
| 215 | #define OSCILLOSCOPE_SPEED_DOWN BUTTON_MIDLEFT |
| 216 | #endif |
| 217 | #ifndef OSCILLOSCOPE_VOL_UP |
| 218 | #define OSCILLOSCOPE_VOL_UP BUTTON_TOPRIGHT |
| 219 | #endif |
| 220 | #ifndef OSCILLOSCOPE_VOL_DOWN |
| 221 | #define OSCILLOSCOPE_VOL_DOWN BUTTON_BOTTOMRIGHT |
| 222 | #endif |
| 223 | #endif |
| 224 | |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 225 | /* colours */ |
| 226 | #if LCD_DEPTH > 1 |
| 227 | #ifdef HAVE_LCD_COLOR |
| 228 | #define BACKG_COLOR LCD_BLACK |
| 229 | #define GRAPH_COLOR LCD_RGBPACK(128, 255, 0) |
| 230 | #define CURSOR_COLOR LCD_RGBPACK(255, 0, 0) |
| 231 | #else |
| 232 | #define BACKG_COLOR LCD_WHITE |
| 233 | #define GRAPH_COLOR LCD_BLACK |
| 234 | #define CURSOR_COLOR LCD_DARKGRAY |
| 235 | #endif |
| 236 | #endif |
| 237 | |
| 238 | enum { DRAW_FILLED, DRAW_LINE, DRAW_PIXEL, MAX_DRAW }; |
| 239 | enum { ADV_SCROLL, ADV_WRAP, MAX_ADV }; |
| 240 | enum { OSC_HORIZ, OSC_VERT, MAX_OSC }; |
| 241 | |
| 242 | #define CFGFILE_VERSION 0 /* Current config file version */ |
| 243 | #define CFGFILE_MINVERSION 0 /* Minimum config file version to accept */ |
| 244 | |
| 245 | |
| 246 | #define MAX_PEAK 0x8000 |
| 247 | |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 248 | #if defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC) |
| 249 | #define mas_codec_readreg(x) rand()%MAX_PEAK |
| 250 | #endif |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 251 | |
| 252 | /* global variables */ |
| 253 | |
Steve Bavin | 6526577 | 2008-05-13 09:57:56 +0000 | [diff] [blame] | 254 | const struct plugin_api* rb; /* global api struct pointer */ |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 255 | |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 256 | /* settings */ |
Jens Arnold | 37f529c | 2006-03-11 08:35:45 +0000 | [diff] [blame] | 257 | struct osc_config { |
| 258 | int delay; /* in ticks */ |
| 259 | int draw; |
| 260 | int advance; |
| 261 | int orientation; |
| 262 | }; |
| 263 | |
| 264 | struct osc_config osc_disk = { 2, DRAW_FILLED, ADV_SCROLL, OSC_HORIZ }; |
| 265 | struct osc_config osc; /* running config */ |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 266 | |
| 267 | static const char cfg_filename[] = "oscilloscope.cfg"; |
| 268 | static char *draw_str[3] = { "filled", "line", "pixel" }; |
| 269 | static char *advance_str[2] = { "scroll", "wrap" }; |
| 270 | static char *orientation_str[2] = { "horizontal", "vertical" }; |
| 271 | |
Jens Arnold | 37f529c | 2006-03-11 08:35:45 +0000 | [diff] [blame] | 272 | struct configdata disk_config[] = { |
| 273 | { TYPE_INT, 1, 99, &osc_disk.delay, "delay", NULL, NULL }, |
| 274 | { TYPE_ENUM, 0, MAX_DRAW, &osc_disk.draw, "draw", draw_str, NULL }, |
| 275 | { TYPE_ENUM, 0, MAX_ADV, &osc_disk.advance, "advance", advance_str, NULL }, |
| 276 | { TYPE_ENUM, 0, MAX_OSC, &osc_disk.orientation, "orientation", orientation_str, NULL } |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 277 | }; |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 278 | |
Jens Arnold | 37f529c | 2006-03-11 08:35:45 +0000 | [diff] [blame] | 279 | |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 280 | long last_tick = 0; /* time of last drawing */ |
| 281 | int last_pos = 0; /* last x or y drawing position. Reset for aspect switch. */ |
| 282 | int last_left; /* last channel values */ |
| 283 | int last_right; |
| 284 | |
| 285 | unsigned char message[16]; /* message to display */ |
| 286 | bool displaymsg = false; |
| 287 | int font_height = 8; |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 288 | |
| 289 | /* implementation */ |
| 290 | |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 291 | void anim_horizontal(int cur_left, int cur_right) |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 292 | { |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 293 | int cur_x, x; |
| 294 | int left, right, dl, dr; |
| 295 | long cur_tick = *rb->current_tick; |
Jens Arnold | 37f529c | 2006-03-11 08:35:45 +0000 | [diff] [blame] | 296 | long d = (cur_tick - last_tick) / osc.delay; |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 297 | bool full_update = false; |
| 298 | |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 299 | if (d == 0) /* too early, bail out */ |
| 300 | return; |
| 301 | |
| 302 | last_tick = cur_tick; |
| 303 | |
| 304 | if (d > HZ) /* first call or too much delay, (re)start */ |
| 305 | { |
| 306 | last_left = cur_left; |
| 307 | last_right = cur_right; |
| 308 | return; |
| 309 | } |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 310 | cur_x = last_pos + d; |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 311 | |
| 312 | if (cur_x >= LCD_WIDTH) |
| 313 | { |
Jens Arnold | 37f529c | 2006-03-11 08:35:45 +0000 | [diff] [blame] | 314 | if (osc.advance == ADV_SCROLL) |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 315 | { |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 316 | int shift = cur_x - (LCD_WIDTH-1); |
| 317 | xlcd_scroll_left(shift); |
| 318 | full_update = true; |
| 319 | cur_x -= shift; |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 320 | last_pos -= shift; |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 321 | } |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 322 | else |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 323 | { |
| 324 | cur_x -= LCD_WIDTH; |
| 325 | } |
| 326 | } |
| 327 | rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); |
| 328 | |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 329 | if (cur_x > last_pos) |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 330 | { |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 331 | rb->lcd_fillrect(last_pos + 1, 0, d, LCD_HEIGHT); |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 332 | } |
| 333 | else |
| 334 | { |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 335 | rb->lcd_fillrect(last_pos + 1, 0, LCD_WIDTH - last_pos, LCD_HEIGHT); |
| 336 | rb->lcd_fillrect(0, 0, cur_x + 1, LCD_HEIGHT); |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 337 | } |
| 338 | rb->lcd_set_drawmode(DRMODE_SOLID); |
| 339 | |
Jens Arnold | 37f529c | 2006-03-11 08:35:45 +0000 | [diff] [blame] | 340 | switch (osc.draw) |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 341 | { |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 342 | case DRAW_FILLED: |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 343 | left = last_left; |
| 344 | right = last_right; |
| 345 | dl = (cur_left - left) / d; |
| 346 | dr = (cur_right - right) / d; |
| 347 | |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 348 | for (x = last_pos + 1; d > 0; x++, d--) |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 349 | { |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 350 | if (x == LCD_WIDTH) |
| 351 | x = 0; |
| 352 | |
| 353 | left += dl; |
| 354 | right += dr; |
| 355 | |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 356 | rb->lcd_vline(x, LCD_HEIGHT/2-1, |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 357 | LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * left) >> 16)); |
| 358 | rb->lcd_vline(x, LCD_HEIGHT/2+1, |
| 359 | LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * right) >> 16)); |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 360 | } |
| 361 | break; |
| 362 | |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 363 | case DRAW_LINE: |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 364 | if (cur_x > last_pos) |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 365 | { |
| 366 | rb->lcd_drawline( |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 367 | last_pos, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * last_left) >> 16), |
| 368 | cur_x, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * cur_left) >> 16) |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 369 | ); |
| 370 | rb->lcd_drawline( |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 371 | last_pos, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * last_right) >> 16), |
| 372 | cur_x, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * cur_right) >> 16) |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 373 | ); |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 374 | } |
| 375 | else |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 376 | { |
| 377 | left = last_left |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 378 | + (LCD_WIDTH - last_pos) * (last_left - cur_left) / d; |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 379 | right = last_right |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 380 | + (LCD_WIDTH - last_pos) * (last_right - cur_right) / d; |
Jens Arnold | 19b45a4 | 2006-03-08 01:14:46 +0000 | [diff] [blame] | 381 | |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 382 | rb->lcd_drawline( |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 383 | last_pos, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * last_left) >> 16), |
| 384 | LCD_WIDTH, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * left) >> 16) |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 385 | ); |
| 386 | rb->lcd_drawline( |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 387 | last_pos, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * last_right) >> 16), |
| 388 | LCD_WIDTH, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * right) >> 16) |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 389 | ); |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 390 | if (cur_x > 0) |
| 391 | { |
| 392 | rb->lcd_drawline( |
| 393 | 0, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * left) >> 16), |
| 394 | cur_x, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * cur_left) >> 16) |
| 395 | ); |
| 396 | rb->lcd_drawline( |
| 397 | 0, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * right) >> 16), |
| 398 | cur_x, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * cur_right) >> 16) |
| 399 | ); |
| 400 | } |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 401 | } |
| 402 | break; |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 403 | |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 404 | case DRAW_PIXEL: |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 405 | left = last_left; |
| 406 | right = last_right; |
| 407 | dl = (cur_left - left) / d; |
| 408 | dr = (cur_right - right) / d; |
| 409 | |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 410 | for (x = last_pos + 1; d > 0; x++, d--) |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 411 | { |
| 412 | if (x == LCD_WIDTH) |
| 413 | x = 0; |
| 414 | |
| 415 | left += dl; |
| 416 | right += dr; |
| 417 | |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 418 | rb->lcd_drawpixel(x, LCD_HEIGHT/2-1 - (((LCD_HEIGHT-2) * left) >> 16)); |
| 419 | rb->lcd_drawpixel(x, LCD_HEIGHT/2+1 + (((LCD_HEIGHT-2) * right) >> 16)); |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 420 | } |
| 421 | break; |
| 422 | |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 423 | } |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 424 | last_left = cur_left; |
| 425 | last_right = cur_right; |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 426 | |
Jens Arnold | c91623b | 2006-03-12 13:44:51 +0000 | [diff] [blame] | 427 | if (displaymsg) |
| 428 | { |
| 429 | int width; |
| 430 | |
| 431 | rb->lcd_getstringsize(message, &width, NULL); |
| 432 | last_pos -= width - 1; |
| 433 | rb->lcd_putsxy(last_pos, 0, message); |
| 434 | displaymsg = false; |
| 435 | |
| 436 | if (last_pos < 0) |
| 437 | last_pos = 0; |
| 438 | } |
| 439 | |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 440 | if (full_update) |
| 441 | { |
| 442 | rb->lcd_update(); |
| 443 | } |
| 444 | else |
| 445 | { |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 446 | #if LCD_DEPTH > 1 /* cursor bar */ |
| 447 | rb->lcd_set_foreground(CURSOR_COLOR); |
| 448 | rb->lcd_vline(cur_x + 1, 0, LCD_HEIGHT-1); |
| 449 | rb->lcd_set_foreground(GRAPH_COLOR); |
| 450 | #else |
| 451 | rb->lcd_set_drawmode(DRMODE_COMPLEMENT); |
| 452 | rb->lcd_vline(cur_x + 1, 0, LCD_HEIGHT-1); |
| 453 | rb->lcd_set_drawmode(DRMODE_SOLID); |
| 454 | #endif |
| 455 | |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 456 | if (cur_x > last_pos) |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 457 | { |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 458 | rb->lcd_update_rect(last_pos, 0, cur_x - last_pos + 2, LCD_HEIGHT); |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 459 | } |
| 460 | else |
| 461 | { |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 462 | rb->lcd_update_rect(last_pos, 0, LCD_WIDTH - last_pos, LCD_HEIGHT); |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 463 | rb->lcd_update_rect(0, 0, cur_x + 2, LCD_HEIGHT); |
| 464 | } |
| 465 | } |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 466 | last_pos = cur_x; |
| 467 | } |
| 468 | |
| 469 | void anim_vertical(int cur_left, int cur_right) |
| 470 | { |
| 471 | int cur_y, y; |
| 472 | int left, right, dl, dr; |
| 473 | long cur_tick = *rb->current_tick; |
Jens Arnold | 37f529c | 2006-03-11 08:35:45 +0000 | [diff] [blame] | 474 | long d = (cur_tick - last_tick) / osc.delay; |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 475 | bool full_update = false; |
| 476 | |
| 477 | if (d == 0) /* too early, bail out */ |
| 478 | return; |
| 479 | |
| 480 | last_tick = cur_tick; |
| 481 | |
| 482 | if (d > HZ) /* first call or too much delay, (re)start */ |
| 483 | { |
| 484 | last_left = cur_left; |
| 485 | last_right = cur_right; |
| 486 | return; |
| 487 | } |
| 488 | cur_y = last_pos + d; |
| 489 | |
| 490 | if (cur_y >= LCD_HEIGHT) |
| 491 | { |
Jens Arnold | 37f529c | 2006-03-11 08:35:45 +0000 | [diff] [blame] | 492 | if (osc.advance == ADV_SCROLL) |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 493 | { |
| 494 | int shift = cur_y - (LCD_HEIGHT-1); |
| 495 | xlcd_scroll_up(shift); |
| 496 | full_update = true; |
| 497 | cur_y -= shift; |
| 498 | last_pos -= shift; |
| 499 | } |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 500 | else |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 501 | { |
| 502 | cur_y -= LCD_HEIGHT; |
| 503 | } |
| 504 | } |
| 505 | rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); |
| 506 | |
| 507 | if (cur_y > last_pos) |
| 508 | { |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 509 | rb->lcd_fillrect(0, last_pos + 1, LCD_WIDTH, d); |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 510 | } |
| 511 | else |
| 512 | { |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 513 | rb->lcd_fillrect(0, last_pos + 1, LCD_WIDTH, LCD_HEIGHT - last_pos); |
| 514 | rb->lcd_fillrect(0, 0, LCD_WIDTH, cur_y + 1); |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 515 | } |
| 516 | rb->lcd_set_drawmode(DRMODE_SOLID); |
| 517 | |
Jens Arnold | 37f529c | 2006-03-11 08:35:45 +0000 | [diff] [blame] | 518 | switch (osc.draw) |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 519 | { |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 520 | case DRAW_FILLED: |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 521 | left = last_left; |
| 522 | right = last_right; |
| 523 | dl = (cur_left - left) / d; |
| 524 | dr = (cur_right - right) / d; |
| 525 | |
| 526 | for (y = last_pos + 1; d > 0; y++, d--) |
| 527 | { |
| 528 | if (y == LCD_HEIGHT) |
| 529 | y = 0; |
| 530 | |
| 531 | left += dl; |
| 532 | right += dr; |
| 533 | |
| 534 | rb->lcd_hline(LCD_WIDTH/2-1, |
| 535 | LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * left) >> 16), y); |
| 536 | rb->lcd_hline(LCD_WIDTH/2+1, |
| 537 | LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * right) >> 16), y); |
| 538 | } |
| 539 | break; |
| 540 | |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 541 | case DRAW_LINE: |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 542 | if (cur_y > last_pos) |
| 543 | { |
| 544 | rb->lcd_drawline( |
| 545 | LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * last_left) >> 16), last_pos, |
| 546 | LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * cur_left) >> 16), cur_y |
| 547 | ); |
| 548 | rb->lcd_drawline( |
| 549 | LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * last_right) >> 16), last_pos, |
| 550 | LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * cur_right) >> 16), cur_y |
| 551 | ); |
| 552 | } |
| 553 | else |
| 554 | { |
| 555 | left = last_left |
| 556 | + (LCD_HEIGHT - last_pos) * (last_left - cur_left) / d; |
| 557 | right = last_right |
| 558 | + (LCD_HEIGHT - last_pos) * (last_right - cur_right) / d; |
| 559 | |
| 560 | rb->lcd_drawline( |
| 561 | LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * last_left) >> 16), last_pos, |
| 562 | LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * left) >> 16), LCD_HEIGHT |
| 563 | ); |
| 564 | rb->lcd_drawline( |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 565 | LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * last_right) >> 16), last_pos, |
| 566 | LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * right) >> 16), LCD_HEIGHT |
| 567 | ); |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 568 | if (cur_y > 0) |
| 569 | { |
| 570 | rb->lcd_drawline( |
| 571 | LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * left) >> 16), 0, |
| 572 | LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * cur_left) >> 16), cur_y |
| 573 | ); |
| 574 | rb->lcd_drawline( |
| 575 | LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * right) >> 16), 0, |
| 576 | LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * cur_right) >> 16), cur_y |
| 577 | ); |
| 578 | } |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 579 | } |
| 580 | break; |
| 581 | |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 582 | case DRAW_PIXEL: |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 583 | left = last_left; |
| 584 | right = last_right; |
| 585 | dl = (cur_left - left) / d; |
| 586 | dr = (cur_right - right) / d; |
| 587 | |
| 588 | for (y = last_pos + 1; d > 0; y++, d--) |
| 589 | { |
| 590 | if (y == LCD_HEIGHT) |
| 591 | y = 0; |
| 592 | |
| 593 | left += dl; |
| 594 | right += dr; |
| 595 | |
| 596 | rb->lcd_drawpixel(LCD_WIDTH/2-1 - (((LCD_WIDTH-2) * left) >> 16), y); |
| 597 | rb->lcd_drawpixel(LCD_WIDTH/2+1 + (((LCD_WIDTH-2) * right) >> 16), y); |
| 598 | } |
| 599 | break; |
| 600 | |
| 601 | } |
| 602 | last_left = cur_left; |
| 603 | last_right = cur_right; |
| 604 | |
| 605 | if (displaymsg) |
| 606 | { |
| 607 | last_pos -= font_height - 1; |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 608 | rb->lcd_putsxy(0, last_pos, message); |
| 609 | displaymsg = false; |
Jens Arnold | c91623b | 2006-03-12 13:44:51 +0000 | [diff] [blame] | 610 | |
| 611 | if (last_pos < 0) |
| 612 | last_pos = 0; |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | if (full_update) |
| 616 | { |
| 617 | rb->lcd_update(); |
| 618 | } |
| 619 | else |
| 620 | { |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 621 | #if LCD_DEPTH > 1 /* cursor bar */ |
| 622 | rb->lcd_set_foreground(CURSOR_COLOR); |
| 623 | rb->lcd_hline(0, LCD_WIDTH-1, cur_y + 1); |
| 624 | rb->lcd_set_foreground(GRAPH_COLOR); |
| 625 | #else |
| 626 | rb->lcd_set_drawmode(DRMODE_COMPLEMENT); |
| 627 | rb->lcd_hline(0, LCD_WIDTH-1, cur_y + 1); |
| 628 | rb->lcd_set_drawmode(DRMODE_SOLID); |
| 629 | #endif |
| 630 | |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 631 | if (cur_y > last_pos) |
| 632 | { |
| 633 | rb->lcd_update_rect(0, last_pos, LCD_WIDTH, cur_y - last_pos + 2); |
| 634 | } |
| 635 | else |
| 636 | { |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 637 | rb->lcd_update_rect(0, last_pos, LCD_WIDTH, LCD_HEIGHT - last_pos); |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 638 | rb->lcd_update_rect(0, 0, LCD_WIDTH, cur_y + 2); |
| 639 | } |
| 640 | } |
| 641 | last_pos = cur_y; |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | void cleanup(void *parameter) |
| 645 | { |
| 646 | (void)parameter; |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 647 | #if LCD_DEPTH > 1 |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 648 | rb->lcd_set_foreground(LCD_DEFAULT_FG); |
| 649 | rb->lcd_set_background(LCD_DEFAULT_BG); |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 650 | #endif |
Peter D'Hoye | cb53e3c | 2007-08-15 12:42:09 +0000 | [diff] [blame] | 651 | /* Turn on backlight timeout (revert to settings) */ |
Peter D'Hoye | 767c0ec | 2007-08-16 23:01:18 +0000 | [diff] [blame] | 652 | backlight_use_settings(rb); /* backlight control in lib/helper.c */ |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 653 | } |
| 654 | |
Steve Bavin | 6526577 | 2008-05-13 09:57:56 +0000 | [diff] [blame] | 655 | enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter) |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 656 | { |
| 657 | int button, vol; |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 658 | int lastbutton = BUTTON_NONE; |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 659 | bool exit = false; |
| 660 | bool paused = false; |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 661 | bool tell_speed; |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 662 | |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 663 | (void)parameter; |
| 664 | rb = api; |
Jens Arnold | 19b45a4 | 2006-03-08 01:14:46 +0000 | [diff] [blame] | 665 | |
| 666 | xlcd_init(rb); |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 667 | configfile_init(rb); |
| 668 | |
Jens Arnold | 37f529c | 2006-03-11 08:35:45 +0000 | [diff] [blame] | 669 | configfile_load(cfg_filename, disk_config, |
| 670 | sizeof(disk_config) / sizeof(disk_config[0]), |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 671 | CFGFILE_MINVERSION); |
Jens Arnold | 37f529c | 2006-03-11 08:35:45 +0000 | [diff] [blame] | 672 | rb->memcpy(&osc, &osc_disk, sizeof(osc)); /* copy to running config */ |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 673 | |
| 674 | #if LCD_DEPTH > 1 |
| 675 | rb->lcd_set_foreground(GRAPH_COLOR); |
| 676 | rb->lcd_set_background(BACKG_COLOR); |
Karl Kurbjun | d6b0c97 | 2006-11-15 06:14:27 +0000 | [diff] [blame] | 677 | rb->lcd_set_backdrop(NULL); |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 678 | rb->lcd_clear_display(); |
| 679 | rb->lcd_update(); |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 680 | #endif |
Peter D'Hoye | cb53e3c | 2007-08-15 12:42:09 +0000 | [diff] [blame] | 681 | |
| 682 | /* Turn off backlight timeout */ |
Peter D'Hoye | 767c0ec | 2007-08-16 23:01:18 +0000 | [diff] [blame] | 683 | backlight_force_on(rb); /* backlight control in lib/helper.c */ |
Peter D'Hoye | cb53e3c | 2007-08-15 12:42:09 +0000 | [diff] [blame] | 684 | |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 685 | rb->lcd_getstringsize("A", NULL, &font_height); |
| 686 | |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 687 | while (!exit) |
| 688 | { |
| 689 | if (!paused) |
| 690 | { |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 691 | int left, right; |
| 692 | |
Jens Arnold | 37f529c | 2006-03-11 08:35:45 +0000 | [diff] [blame] | 693 | rb->sleep(MAX(last_tick + osc.delay - *rb->current_tick - 1, 0)); |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 694 | |
| 695 | #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) |
| 696 | left = rb->mas_codec_readreg(0xC); |
| 697 | right = rb->mas_codec_readreg(0xD); |
| 698 | #elif (CONFIG_CODEC == SWCODEC) |
| 699 | rb->pcm_calculate_peaks(&left, &right); |
| 700 | #endif |
Jens Arnold | 37f529c | 2006-03-11 08:35:45 +0000 | [diff] [blame] | 701 | if (osc.orientation == OSC_HORIZ) |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 702 | anim_horizontal(left, right); |
| 703 | else |
| 704 | anim_vertical(left, right); |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 705 | } |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 706 | |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 707 | tell_speed = false; |
Jens Arnold | 0ee36f8 | 2004-11-12 21:40:57 +0000 | [diff] [blame] | 708 | button = rb->button_get(paused); |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 709 | switch (button) |
| 710 | { |
Kevin Ferrare | 0e027bd | 2006-06-30 16:43:47 +0000 | [diff] [blame] | 711 | #ifdef OSCILLOSCOPE_RC_QUIT |
| 712 | case OSCILLOSCOPE_RC_QUIT: |
| 713 | #endif |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 714 | case OSCILLOSCOPE_QUIT: |
| 715 | exit = true; |
| 716 | break; |
| 717 | |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 718 | case OSCILLOSCOPE_ADVMODE: |
Jens Arnold | 37f529c | 2006-03-11 08:35:45 +0000 | [diff] [blame] | 719 | if (++osc.advance >= MAX_ADV) |
| 720 | osc.advance = 0; |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 721 | break; |
| 722 | |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 723 | case OSCILLOSCOPE_DRAWMODE: |
| 724 | #ifdef OSCILLOSCOPE_DRAWMODE_PRE |
| 725 | if (lastbutton != OSCILLOSCOPE_DRAWMODE_PRE) |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 726 | break; |
| 727 | #endif |
Jens Arnold | 37f529c | 2006-03-11 08:35:45 +0000 | [diff] [blame] | 728 | if (++osc.draw >= MAX_DRAW) |
| 729 | osc.draw = 0; |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 730 | break; |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 731 | |
| 732 | case OSCILLOSCOPE_ORIENTATION: |
Jens Arnold | 61e798f | 2007-04-09 17:03:48 +0000 | [diff] [blame] | 733 | #ifdef OSCILLOSCOPE_ORIENTATION_PRE |
| 734 | if (lastbutton != OSCILLOSCOPE_ORIENTATION_PRE) |
| 735 | break; |
| 736 | #endif |
Jens Arnold | 37f529c | 2006-03-11 08:35:45 +0000 | [diff] [blame] | 737 | if (++osc.orientation >= MAX_OSC) |
| 738 | osc.orientation = 0; |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 739 | last_pos = 0; |
Jens Arnold | f9765d3 | 2006-03-11 01:13:51 +0000 | [diff] [blame] | 740 | last_tick = 0; |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 741 | displaymsg = false; |
| 742 | rb->lcd_clear_display(); |
| 743 | rb->lcd_update(); |
| 744 | break; |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 745 | |
| 746 | case OSCILLOSCOPE_PAUSE: |
| 747 | paused = !paused; |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 748 | last_tick = 0; |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 749 | break; |
| 750 | |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 751 | case OSCILLOSCOPE_SPEED_UP: |
| 752 | case OSCILLOSCOPE_SPEED_UP | BUTTON_REPEAT: |
Jens Arnold | 37f529c | 2006-03-11 08:35:45 +0000 | [diff] [blame] | 753 | if (osc.delay > 1) |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 754 | { |
Jens Arnold | 37f529c | 2006-03-11 08:35:45 +0000 | [diff] [blame] | 755 | osc.delay--; |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 756 | tell_speed = true; |
| 757 | } |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 758 | break; |
| 759 | |
| 760 | case OSCILLOSCOPE_SPEED_DOWN: |
| 761 | case OSCILLOSCOPE_SPEED_DOWN | BUTTON_REPEAT: |
Jens Arnold | 37f529c | 2006-03-11 08:35:45 +0000 | [diff] [blame] | 762 | osc.delay++; |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 763 | tell_speed = true; |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 764 | break; |
| 765 | |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 766 | case OSCILLOSCOPE_VOL_UP: |
| 767 | case OSCILLOSCOPE_VOL_UP | BUTTON_REPEAT: |
| 768 | vol = rb->global_settings->volume; |
Jens Arnold | c80e0c1 | 2005-12-17 21:13:30 +0000 | [diff] [blame] | 769 | if (vol < rb->sound_max(SOUND_VOLUME)) |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 770 | { |
| 771 | vol++; |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 772 | rb->sound_set(SOUND_VOLUME, vol); |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 773 | rb->global_settings->volume = vol; |
| 774 | } |
| 775 | break; |
| 776 | |
| 777 | case OSCILLOSCOPE_VOL_DOWN: |
| 778 | case OSCILLOSCOPE_VOL_DOWN | BUTTON_REPEAT: |
| 779 | vol = rb->global_settings->volume; |
Jens Arnold | c80e0c1 | 2005-12-17 21:13:30 +0000 | [diff] [blame] | 780 | if (vol > rb->sound_min(SOUND_VOLUME)) |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 781 | { |
| 782 | vol--; |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 783 | rb->sound_set(SOUND_VOLUME, vol); |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 784 | rb->global_settings->volume = vol; |
| 785 | } |
| 786 | break; |
| 787 | |
| 788 | default: |
| 789 | if (rb->default_event_handler_ex(button, cleanup, NULL) |
| 790 | == SYS_USB_CONNECTED) |
| 791 | return PLUGIN_USB_CONNECTED; |
| 792 | break; |
| 793 | } |
Jens Arnold | b318b3e | 2006-03-09 07:52:26 +0000 | [diff] [blame] | 794 | if (button != BUTTON_NONE) |
| 795 | lastbutton = button; |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 796 | |
| 797 | if (tell_speed) |
| 798 | { |
Jens Arnold | c91623b | 2006-03-12 13:44:51 +0000 | [diff] [blame] | 799 | rb->snprintf(message, sizeof(message), "%s%d", |
| 800 | (osc.orientation == OSC_VERT) ? "Speed: " : "", |
| 801 | 100 / osc.delay); |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 802 | displaymsg = true; |
| 803 | } |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 804 | } |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 805 | cleanup(NULL); |
Jens Arnold | 37f529c | 2006-03-11 08:35:45 +0000 | [diff] [blame] | 806 | if (rb->memcmp(&osc, &osc_disk, sizeof(osc))) /* save settings if changed */ |
| 807 | { |
| 808 | rb->memcpy(&osc_disk, &osc, sizeof(osc)); |
| 809 | configfile_save(cfg_filename, disk_config, |
| 810 | sizeof(disk_config) / sizeof(disk_config[0]), |
| 811 | CFGFILE_VERSION); |
| 812 | } |
Jens Arnold | db14d8e | 2004-11-07 10:31:39 +0000 | [diff] [blame] | 813 | return PLUGIN_OK; |
| 814 | } |
Jens Arnold | 78e4f4d | 2006-03-10 00:18:58 +0000 | [diff] [blame] | 815 | #endif /* HAVE_LCD_BITMAP */ |