diff options
author | Jens Arnold <amiconn@rockbox.org> | 2006-03-11 08:35:45 +0000 |
---|---|---|
committer | Jens Arnold <amiconn@rockbox.org> | 2006-03-11 08:35:45 +0000 |
commit | 37f529cc3cdcc7990b2a770efec06e45c6054f36 (patch) | |
tree | 4b737790513c5a5869330d5f57666246c9bbf82c /apps | |
parent | cc4dc39dded647a5c3e62eae0c5577b69693b289 (diff) | |
download | rockbox-37f529cc3cdcc7990b2a770efec06e45c6054f36.tar.gz rockbox-37f529cc3cdcc7990b2a770efec06e45c6054f36.zip |
Only save settings if they changed (saves a disk spinup otherwise).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8994 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r-- | apps/plugins/oscilloscope.c | 73 |
1 files changed, 43 insertions, 30 deletions
diff --git a/apps/plugins/oscilloscope.c b/apps/plugins/oscilloscope.c index da0bf0275b..baaf25d2b0 100644 --- a/apps/plugins/oscilloscope.c +++ b/apps/plugins/oscilloscope.c | |||
@@ -130,23 +130,29 @@ enum { OSC_HORIZ, OSC_VERT, MAX_OSC }; | |||
130 | struct plugin_api* rb; /* global api struct pointer */ | 130 | struct plugin_api* rb; /* global api struct pointer */ |
131 | 131 | ||
132 | /* settings */ | 132 | /* settings */ |
133 | int osc_delay = 2; /* in ticks */ | 133 | struct osc_config { |
134 | int osc_draw = DRAW_FILLED; | 134 | int delay; /* in ticks */ |
135 | int osc_advance = ADV_SCROLL; | 135 | int draw; |
136 | int osc_orientation = OSC_HORIZ; | 136 | int advance; |
137 | int orientation; | ||
138 | }; | ||
139 | |||
140 | struct osc_config osc_disk = { 2, DRAW_FILLED, ADV_SCROLL, OSC_HORIZ }; | ||
141 | struct osc_config osc; /* running config */ | ||
137 | 142 | ||
138 | static const char cfg_filename[] = "oscilloscope.cfg"; | 143 | static const char cfg_filename[] = "oscilloscope.cfg"; |
139 | static char *draw_str[3] = { "filled", "line", "pixel" }; | 144 | static char *draw_str[3] = { "filled", "line", "pixel" }; |
140 | static char *advance_str[2] = { "scroll", "wrap" }; | 145 | static char *advance_str[2] = { "scroll", "wrap" }; |
141 | static char *orientation_str[2] = { "horizontal", "vertical" }; | 146 | static char *orientation_str[2] = { "horizontal", "vertical" }; |
142 | 147 | ||
143 | struct configdata config[] = { | 148 | struct configdata disk_config[] = { |
144 | { TYPE_INT, 1, 99, &osc_delay, "delay", NULL, NULL }, | 149 | { TYPE_INT, 1, 99, &osc_disk.delay, "delay", NULL, NULL }, |
145 | { TYPE_ENUM, 0, MAX_DRAW, &osc_draw, "draw", draw_str, NULL }, | 150 | { TYPE_ENUM, 0, MAX_DRAW, &osc_disk.draw, "draw", draw_str, NULL }, |
146 | { TYPE_ENUM, 0, MAX_ADV, &osc_advance, "advance", advance_str, NULL }, | 151 | { TYPE_ENUM, 0, MAX_ADV, &osc_disk.advance, "advance", advance_str, NULL }, |
147 | { TYPE_ENUM, 0, MAX_OSC, &osc_orientation, "orientation", orientation_str, NULL } | 152 | { TYPE_ENUM, 0, MAX_OSC, &osc_disk.orientation, "orientation", orientation_str, NULL } |
148 | }; | 153 | }; |
149 | 154 | ||
155 | |||
150 | long last_tick = 0; /* time of last drawing */ | 156 | long last_tick = 0; /* time of last drawing */ |
151 | int last_pos = 0; /* last x or y drawing position. Reset for aspect switch. */ | 157 | int last_pos = 0; /* last x or y drawing position. Reset for aspect switch. */ |
152 | int last_left; /* last channel values */ | 158 | int last_left; /* last channel values */ |
@@ -163,7 +169,7 @@ void anim_horizontal(int cur_left, int cur_right) | |||
163 | int cur_x, x; | 169 | int cur_x, x; |
164 | int left, right, dl, dr; | 170 | int left, right, dl, dr; |
165 | long cur_tick = *rb->current_tick; | 171 | long cur_tick = *rb->current_tick; |
166 | long d = (cur_tick - last_tick) / osc_delay; | 172 | long d = (cur_tick - last_tick) / osc.delay; |
167 | bool full_update = false; | 173 | bool full_update = false; |
168 | 174 | ||
169 | if (d == 0) /* too early, bail out */ | 175 | if (d == 0) /* too early, bail out */ |
@@ -181,7 +187,7 @@ void anim_horizontal(int cur_left, int cur_right) | |||
181 | 187 | ||
182 | if (cur_x >= LCD_WIDTH) | 188 | if (cur_x >= LCD_WIDTH) |
183 | { | 189 | { |
184 | if (osc_advance == ADV_SCROLL) | 190 | if (osc.advance == ADV_SCROLL) |
185 | { | 191 | { |
186 | int shift = cur_x - (LCD_WIDTH-1); | 192 | int shift = cur_x - (LCD_WIDTH-1); |
187 | xlcd_scroll_left(shift); | 193 | xlcd_scroll_left(shift); |
@@ -207,7 +213,7 @@ void anim_horizontal(int cur_left, int cur_right) | |||
207 | } | 213 | } |
208 | rb->lcd_set_drawmode(DRMODE_SOLID); | 214 | rb->lcd_set_drawmode(DRMODE_SOLID); |
209 | 215 | ||
210 | switch (osc_draw) | 216 | switch (osc.draw) |
211 | { | 217 | { |
212 | case DRAW_FILLED: | 218 | case DRAW_FILLED: |
213 | left = last_left; | 219 | left = last_left; |
@@ -328,7 +334,7 @@ void anim_vertical(int cur_left, int cur_right) | |||
328 | int cur_y, y; | 334 | int cur_y, y; |
329 | int left, right, dl, dr; | 335 | int left, right, dl, dr; |
330 | long cur_tick = *rb->current_tick; | 336 | long cur_tick = *rb->current_tick; |
331 | long d = (cur_tick - last_tick) / osc_delay; | 337 | long d = (cur_tick - last_tick) / osc.delay; |
332 | bool full_update = false; | 338 | bool full_update = false; |
333 | 339 | ||
334 | if (d == 0) /* too early, bail out */ | 340 | if (d == 0) /* too early, bail out */ |
@@ -346,7 +352,7 @@ void anim_vertical(int cur_left, int cur_right) | |||
346 | 352 | ||
347 | if (cur_y >= LCD_HEIGHT) | 353 | if (cur_y >= LCD_HEIGHT) |
348 | { | 354 | { |
349 | if (osc_advance == ADV_SCROLL) | 355 | if (osc.advance == ADV_SCROLL) |
350 | { | 356 | { |
351 | int shift = cur_y - (LCD_HEIGHT-1); | 357 | int shift = cur_y - (LCD_HEIGHT-1); |
352 | xlcd_scroll_up(shift); | 358 | xlcd_scroll_up(shift); |
@@ -372,7 +378,7 @@ void anim_vertical(int cur_left, int cur_right) | |||
372 | } | 378 | } |
373 | rb->lcd_set_drawmode(DRMODE_SOLID); | 379 | rb->lcd_set_drawmode(DRMODE_SOLID); |
374 | 380 | ||
375 | switch (osc_draw) | 381 | switch (osc.draw) |
376 | { | 382 | { |
377 | case DRAW_FILLED: | 383 | case DRAW_FILLED: |
378 | left = last_left; | 384 | left = last_left; |
@@ -524,8 +530,10 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
524 | xlcd_init(rb); | 530 | xlcd_init(rb); |
525 | configfile_init(rb); | 531 | configfile_init(rb); |
526 | 532 | ||
527 | configfile_load(cfg_filename, config, sizeof(config) / sizeof(config[0]), | 533 | configfile_load(cfg_filename, disk_config, |
534 | sizeof(disk_config) / sizeof(disk_config[0]), | ||
528 | CFGFILE_MINVERSION); | 535 | CFGFILE_MINVERSION); |
536 | rb->memcpy(&osc, &osc_disk, sizeof(osc)); /* copy to running config */ | ||
529 | 537 | ||
530 | #if LCD_DEPTH > 1 | 538 | #if LCD_DEPTH > 1 |
531 | rb->lcd_set_foreground(GRAPH_COLOR); | 539 | rb->lcd_set_foreground(GRAPH_COLOR); |
@@ -544,7 +552,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
544 | { | 552 | { |
545 | int left, right; | 553 | int left, right; |
546 | 554 | ||
547 | rb->sleep(MAX(last_tick + osc_delay - *rb->current_tick - 1, 0)); | 555 | rb->sleep(MAX(last_tick + osc.delay - *rb->current_tick - 1, 0)); |
548 | 556 | ||
549 | #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) | 557 | #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) |
550 | left = rb->mas_codec_readreg(0xC); | 558 | left = rb->mas_codec_readreg(0xC); |
@@ -552,7 +560,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
552 | #elif (CONFIG_CODEC == SWCODEC) | 560 | #elif (CONFIG_CODEC == SWCODEC) |
553 | rb->pcm_calculate_peaks(&left, &right); | 561 | rb->pcm_calculate_peaks(&left, &right); |
554 | #endif | 562 | #endif |
555 | if (osc_orientation == OSC_HORIZ) | 563 | if (osc.orientation == OSC_HORIZ) |
556 | anim_horizontal(left, right); | 564 | anim_horizontal(left, right); |
557 | else | 565 | else |
558 | anim_vertical(left, right); | 566 | anim_vertical(left, right); |
@@ -567,8 +575,8 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
567 | break; | 575 | break; |
568 | 576 | ||
569 | case OSCILLOSCOPE_ADVMODE: | 577 | case OSCILLOSCOPE_ADVMODE: |
570 | if (++osc_advance >= MAX_ADV) | 578 | if (++osc.advance >= MAX_ADV) |
571 | osc_advance = 0; | 579 | osc.advance = 0; |
572 | break; | 580 | break; |
573 | 581 | ||
574 | case OSCILLOSCOPE_DRAWMODE: | 582 | case OSCILLOSCOPE_DRAWMODE: |
@@ -576,13 +584,13 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
576 | if (lastbutton != OSCILLOSCOPE_DRAWMODE_PRE) | 584 | if (lastbutton != OSCILLOSCOPE_DRAWMODE_PRE) |
577 | break; | 585 | break; |
578 | #endif | 586 | #endif |
579 | if (++osc_draw >= MAX_DRAW) | 587 | if (++osc.draw >= MAX_DRAW) |
580 | osc_draw = 0; | 588 | osc.draw = 0; |
581 | break; | 589 | break; |
582 | 590 | ||
583 | case OSCILLOSCOPE_ORIENTATION: | 591 | case OSCILLOSCOPE_ORIENTATION: |
584 | if (++osc_orientation >= MAX_OSC) | 592 | if (++osc.orientation >= MAX_OSC) |
585 | osc_orientation = 0; | 593 | osc.orientation = 0; |
586 | last_pos = 0; | 594 | last_pos = 0; |
587 | last_tick = 0; | 595 | last_tick = 0; |
588 | displaymsg = false; | 596 | displaymsg = false; |
@@ -597,16 +605,16 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
597 | 605 | ||
598 | case OSCILLOSCOPE_SPEED_UP: | 606 | case OSCILLOSCOPE_SPEED_UP: |
599 | case OSCILLOSCOPE_SPEED_UP | BUTTON_REPEAT: | 607 | case OSCILLOSCOPE_SPEED_UP | BUTTON_REPEAT: |
600 | if (osc_delay > 1) | 608 | if (osc.delay > 1) |
601 | { | 609 | { |
602 | osc_delay--; | 610 | osc.delay--; |
603 | tell_speed = true; | 611 | tell_speed = true; |
604 | } | 612 | } |
605 | break; | 613 | break; |
606 | 614 | ||
607 | case OSCILLOSCOPE_SPEED_DOWN: | 615 | case OSCILLOSCOPE_SPEED_DOWN: |
608 | case OSCILLOSCOPE_SPEED_DOWN | BUTTON_REPEAT: | 616 | case OSCILLOSCOPE_SPEED_DOWN | BUTTON_REPEAT: |
609 | osc_delay++; | 617 | osc.delay++; |
610 | tell_speed = true; | 618 | tell_speed = true; |
611 | break; | 619 | break; |
612 | 620 | ||
@@ -643,13 +651,18 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
643 | 651 | ||
644 | if (tell_speed) | 652 | if (tell_speed) |
645 | { | 653 | { |
646 | rb->snprintf(message, sizeof(message), "Speed: %d", 100 / osc_delay); | 654 | rb->snprintf(message, sizeof(message), "Speed: %d", 100 / osc.delay); |
647 | displaymsg = true; | 655 | displaymsg = true; |
648 | } | 656 | } |
649 | } | 657 | } |
650 | cleanup(NULL); | 658 | cleanup(NULL); |
651 | configfile_save(cfg_filename, config, sizeof(config) / sizeof(config[0]), | 659 | if (rb->memcmp(&osc, &osc_disk, sizeof(osc))) /* save settings if changed */ |
652 | CFGFILE_VERSION); | 660 | { |
661 | rb->memcpy(&osc_disk, &osc, sizeof(osc)); | ||
662 | configfile_save(cfg_filename, disk_config, | ||
663 | sizeof(disk_config) / sizeof(disk_config[0]), | ||
664 | CFGFILE_VERSION); | ||
665 | } | ||
653 | return PLUGIN_OK; | 666 | return PLUGIN_OK; |
654 | } | 667 | } |
655 | #endif /* HAVE_LCD_BITMAP */ | 668 | #endif /* HAVE_LCD_BITMAP */ |