From 93b2f9fd447b73fff736d71826880ef9ac64bd94 Mon Sep 17 00:00:00 2001 From: Kevin Ferrare Date: Sat, 4 Aug 2007 03:01:46 +0000 Subject: Rewrote the clock plugin in a cleaner and more modular way so that it can scale on remote screens. Use left-right keys to change the type of clock displayed (analogic, digital, binary) and up/downto change the look of the clock git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14174 a1c6a512-1295-4272-9138-f99709370657 --- apps/plugins/SOURCES | 1 - apps/plugins/SUBDIRS | 5 + apps/plugins/bitmaps/native/SOURCES | 8 + .../bitmaps/native/clock_binary.112x64x1.bmp | Bin 0 -> 1974 bytes .../bitmaps/native/clock_binary.128x128x16.bmp | Bin 0 -> 3414 bytes .../bitmaps/native/clock_binary.138x110x2.bmp | Bin 0 -> 2614 bytes .../bitmaps/native/clock_binary.160x128x16.bmp | Bin 0 -> 5374 bytes .../bitmaps/native/clock_binary.160x128x2.bmp | Bin 0 -> 3038 bytes .../bitmaps/native/clock_binary.220x176x16.bmp | Bin 0 -> 10638 bytes .../bitmaps/native/clock_binary.320x240x16.bmp | Bin 0 -> 21334 bytes .../bitmaps/native/clock_digits.112x64x1.bmp | Bin 1262 -> 1102 bytes .../bitmaps/native/clock_digits.128x128x16.bmp | Bin 25256 -> 21894 bytes .../bitmaps/native/clock_digits.138x110x2.bmp | Bin 12600 -> 11062 bytes .../bitmaps/native/clock_digits.160x128x16.bmp | Bin 39956 -> 34634 bytes .../bitmaps/native/clock_digits.160x128x2.bmp | Bin 15776 -> 13818 bytes .../bitmaps/native/clock_digits.220x176x16.bmp | Bin 79436 -> 68850 bytes .../bitmaps/native/clock_digits.320x240x16.bmp | Bin 159656 -> 138374 bytes apps/plugins/bitmaps/remote_native/SOURCES | 11 + .../remote_native/clock_binary_remote.112x64x1.bmp | Bin 0 -> 1974 bytes .../remote_native/clock_digits_remote.112x64x1.bmp | Bin 0 -> 1102 bytes .../remote_native/clock_logo_remote.112x64x1.bmp | Bin 0 -> 864 bytes .../clock_messages_remote.112x64x1.bmp | Bin 0 -> 1408 bytes .../clock_segments_remote.112x64x1.bmp | Bin 0 -> 1102 bytes .../clock_smalldigits_remote.112x64x1.bmp | Bin 0 -> 582 bytes .../clock_smallsegments_remote.112x64x1.bmp | Bin 0 -> 686 bytes apps/plugins/clock.c | 1673 -------------------- apps/plugins/clock/Makefile | 112 ++ apps/plugins/clock/SOURCES | 10 + apps/plugins/clock/clock.c | 199 +++ apps/plugins/clock/clock.h | 32 + apps/plugins/clock/clock_bitmap_strings.c | 46 + apps/plugins/clock/clock_bitmap_strings.h | 31 + apps/plugins/clock/clock_bitmaps.c | 105 ++ apps/plugins/clock/clock_bitmaps.h | 33 + apps/plugins/clock/clock_counter.c | 42 + apps/plugins/clock/clock_counter.h | 19 + apps/plugins/clock/clock_draw.c | 103 ++ apps/plugins/clock/clock_draw.h | 32 + apps/plugins/clock/clock_draw_analog.c | 217 +++ apps/plugins/clock/clock_draw_analog.h | 32 + apps/plugins/clock/clock_draw_binary.c | 51 + apps/plugins/clock/clock_draw_binary.h | 27 + apps/plugins/clock/clock_draw_digital.c | 87 + apps/plugins/clock/clock_draw_digital.h | 31 + apps/plugins/clock/clock_menu.c | 246 +++ apps/plugins/clock/clock_menu.h | 7 + apps/plugins/clock/clock_settings.c | 200 +++ apps/plugins/clock/clock_settings.h | 91 ++ apps/plugins/lib/SOURCES | 1 + apps/plugins/lib/picture.c | 70 + apps/plugins/lib/picture.h | 40 + apps/plugins/lib/xlcd.h | 3 +- apps/plugins/lib/xlcd_draw.c | 135 +- 53 files changed, 1958 insertions(+), 1742 deletions(-) create mode 100644 apps/plugins/bitmaps/native/clock_binary.112x64x1.bmp create mode 100644 apps/plugins/bitmaps/native/clock_binary.128x128x16.bmp create mode 100644 apps/plugins/bitmaps/native/clock_binary.138x110x2.bmp create mode 100644 apps/plugins/bitmaps/native/clock_binary.160x128x16.bmp create mode 100644 apps/plugins/bitmaps/native/clock_binary.160x128x2.bmp create mode 100644 apps/plugins/bitmaps/native/clock_binary.220x176x16.bmp create mode 100644 apps/plugins/bitmaps/native/clock_binary.320x240x16.bmp create mode 100644 apps/plugins/bitmaps/remote_native/clock_binary_remote.112x64x1.bmp create mode 100644 apps/plugins/bitmaps/remote_native/clock_digits_remote.112x64x1.bmp create mode 100644 apps/plugins/bitmaps/remote_native/clock_logo_remote.112x64x1.bmp create mode 100644 apps/plugins/bitmaps/remote_native/clock_messages_remote.112x64x1.bmp create mode 100644 apps/plugins/bitmaps/remote_native/clock_segments_remote.112x64x1.bmp create mode 100644 apps/plugins/bitmaps/remote_native/clock_smalldigits_remote.112x64x1.bmp create mode 100644 apps/plugins/bitmaps/remote_native/clock_smallsegments_remote.112x64x1.bmp delete mode 100644 apps/plugins/clock.c create mode 100644 apps/plugins/clock/Makefile create mode 100644 apps/plugins/clock/SOURCES create mode 100644 apps/plugins/clock/clock.c create mode 100644 apps/plugins/clock/clock.h create mode 100644 apps/plugins/clock/clock_bitmap_strings.c create mode 100644 apps/plugins/clock/clock_bitmap_strings.h create mode 100644 apps/plugins/clock/clock_bitmaps.c create mode 100644 apps/plugins/clock/clock_bitmaps.h create mode 100644 apps/plugins/clock/clock_counter.c create mode 100644 apps/plugins/clock/clock_counter.h create mode 100644 apps/plugins/clock/clock_draw.c create mode 100644 apps/plugins/clock/clock_draw.h create mode 100644 apps/plugins/clock/clock_draw_analog.c create mode 100644 apps/plugins/clock/clock_draw_analog.h create mode 100644 apps/plugins/clock/clock_draw_binary.c create mode 100644 apps/plugins/clock/clock_draw_binary.h create mode 100644 apps/plugins/clock/clock_draw_digital.c create mode 100644 apps/plugins/clock/clock_draw_digital.h create mode 100644 apps/plugins/clock/clock_menu.c create mode 100644 apps/plugins/clock/clock_menu.h create mode 100644 apps/plugins/clock/clock_settings.c create mode 100644 apps/plugins/clock/clock_settings.h create mode 100644 apps/plugins/lib/picture.c create mode 100644 apps/plugins/lib/picture.h (limited to 'apps/plugins') diff --git a/apps/plugins/SOURCES b/apps/plugins/SOURCES index 96a7ebec2d..31d94d5811 100644 --- a/apps/plugins/SOURCES +++ b/apps/plugins/SOURCES @@ -82,7 +82,6 @@ vu_meter.c wormlet.c #if CONFIG_RTC -clock.c #if CONFIG_KEYPAD == RECORDER_PAD /* Recorder models only for now */ calendar.c #endif diff --git a/apps/plugins/SUBDIRS b/apps/plugins/SUBDIRS index 6665f41e4e..3f0fc9051b 100644 --- a/apps/plugins/SUBDIRS +++ b/apps/plugins/SUBDIRS @@ -3,6 +3,11 @@ /* For all targets */ /* For various targets... */ + +#if CONFIG_RTC +clock +#endif + #if (CONFIG_KEYPAD == RECORDER_PAD) || defined(HAVE_LCD_COLOR) \ || defined(IRIVER_H100_SERIES) || defined(IAUDIO_M5) rockboy diff --git a/apps/plugins/bitmaps/native/SOURCES b/apps/plugins/bitmaps/native/SOURCES index 05029c430c..93939c95f7 100644 --- a/apps/plugins/bitmaps/native/SOURCES +++ b/apps/plugins/bitmaps/native/SOURCES @@ -112,6 +112,7 @@ chessbox_pieces.64x64x1.bmp /* Clock */ #if (LCD_WIDTH >= 320) && (LCD_HEIGHT >= 240) && (LCD_DEPTH >= 16) +clock_binary.320x240x16.bmp clock_digits.320x240x16.bmp clock_smalldigits.320x240x16.bmp clock_segments.320x240x16.bmp @@ -119,6 +120,7 @@ clock_smallsegments.320x240x16.bmp clock_logo.320x240x16.bmp clock_messages.320x240x16.bmp #elif (LCD_WIDTH >= 220) && (LCD_HEIGHT >= 176) && (LCD_DEPTH >= 16) +clock_binary.220x176x16.bmp clock_digits.220x176x16.bmp clock_smalldigits.220x176x16.bmp clock_segments.220x176x16.bmp @@ -126,6 +128,7 @@ clock_smallsegments.220x176x16.bmp clock_logo.220x176x16.bmp clock_messages.220x176x16.bmp #elif (LCD_WIDTH >= 176) && (LCD_HEIGHT >= 132) && (LCD_DEPTH >= 16) +clock_binary.160x128x16.bmp clock_digits.160x128x16.bmp clock_smalldigits.160x128x16.bmp clock_segments.160x128x16.bmp @@ -133,6 +136,7 @@ clock_smallsegments.160x128x16.bmp clock_logo.176x132x16.bmp clock_messages.176x132x16.bmp #elif (LCD_WIDTH >= 160) && (LCD_HEIGHT >= 128) && (LCD_DEPTH >= 16) +clock_binary.160x128x16.bmp clock_digits.160x128x16.bmp clock_smalldigits.160x128x16.bmp clock_segments.160x128x16.bmp @@ -140,6 +144,7 @@ clock_smallsegments.160x128x16.bmp clock_logo.160x128x16.bmp clock_messages.160x128x16.bmp #elif (LCD_WIDTH >= 128) && (LCD_HEIGHT >= 128) && (LCD_DEPTH >= 16) +clock_binary.128x128x16.bmp clock_digits.128x128x16.bmp clock_smalldigits.128x128x16.bmp clock_segments.128x128x16.bmp @@ -147,6 +152,7 @@ clock_smallsegments.128x128x16.bmp clock_logo.128x128x16.bmp clock_messages.128x128x16.bmp #elif (LCD_WIDTH >= 160) && (LCD_HEIGHT >= 128) && (LCD_DEPTH >= 2) +clock_binary.160x128x2.bmp clock_digits.160x128x2.bmp clock_smalldigits.160x128x2.bmp clock_segments.160x128x2.bmp @@ -154,6 +160,7 @@ clock_smallsegments.160x128x2.bmp clock_logo.160x128x2.bmp clock_messages.160x128x2.bmp #elif (LCD_WIDTH >= 138) && (LCD_HEIGHT >= 110) && (LCD_DEPTH >= 2) +clock_binary.138x110x2.bmp clock_digits.138x110x2.bmp clock_smalldigits.160x128x2.bmp clock_segments.138x110x2.bmp @@ -161,6 +168,7 @@ clock_smallsegments.160x128x2.bmp clock_logo.138x110x2.bmp clock_messages.138x110x2.bmp #elif (LCD_WIDTH >= 112) && (LCD_HEIGHT >= 64) && (LCD_DEPTH >= 1) +clock_binary.112x64x1.bmp clock_digits.112x64x1.bmp clock_smalldigits.112x64x1.bmp clock_segments.112x64x1.bmp diff --git a/apps/plugins/bitmaps/native/clock_binary.112x64x1.bmp b/apps/plugins/bitmaps/native/clock_binary.112x64x1.bmp new file mode 100644 index 0000000000..a42401c293 Binary files /dev/null and b/apps/plugins/bitmaps/native/clock_binary.112x64x1.bmp differ diff --git a/apps/plugins/bitmaps/native/clock_binary.128x128x16.bmp b/apps/plugins/bitmaps/native/clock_binary.128x128x16.bmp new file mode 100644 index 0000000000..9f98dc2753 Binary files /dev/null and b/apps/plugins/bitmaps/native/clock_binary.128x128x16.bmp differ diff --git a/apps/plugins/bitmaps/native/clock_binary.138x110x2.bmp b/apps/plugins/bitmaps/native/clock_binary.138x110x2.bmp new file mode 100644 index 0000000000..0596c71e3c Binary files /dev/null and b/apps/plugins/bitmaps/native/clock_binary.138x110x2.bmp differ diff --git a/apps/plugins/bitmaps/native/clock_binary.160x128x16.bmp b/apps/plugins/bitmaps/native/clock_binary.160x128x16.bmp new file mode 100644 index 0000000000..d1982ba94a Binary files /dev/null and b/apps/plugins/bitmaps/native/clock_binary.160x128x16.bmp differ diff --git a/apps/plugins/bitmaps/native/clock_binary.160x128x2.bmp b/apps/plugins/bitmaps/native/clock_binary.160x128x2.bmp new file mode 100644 index 0000000000..9808694a6c Binary files /dev/null and b/apps/plugins/bitmaps/native/clock_binary.160x128x2.bmp differ diff --git a/apps/plugins/bitmaps/native/clock_binary.220x176x16.bmp b/apps/plugins/bitmaps/native/clock_binary.220x176x16.bmp new file mode 100644 index 0000000000..3cc2bd15cb Binary files /dev/null and b/apps/plugins/bitmaps/native/clock_binary.220x176x16.bmp differ diff --git a/apps/plugins/bitmaps/native/clock_binary.320x240x16.bmp b/apps/plugins/bitmaps/native/clock_binary.320x240x16.bmp new file mode 100644 index 0000000000..158ac90ae9 Binary files /dev/null and b/apps/plugins/bitmaps/native/clock_binary.320x240x16.bmp differ diff --git a/apps/plugins/bitmaps/native/clock_digits.112x64x1.bmp b/apps/plugins/bitmaps/native/clock_digits.112x64x1.bmp index c8738029cb..cd4a3ba152 100644 Binary files a/apps/plugins/bitmaps/native/clock_digits.112x64x1.bmp and b/apps/plugins/bitmaps/native/clock_digits.112x64x1.bmp differ diff --git a/apps/plugins/bitmaps/native/clock_digits.128x128x16.bmp b/apps/plugins/bitmaps/native/clock_digits.128x128x16.bmp index 87694982c9..c9edb25dd0 100644 Binary files a/apps/plugins/bitmaps/native/clock_digits.128x128x16.bmp and b/apps/plugins/bitmaps/native/clock_digits.128x128x16.bmp differ diff --git a/apps/plugins/bitmaps/native/clock_digits.138x110x2.bmp b/apps/plugins/bitmaps/native/clock_digits.138x110x2.bmp index d3a3ea15a4..69a2fef25b 100644 Binary files a/apps/plugins/bitmaps/native/clock_digits.138x110x2.bmp and b/apps/plugins/bitmaps/native/clock_digits.138x110x2.bmp differ diff --git a/apps/plugins/bitmaps/native/clock_digits.160x128x16.bmp b/apps/plugins/bitmaps/native/clock_digits.160x128x16.bmp index 6b2b41c496..7fccf93928 100644 Binary files a/apps/plugins/bitmaps/native/clock_digits.160x128x16.bmp and b/apps/plugins/bitmaps/native/clock_digits.160x128x16.bmp differ diff --git a/apps/plugins/bitmaps/native/clock_digits.160x128x2.bmp b/apps/plugins/bitmaps/native/clock_digits.160x128x2.bmp index 6a82bb05d0..75abec3fa4 100644 Binary files a/apps/plugins/bitmaps/native/clock_digits.160x128x2.bmp and b/apps/plugins/bitmaps/native/clock_digits.160x128x2.bmp differ diff --git a/apps/plugins/bitmaps/native/clock_digits.220x176x16.bmp b/apps/plugins/bitmaps/native/clock_digits.220x176x16.bmp index 41fef2bc1e..c18e7aeb35 100644 Binary files a/apps/plugins/bitmaps/native/clock_digits.220x176x16.bmp and b/apps/plugins/bitmaps/native/clock_digits.220x176x16.bmp differ diff --git a/apps/plugins/bitmaps/native/clock_digits.320x240x16.bmp b/apps/plugins/bitmaps/native/clock_digits.320x240x16.bmp index 0da719cd54..8a6ea68d43 100644 Binary files a/apps/plugins/bitmaps/native/clock_digits.320x240x16.bmp and b/apps/plugins/bitmaps/native/clock_digits.320x240x16.bmp differ diff --git a/apps/plugins/bitmaps/remote_native/SOURCES b/apps/plugins/bitmaps/remote_native/SOURCES index d59621d686..a884ebb24a 100644 --- a/apps/plugins/bitmaps/remote_native/SOURCES +++ b/apps/plugins/bitmaps/remote_native/SOURCES @@ -4,3 +4,14 @@ osx.dummy.bmp /* Jackpot */ jackpot_slots_remote.15x210x1.bmp + +clock_logo_remote.112x64x1.bmp +clock_messages_remote.112x64x1.bmp + +clock_binary_remote.112x64x1.bmp + +clock_digits_remote.112x64x1.bmp +clock_smalldigits_remote.112x64x1.bmp + +clock_segments_remote.112x64x1.bmp +clock_smallsegments_remote.112x64x1.bmp diff --git a/apps/plugins/bitmaps/remote_native/clock_binary_remote.112x64x1.bmp b/apps/plugins/bitmaps/remote_native/clock_binary_remote.112x64x1.bmp new file mode 100644 index 0000000000..a42401c293 Binary files /dev/null and b/apps/plugins/bitmaps/remote_native/clock_binary_remote.112x64x1.bmp differ diff --git a/apps/plugins/bitmaps/remote_native/clock_digits_remote.112x64x1.bmp b/apps/plugins/bitmaps/remote_native/clock_digits_remote.112x64x1.bmp new file mode 100644 index 0000000000..cd4a3ba152 Binary files /dev/null and b/apps/plugins/bitmaps/remote_native/clock_digits_remote.112x64x1.bmp differ diff --git a/apps/plugins/bitmaps/remote_native/clock_logo_remote.112x64x1.bmp b/apps/plugins/bitmaps/remote_native/clock_logo_remote.112x64x1.bmp new file mode 100644 index 0000000000..47b6cddf73 Binary files /dev/null and b/apps/plugins/bitmaps/remote_native/clock_logo_remote.112x64x1.bmp differ diff --git a/apps/plugins/bitmaps/remote_native/clock_messages_remote.112x64x1.bmp b/apps/plugins/bitmaps/remote_native/clock_messages_remote.112x64x1.bmp new file mode 100644 index 0000000000..8cdc43155f Binary files /dev/null and b/apps/plugins/bitmaps/remote_native/clock_messages_remote.112x64x1.bmp differ diff --git a/apps/plugins/bitmaps/remote_native/clock_segments_remote.112x64x1.bmp b/apps/plugins/bitmaps/remote_native/clock_segments_remote.112x64x1.bmp new file mode 100644 index 0000000000..15caccec22 Binary files /dev/null and b/apps/plugins/bitmaps/remote_native/clock_segments_remote.112x64x1.bmp differ diff --git a/apps/plugins/bitmaps/remote_native/clock_smalldigits_remote.112x64x1.bmp b/apps/plugins/bitmaps/remote_native/clock_smalldigits_remote.112x64x1.bmp new file mode 100644 index 0000000000..54a0802d20 Binary files /dev/null and b/apps/plugins/bitmaps/remote_native/clock_smalldigits_remote.112x64x1.bmp differ diff --git a/apps/plugins/bitmaps/remote_native/clock_smallsegments_remote.112x64x1.bmp b/apps/plugins/bitmaps/remote_native/clock_smallsegments_remote.112x64x1.bmp new file mode 100644 index 0000000000..767e25556e Binary files /dev/null and b/apps/plugins/bitmaps/remote_native/clock_smallsegments_remote.112x64x1.bmp differ diff --git a/apps/plugins/clock.c b/apps/plugins/clock.c deleted file mode 100644 index 71415c03d4..0000000000 --- a/apps/plugins/clock.c +++ /dev/null @@ -1,1673 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2003 Zakk Roberts - * - * All files in this archive are subject to the GNU General Public License. - * See the file COPYING in the source tree root for full license agreement. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ - -/***************************** - * RELEASE NOTES - -***** VERSION 4.00 ** -New almost entirely bitmap based display. Scales to all resolutions. Combined -Digital and LCD modes into one. Use Rockbox menu code for the menu. Removed -count-down option. A couple new options. Source code reworked, improved, cleaned -up. - -***** VERSION 3.10 ** -Drawing now scales for the display - still needs updated bitmaps for the binary -and plain mode. The Time's Up logo could also be updated. - -***** VERSION 3.00 ** -New, simpler UI - every screen can be accessed from the new Main Menu. -Huge code cleanup - many major functions rewritten and optimized, -targeting scalability. Number of variables reduced majorly. -New clock mode: Plain (simple, large text). ON now controls counter -(press toggle/hold reset). Fancier credits roll. New logo. iRiver and iPod ports -are working but not yet scaled to fit their LCDs. - -***** VERSION 2.60 ** -Fixed general settings typo, split up settings function, added cursor animations, -and updated cursor look (rounded edges). - -***** VERSION 2.51 ** -"Show Counter" option is now saved to disk - -***** VERSION 2.50 ** -New general settings mode added, reworked options screen, cleaned up a few -things and removed redundant code, faster load_settings(), fixed a -help-screen bug (thanks to zeekoe) - -***** VERSION 2.40 ** -Cleaned and optimized code, removed unused code/bitmaps, credits screen updated, -centered text all over, general settings added at ON+F3, -new arrow bitmap for general settings and mode selector, -bugfix: 12:00AM is no longer 00:00AM - -***** VERSION 2.31 ** -Fixed credits roll - now displays all names. Features -improved animations. Also revised release notes. - -***** VERSION 2.30 ** -Tab indentation removed, and Counter screen added -at ON+F2, with countdown options - -***** VERSION 2.22 ** -Fixed two bugs: -Digital settings are now independent of LCD settings -12/24h "Analog" settings are now displayed correctly. - -***** VERSION 2.21 ** --Changed the behaviour of F2 - -***** VERSION 2.20 ** -Few small bugs taken care of. New features: -New binary mode, new mode selector, "counter", and redesigned help screen. - -***** VERSION 2.10 ** -New bug fixes, and some new features: -an LCD imitation mode, and American and European date modes. - -***** VERSION 2.00 ** -Major update, lots of bugfixes and new features. -Fullscreen mode introduced, modes have independent settings, credit roll -added, options screen reworked, logo selector, and -much- cleaner code. - -***** VERSION 1.0 ** -Original release, featuring analog/digital modes and a few options. -*****************************/ -#include "plugin.h" -#include "time.h" -#include "checkbox.h" -#include "xlcd.h" -#include "oldmenuapi.h" -#include "fixedpoint.h" -#include "pluginlib_actions.h" - -PLUGIN_HEADER - -/* External bitmap references */ -#include "clock_digits.h" -#include "clock_smalldigits.h" -#include "clock_smallsegments.h" -#include "clock_messages.h" -#include "clock_logo.h" -#include "clock_segments.h" - -/* Bitmap positions/deltas, per LCD size */ -#if (LCD_WIDTH >= 112) && (LCD_HEIGHT >= 64) && (LCD_DEPTH >= 1) /* Archos */ -#define LCD_OFFSET 1 -#define HAND_W 2 -#else -#define LCD_OFFSET 1.5 -#define HAND_W 3 -#endif - -#define DIGIT_WIDTH BMPWIDTH_clock_digits -#define DIGIT_HEIGHT (BMPHEIGHT_clock_digits/15) -#define SMALLDIGIT_WIDTH BMPWIDTH_clock_smalldigits -#define SMALLDIGIT_HEIGHT (BMPHEIGHT_clock_smalldigits/13) -#define SMALLSEG_WIDTH BMPWIDTH_clock_smallsegments -#define SMALLSEG_HEIGHT (BMPHEIGHT_clock_smallsegments/13) -#define MESSAGE_WIDTH BMPWIDTH_clock_messages -#define MESSAGE_HEIGHT (BMPHEIGHT_clock_messages/6) -#define LOGO_WIDTH BMPWIDTH_clock_logo -#define LOGO_HEIGHT BMPHEIGHT_clock_logo - -/* Parts of larger bitmaps */ -#define COLON 10 -#define DOT_FILLED 11 -#define DOT_EMPTY 12 -#define ICON_PM 13 -#define ICON_AM 14 -#define SEGMENT_AM 11 -#define SEGMENT_PM 12 -#define SLASH 11 -#define PERIOD 12 - -/* Message names/values */ -#define MESSAGE_LOADING 0 -#define MESSAGE_LOADED 1 -#define MESSAGE_ERRLOAD 2 -#define MESSAGE_SAVING 3 -#define MESSAGE_SAVED 4 -#define MESSAGE_ERRSAVE 5 - -/* Some macros to simplify drawing et al */ -#define draw_digit( num, x, y )\ - rb->lcd_bitmap_part( clock_digits, 0, num * DIGIT_HEIGHT, \ - DIGIT_WIDTH, x, y, DIGIT_WIDTH, DIGIT_HEIGHT ) -#define draw_smalldigit( num, x, y )\ - rb->lcd_bitmap_part( clock_smalldigits, 0, num * SMALLDIGIT_HEIGHT, \ - SMALLDIGIT_WIDTH, x, y, SMALLDIGIT_WIDTH, SMALLDIGIT_HEIGHT ) -#define draw_segment( num, x, y )\ - rb->lcd_bitmap_part( clock_segments, 0, num * DIGIT_HEIGHT, \ - DIGIT_WIDTH, x, y, DIGIT_WIDTH, DIGIT_HEIGHT ) -#define draw_smallsegment( num, x, y )\ - rb->lcd_bitmap_part( clock_smallsegments, 0, num * SMALLSEG_HEIGHT, \ - SMALLSEG_WIDTH, x, y, SMALLSEG_WIDTH, SMALLSEG_HEIGHT ) -#define draw_message( msg, ypos )\ - rb->lcd_bitmap_part( clock_messages, 0, msg*MESSAGE_HEIGHT, MESSAGE_WIDTH, \ - 0, LCD_HEIGHT-(MESSAGE_HEIGHT*ypos), MESSAGE_WIDTH, MESSAGE_HEIGHT ) -#define DIGIT_XOFS(x) (LCD_WIDTH-x*DIGIT_WIDTH)/2 -#define DIGIT_YOFS(x) (LCD_HEIGHT-x*DIGIT_HEIGHT)/2 -#define SMALLDIGIT_XOFS(x) (LCD_WIDTH-x*SMALLDIGIT_WIDTH)/2 -#define SMALLDIGIT_YOFS(x) (LCD_HEIGHT-x*SMALLDIGIT_HEIGHT)/2 -#define SMALLSEG_XOFS(x) (LCD_WIDTH-x*SMALLSEG_WIDTH)/2 -#define SMALLSEG_YOFS(x) (LCD_HEIGHT-x*SMALLSEG_HEIGHT)/2 - -/* Keymaps */ -const struct button_mapping* plugin_contexts[]={ - generic_actions, - generic_directions -}; - -#define ACTION_COUNTER_TOGGLE PLA_FIRE -#define ACTION_COUNTER_RESET PLA_FIRE_REPEAT -#define ACTION_MENU PLA_MENU -#define ACTION_EXIT PLA_QUIT -#define ACTION_MODE_NEXT PLA_RIGHT -#define ACTION_MODE_PREV PLA_LEFT - -/************ - * Prototypes - ***********/ -void save_settings(bool interface); - -/******************** - * Misc counter stuff - *******************/ -int start_tick = 0; -int passed_time = 0; -int counter = 0; -int displayed_value = 0; -int count_h, count_m, count_s; -bool counting = false; - -/******************** - * Everything else... - *******************/ -bool idle_poweroff = true; /* poweroff activated or not? */ -bool exit_clock = false; /* when true, the main plugin loop will exit */ - -static struct plugin_api* rb; - -/*********************************************************************** - * Used for hands to define lengths at a given time, analog + fullscreen - **********************************************************************/ -unsigned int xminute[61]; -unsigned int yminute[61]; -unsigned int yhour[61]; -unsigned int xhour[61]; -unsigned int xminute_full[61]; -unsigned int yminute_full[61]; -unsigned int xhour_full[61]; -unsigned int yhour_full[61]; - -/* settings are saved to this location */ -static const char default_filename[] = "/.rockbox/rocks/.clock_settings"; - -/********************************************************* - * Some arrays/definitions for drawing settings/menu text. - ********************************************************/ -#define ANALOG 1 -#define FULLSCREEN 2 -#define DIGITAL 3 -#define PLAIN 4 -#define BINARY 5 -#define CLOCK_MODES 5 - -#define analog_date 0 -#define analog_secondhand 1 -#define analog_time 2 -#define digital_seconds 0 -#define digital_date 1 -#define digital_blinkcolon 2 -#define digital_format 3 -#define fullscreen_border 0 -#define fullscreen_secondhand 1 -#define binary_mode 0 -#define plain_format 0 -#define plain_seconds 1 -#define plain_date 2 -#define plain_blinkcolon 3 -#define general_counter 0 -#define general_savesetting 1 -#define general_backlight 2 - -/* Option structs (possible selections per each option) */ -static const struct opt_items noyes_text[] = { - { "No", -1 }, - { "Yes", -1 } -}; - -static const struct opt_items backlight_settings_text[] = { - { "Always Off", -1 }, - { "Rockbox setting", -1 }, - { "Always On", -1 } -}; -static const struct opt_items idle_poweroff_text[] = { - { "Disabled", -1 }, - { "Enabled", -1 } -}; -static const struct opt_items counting_direction_text[] = { - {"Down", -1}, - {"Up", -1} -}; -static const struct opt_items date_format_text[] = { - { "No", -1 }, - { "American format", -1 }, - { "European format", -1 } -}; - -static const struct opt_items analog_time_text[] = { - { "No", -1 }, - { "24-hour Format", -1 }, - { "12-hour Format", -1 } -}; - -static const struct opt_items time_format_text[] = { - { "24-hour Format", -1 }, - { "12-hour Format", -1 } -}; - -static const struct opt_items binary_mode_text[] = { - { "Numbers", -1 }, - { "Dots", -1 } -}; - -/***************************************** - * All settings, saved to default_filename - ****************************************/ -struct saved_settings -{ - int clock; /* clock mode */ - int general[4]; /* general settings*/ - int analog[3]; - int digital[4]; - int fullscreen[2]; - int binary[1]; - int plain[4]; -} clock_settings; - -/************************ - * Setting default values - ***********************/ -void reset_settings(void) -{ - clock_settings.clock = 1; - clock_settings.general[general_counter] = 1; - clock_settings.general[general_savesetting] = 1; - clock_settings.general[general_backlight] = 2; - clock_settings.analog[analog_date] = 0; - clock_settings.analog[analog_secondhand] = true; - clock_settings.analog[analog_time] = false; - clock_settings.digital[digital_seconds] = 1; - clock_settings.digital[digital_date] = 1; - clock_settings.digital[digital_blinkcolon] = false; - clock_settings.digital[digital_format] = true; - clock_settings.fullscreen[fullscreen_border] = true; - clock_settings.fullscreen[fullscreen_secondhand] = true; - clock_settings.plain[plain_format] = true; - clock_settings.plain[plain_seconds] = true; - clock_settings.plain[plain_date] = 1; - clock_settings.plain[plain_blinkcolon] = false; -} - -/************************************************************** - * Simple function to check if we're switching to digital mode, - * and if so, set bg/fg colors appropriately. - *************************************************************/ -void set_digital_colors(void) -{ -#ifdef HAVE_LCD_COLOR /* color LCDs.. */ - if(clock_settings.clock == DIGITAL) - { - rb->lcd_set_foreground(LCD_WHITE); - rb->lcd_set_background(LCD_BLACK); - } - else - { - rb->lcd_set_foreground(LCD_BLACK); - rb->lcd_set_background(LCD_RGBPACK(180,200,230)); - } -#elif LCD_DEPTH >= 2 - if(clock_settings.clock == DIGITAL) - { - rb->lcd_set_foreground(LCD_WHITE); - rb->lcd_set_background(LCD_BLACK); - } - else - { - rb->lcd_set_foreground(LCD_BLACK); - rb->lcd_set_background(LCD_WHITE); - } -#endif -} - -/************************************************************* - * Simple function to set standard black-on-light blue colors. - ************************************************************/ -void set_standard_colors(void) -{ -#ifdef HAVE_LCD_COLOR /* color LCDs only.. */ - rb->lcd_set_foreground(LCD_BLACK); - rb->lcd_set_background(LCD_RGBPACK(180,200,230)); -#elif LCD_DEPTH >= 2 - rb->lcd_set_foreground(LCD_BLACK); - rb->lcd_set_background(LCD_WHITE); -#endif -} - -/************************** - * Cleanup on plugin return - *************************/ -void cleanup(void *parameter) -{ - (void)parameter; - - if(clock_settings.general[general_savesetting] == 1) - save_settings(true); - - /* restore set backlight timeout */ - rb->backlight_set_timeout(rb->global_settings->backlight_timeout); -} - -/**************** - * Shows the logo - ***************/ -void show_clock_logo(void) -{ -#ifdef HAVE_LCD_COLOR - rb->lcd_set_foreground(LCD_BLACK); - rb->lcd_set_background(LCD_RGBPACK(180,200,230)); -#endif - - rb->lcd_clear_display();; - - rb->lcd_bitmap(clock_logo, 0, 0, LOGO_WIDTH, LOGO_HEIGHT); - - rb->lcd_update(); -} - -/******************************** - * Saves "saved_settings" to disk - *******************************/ -void save_settings(bool interface) -{ - int fd; - - if(interface) - { - rb->lcd_clear_display(); - show_clock_logo(); - - draw_message(MESSAGE_SAVING, 1); - - rb->lcd_update(); - } - - fd = rb->creat(default_filename); /* create the settings file */ - - if(fd >= 0) /* file exists, save successful */ - { - rb->write (fd, &clock_settings, sizeof(struct saved_settings)); - rb->close(fd); - - if(interface) - { - rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); - rb->lcd_fillrect(0, LCD_HEIGHT-MESSAGE_HEIGHT, LCD_WIDTH, MESSAGE_HEIGHT); - rb->lcd_set_drawmode(DRMODE_SOLID); - draw_message(MESSAGE_SAVED, 1); - } - } - else /* couldn't save for some reason */ - { - if(interface) - { - rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); - rb->lcd_fillrect(0, LCD_HEIGHT-MESSAGE_HEIGHT, LCD_WIDTH, MESSAGE_HEIGHT); - rb->lcd_set_drawmode(DRMODE_SOLID); - draw_message(MESSAGE_ERRSAVE, 1); - } - } - - if(interface) - { - rb->lcd_update(); - rb->sleep(HZ); /* pause a second */ - } -} - -/********************************** - * Loads "saved_settings" from disk - *********************************/ -void load_settings(void) -{ - /* open the settings file */ - int fd; - fd = rb->open(default_filename, O_RDONLY); - - rb->lcd_clear_display(); - show_clock_logo(); - - draw_message(MESSAGE_LOADING, 1); - - rb->lcd_update(); - - if(fd >= 0) /* does file exist? */ - { - if(rb->filesize(fd) == sizeof(struct saved_settings)) /* if so, is it the right size? */ - { - rb->read(fd, &clock_settings, sizeof(struct saved_settings)); - rb->close(fd); - - rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); - rb->lcd_fillrect(0, LCD_HEIGHT-MESSAGE_HEIGHT, LCD_WIDTH, MESSAGE_HEIGHT); - rb->lcd_set_drawmode(DRMODE_SOLID); - draw_message(MESSAGE_LOADED, 1); - } - else /* must be invalid, bail out */ - { - rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); - rb->lcd_fillrect(0, LCD_HEIGHT-MESSAGE_HEIGHT, LCD_WIDTH, MESSAGE_HEIGHT); - rb->lcd_set_drawmode(DRMODE_SOLID); - draw_message(MESSAGE_ERRLOAD, 1); - - reset_settings(); - } - } - else /* must be missing, bail out */ - { - rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); - rb->lcd_fillrect(0, LCD_HEIGHT-MESSAGE_HEIGHT, LCD_WIDTH, MESSAGE_HEIGHT); - rb->lcd_set_drawmode(DRMODE_SOLID); - draw_message(MESSAGE_ERRLOAD, 1); - - reset_settings(); - } - - rb->lcd_update(); - -#ifndef SIMULATOR - rb->ata_sleep(); -#endif - - rb->sleep(HZ); -} - -void polar_to_cartesian(int a, int r, int* x, int* y) -{ - *x = (sin_int(a) * r) >> 14; - *y = (sin_int(a-90) * r) >> 14; -} - -void polar_to_cartesian_screen_centered(struct screen * display, - int a, int r, int* x, int* y) -{ - polar_to_cartesian(a, r, x, y); - *x+=display->width/2; - *y+=display->height/2; -} - -void angle_to_square(struct screen * display, - int square_width, int square_height, - int a, int* x, int* y) -{ - a = (a+360-90)%360; - if(a>45 && a<=135){/* top line */ - a-=45; - *x=square_width-(square_width*2*a)/90; - *y=square_height; - }else if(a>135 && a<=225){/* left line */ - a-=135; - *x=-square_width; - *y=square_height-(square_height*2*a)/90; - }else if(a>225 && a<=315){/* bottom line */ - a-=225; - *x=(square_width*2*a)/90-square_width; - *y=-square_height; - }else if(a>315 || a<=45){/* right line */ - if(a>315) - a-=315; - else - a+=45; - *x=square_width; - *y=(square_height*2*a)/90-square_height; - } - /* recenter */ - *x+=display->width/2; - *y+=display->height/2; -} - -/******************************* - * Init clock, set up x/y tables - ******************************/ -void init_clock(void) -{ - #define ANALOG_VALUES 60 - #define ANALOG_YCENTER (LCD_HEIGHT/2) - #define ANALOG_XCENTER (LCD_WIDTH/2) - #define ANALOG_MIN_RADIUS MIN(LCD_HEIGHT/2 -10, LCD_WIDTH/2 -10) - #define ANALOG_HR_RADIUS ((2 * ANALOG_MIN_RADIUS)/3) - - #define PI 3.141592 - int i; - - rb->lcd_setfont(FONT_SYSFIXED); /* universal font */ - - load_settings(); - - /* set backlight timeout */ - if(clock_settings.general[general_backlight] == 0) - rb->backlight_set_timeout(0); - else if(clock_settings.general[general_backlight] == 1) - rb->backlight_set_timeout(rb->global_settings->backlight_timeout); - else if(clock_settings.general[general_backlight] == 2) - rb->backlight_set_timeout(1); - - for(i=0; iscreens[0], angle, ANALOG_MIN_RADIUS, - &(xminute[i]), &(yminute[i])); - polar_to_cartesian_screen_centered( - rb->screens[0], angle, ANALOG_HR_RADIUS, - &(xhour[i]), &(yhour[i])); - - /* Fullscreen initialization */ - angle_to_square(rb->screens[0], LCD_WIDTH/2, LCD_HEIGHT/2, angle, - &(xminute_full[i]), &(yminute_full[i])); - angle_to_square(rb->screens[0], LCD_WIDTH/3, LCD_HEIGHT/3, angle, - &(xhour_full[i]), &(yhour_full[i])); - } -} - -/******************* - * Analog clock mode - ******************/ -void analog_clock(int hour, int minute, int second) -{ - if(hour >= 12) - hour -= 12; - - int i; - int hourpos = (hour*5) + (minute/12); - - /* Crappy fake antialiasing (color LCDs only)! - * how this works is we draw a large mid-gray hr/min/sec hand, - * then the actual (slightly smaller) hand on top of those. - * End result: mid-gray edges to the black hands, smooths them out. */ -#ifdef HAVE_LCD_COLOR - rb->lcd_set_foreground(LCD_RGBPACK(100,110,125)); - - /* second hand */ - if(clock_settings.analog[analog_secondhand]) - { - xlcd_filltriangle(LCD_WIDTH/2, LCD_HEIGHT/2-2, LCD_WIDTH/2, LCD_HEIGHT/2+2, - xminute[second], yminute[second]); - xlcd_filltriangle(LCD_WIDTH/2-2, LCD_HEIGHT/2, LCD_WIDTH/2+2, LCD_HEIGHT/2, - xminute[second], yminute[second]); - } - - /* minute hand */ - xlcd_filltriangle(LCD_WIDTH/2, LCD_HEIGHT/2-4, LCD_WIDTH/2, LCD_HEIGHT/2+4, - xminute[minute], yminute[minute]); - xlcd_filltriangle(LCD_WIDTH/2-4, LCD_HEIGHT/2, LCD_WIDTH/2+4, LCD_HEIGHT/2, - xminute[minute], yminute[minute]); - - /* hour hand */ - xlcd_filltriangle(LCD_WIDTH/2, LCD_HEIGHT/2-4, LCD_WIDTH/2, LCD_HEIGHT/2+4, - xhour[hourpos], yhour[hourpos]); - xlcd_filltriangle(LCD_WIDTH/2-4, LCD_HEIGHT/2, LCD_WIDTH/2+4, LCD_HEIGHT/2, - xhour[hourpos], yhour[hourpos]); - - rb->lcd_set_foreground(LCD_BLACK); -#endif - - /* second hand, if needed */ - if(clock_settings.analog[analog_secondhand]) - { - xlcd_filltriangle(LCD_WIDTH/2, LCD_HEIGHT/2-1, LCD_WIDTH/2, LCD_HEIGHT/2+1, - xminute[second], yminute[second]); - xlcd_filltriangle(LCD_WIDTH/2-1, LCD_HEIGHT/2, LCD_WIDTH/2+1, LCD_HEIGHT/2, - xminute[second], yminute[second]); - } - - /* minute hand */ - xlcd_filltriangle(LCD_WIDTH/2, LCD_HEIGHT/2-HAND_W, LCD_WIDTH/2, - LCD_HEIGHT/2+HAND_W, xminute[minute], yminute[minute]); - xlcd_filltriangle(LCD_WIDTH/2-HAND_W, LCD_HEIGHT/2, LCD_WIDTH/2 - +HAND_W, LCD_HEIGHT/2, xminute[minute], yminute[minute]); - - /* hour hand */ - xlcd_filltriangle(LCD_WIDTH/2, LCD_HEIGHT/2-HAND_W, LCD_WIDTH/2, - LCD_HEIGHT/2+HAND_W, xhour[hourpos], yhour[hourpos]); - xlcd_filltriangle(LCD_WIDTH/2-HAND_W, LCD_HEIGHT/2, LCD_WIDTH/2 - +HAND_W, LCD_HEIGHT/2, xhour[hourpos], yhour[hourpos]); - - /* Draw the circle */ - for(i=0; i < 60; i+=5) - rb->lcd_fillrect(xminute[i]-1, yminute[i]-1, 3, 3); - - /* Draw the cover over the center */ - rb->lcd_drawline((LCD_WIDTH/2)-1, (LCD_HEIGHT/2)+3, - (LCD_WIDTH/2)+1, (LCD_HEIGHT/2)+3); - rb->lcd_drawline((LCD_WIDTH/2)-3, (LCD_HEIGHT/2)+2, - (LCD_WIDTH/2)+3, (LCD_HEIGHT/2)+2); - rb->lcd_drawline((LCD_WIDTH/2)-4, (LCD_HEIGHT/2)+1, - (LCD_WIDTH/2)+4, (LCD_HEIGHT/2)+1); - rb->lcd_drawline((LCD_WIDTH/2)-4, LCD_HEIGHT/2, - (LCD_WIDTH/2)+4, LCD_HEIGHT/2); - rb->lcd_drawline((LCD_WIDTH/2)-4, (LCD_HEIGHT/2)-1, - (LCD_WIDTH/2)+4, (LCD_HEIGHT/2)-1); - rb->lcd_drawline((LCD_WIDTH/2)-3, (LCD_HEIGHT/2)-2, - (LCD_WIDTH/2)+3, (LCD_HEIGHT/2)-2); - rb->lcd_drawline((LCD_WIDTH/2)-1, (LCD_HEIGHT/2)-3, - (LCD_WIDTH/2)+1, (LCD_HEIGHT/2)-3); -} - -/******************** - * Digital clock mode - *******************/ -void digital_clock(int hour, int minute, int second, bool colon) -{ - int x_ofs=0; - - /* this basically detects if we draw an AM or PM bitmap. - * if we don't, we center the hh:mm display. */ - if(!clock_settings.digital[digital_format]) - x_ofs=DIGIT_WIDTH/2; - -#if LCD_DEPTH == 1 - rb->lcd_fillrect(0,0,112,64); -#endif - - if(clock_settings.digital[digital_format]) - { - /* draw the AM or PM bitmap */ - if(hour<12) - draw_segment(SEGMENT_AM,DIGIT_XOFS(6)+DIGIT_WIDTH*5, 0); - else - draw_segment(SEGMENT_PM,DIGIT_XOFS(6)+DIGIT_WIDTH*5, 0); - - /* and then readjust the hour to 12-hour format - * ( 13:00+ -> 1:00+ ) */ - if(hour>12) - hour -= 12; - } - - /* hour */ - draw_segment(hour/10, DIGIT_XOFS(6)+x_ofs, 0); - draw_segment(hour%10, DIGIT_XOFS(6)+DIGIT_WIDTH+x_ofs, 0); - - /* colon */ - if(colon) - draw_segment(COLON, DIGIT_XOFS(6)+2*DIGIT_WIDTH+x_ofs, 0); - - /* minutes */ - draw_segment(minute/10, DIGIT_XOFS(6)+3*DIGIT_WIDTH+x_ofs, 0); - draw_segment(minute%10, DIGIT_XOFS(6)+4*DIGIT_WIDTH+x_ofs, 0); - - if(clock_settings.digital[digital_seconds]) - { - draw_segment(second/10, DIGIT_XOFS(2), DIGIT_HEIGHT); - draw_segment(second%10, DIGIT_XOFS(2)+DIGIT_WIDTH, DIGIT_HEIGHT); - } -} - -/*********************** - * Fullscreen clock mode - **********************/ -void fullscreen_clock(int hour, int minute, int second) -{ - if(hour >= 12) - hour -= 12; - - int i; - int hourpos = (hour*5) + (minute/12); - - /* Crappy fake antialiasing (color LCDs only)! - * how this works is we draw a large mid-gray hr/min/sec hand, - * then the actual (slightly smaller) hand on top of those. - * End result: mid-gray edges to the black hands, smooths them out. */ -#ifdef HAVE_LCD_COLOR - rb->lcd_set_foreground(LCD_RGBPACK(100,110,125)); - - /* second hand */ - if(clock_settings.analog[analog_secondhand]) - { - xlcd_filltriangle(LCD_WIDTH/2, LCD_HEIGHT/2-2, LCD_WIDTH/2, LCD_HEIGHT/2+2, - xminute_full[second], yminute_full[second]); - xlcd_filltriangle(LCD_WIDTH/2-2, LCD_HEIGHT/2, LCD_WIDTH/2+2, LCD_HEIGHT/2, - xminute_full[second], yminute_full[second]); - } - - /* minute hand */ - xlcd_filltriangle(LCD_WIDTH/2, LCD_HEIGHT/2-4, LCD_WIDTH/2, LCD_HEIGHT/2+4, - xminute_full[minute], yminute_full[minute]); - xlcd_filltriangle(LCD_WIDTH/2-4, LCD_HEIGHT/2, LCD_WIDTH/2+4, LCD_HEIGHT/2, - xminute_full[minute], yminute_full[minute]); - - /* hour hand */ - xlcd_filltriangle(LCD_WIDTH/2, LCD_HEIGHT/2-4, LCD_WIDTH/2, LCD_HEIGHT/2+4, - xhour_full[hourpos], yhour_full[hourpos]); - xlcd_filltriangle(LCD_WIDTH/2-4, LCD_HEIGHT/2, LCD_WIDTH/2+4, LCD_HEIGHT/2, - xhour_full[hourpos], yhour_full[hourpos]); - - rb->lcd_set_foreground(LCD_BLACK); -#endif - - /* second hand, if needed */ - if(clock_settings.analog[analog_secondhand]) - { - xlcd_filltriangle(LCD_WIDTH/2, LCD_HEIGHT/2-1, LCD_WIDTH/2, LCD_HEIGHT/2+1, - xminute_full[second], yminute_full[second]); - xlcd_filltriangle(LCD_WIDTH/2-1, LCD_HEIGHT/2, LCD_WIDTH/2+1, LCD_HEIGHT/2, - xminute_full[second], yminute_full[second]); - } - - /* minute hand */ - xlcd_filltriangle(LCD_WIDTH/2, LCD_HEIGHT/2-3, LCD_WIDTH/2, LCD_HEIGHT/2+3, - xminute_full[minute], yminute_full[minute]); - xlcd_filltriangle(LCD_WIDTH/2-3, LCD_HEIGHT/2, LCD_WIDTH/2+3, LCD_HEIGHT/2, - xminute_full[minute], yminute_full[minute]); - - /* hour hand */ - xlcd_filltriangle(LCD_WIDTH/2, LCD_HEIGHT/2-3, LCD_WIDTH/2, LCD_HEIGHT/2+3, - xhour_full[hourpos], yhour_full[hourpos]); - xlcd_filltriangle(LCD_WIDTH/2-3, LCD_HEIGHT/2, LCD_WIDTH/2+3, LCD_HEIGHT/2, - xhour_full[hourpos], yhour_full[hourpos]); - - /* Draw the circle */ - for(i=0; i < 60; i+=5) - rb->lcd_fillrect(xminute_full[i]-1, yminute_full[i]-1, 3, 3); - - /* Draw the cover over the center */ - rb->lcd_drawline((LCD_WIDTH/2)-1, (LCD_HEIGHT/2)+3, - (LCD_WIDTH/2)+1, (LCD_HEIGHT/2)+3); - rb->lcd_drawline((LCD_WIDTH/2)-3, (LCD_HEIGHT/2)+2, - (LCD_WIDTH/2)+3, (LCD_HEIGHT/2)+2); - rb->lcd_drawline((LCD_WIDTH/2)-4, (LCD_HEIGHT/2)+1, - (LCD_WIDTH/2)+4, (LCD_HEIGHT/2)+1); - rb->lcd_drawline((LCD_WIDTH/2)-4, LCD_HEIGHT/2, - (LCD_WIDTH/2)+4, LCD_HEIGHT/2); - rb->lcd_drawline((LCD_WIDTH/2)-4, (LCD_HEIGHT/2)-1, - (LCD_WIDTH/2)+4, (LCD_HEIGHT/2)-1); - rb->lcd_drawline((LCD_WIDTH/2)-3, (LCD_HEIGHT/2)-2, - (LCD_WIDTH/2)+3, (LCD_HEIGHT/2)-2); - rb->lcd_drawline((LCD_WIDTH/2)-1, (LCD_HEIGHT/2)-3, - (LCD_WIDTH/2)+1, (LCD_HEIGHT/2)-3); -} - -/******************* - * Binary clock mode - ******************/ -void binary_clock(int hour, int minute, int second) -{ - int i, xpos=0; - int mode_var[3]; /* pointers to h, m, s arguments */ - int mode; /* 0 = hour, 1 = minute, 2 = second */ - - mode_var[0] = hour; - mode_var[1] = minute; - mode_var[2] = second; - - for(mode = 0; mode < 3; mode++) - { - for(i = 32; i > 0; i /= 2) - { - if(mode_var[mode] >= i) - { - if(clock_settings.binary[binary_mode]) - draw_digit(DOT_FILLED, xpos*DIGIT_WIDTH+DIGIT_XOFS(6), DIGIT_HEIGHT*mode+DIGIT_YOFS(3)); - else - draw_digit(1, xpos*DIGIT_WIDTH+DIGIT_XOFS(6), DIGIT_HEIGHT*mode+DIGIT_YOFS(3)); - mode_var[mode] -= i; - } - else - { - if(clock_settings.binary[binary_mode]) - draw_digit(DOT_EMPTY, xpos*DIGIT_WIDTH+DIGIT_XOFS(6), DIGIT_HEIGHT*mode+DIGIT_YOFS(3)); - else - draw_digit(0, xpos*DIGIT_WIDTH+DIGIT_XOFS(6), DIGIT_HEIGHT*mode+DIGIT_YOFS(3)); - } - - xpos++; - } - - xpos=0; /* reset the x-pos for next mode */ - } -} - -/****************** - * Plain clock mode - *****************/ -void plain_clock(int hour, int minute, int second, bool colon) -{ - - int x_ofs=0; - - /* this basically detects if we draw an AM or PM bitmap. - * if we don't, we center the hh:mm display. */ - if(!clock_settings.plain[plain_format]) - x_ofs=DIGIT_WIDTH/2; - - if(clock_settings.plain[plain_format]) - { - /* draw the AM or PM bitmap */ - if(hour<12) - draw_digit(ICON_AM, DIGIT_XOFS(6)+(DIGIT_WIDTH*5)+x_ofs, 0); - else - draw_digit(ICON_PM, DIGIT_XOFS(6)+(DIGIT_WIDTH*5)+x_ofs, 0); - - /* and then readjust the hour to 12-hour format - * ( 13:00+ -> 1:00+ ) */ - if(hour>12) - hour -= 12; - } - - - draw_digit(hour/10, DIGIT_XOFS(6)+(DIGIT_WIDTH*0)+x_ofs, 0); - draw_digit(hour%10, DIGIT_XOFS(6)+(DIGIT_WIDTH*1)+x_ofs, 0); - - if(colon) - draw_digit(COLON, DIGIT_XOFS(6)+(DIGIT_WIDTH*2)+x_ofs, 0); - - draw_digit(minute/10, DIGIT_XOFS(6)+(DIGIT_WIDTH*3)+x_ofs, 0); - draw_digit(minute%10, DIGIT_XOFS(6)+(DIGIT_WIDTH*4)+x_ofs, 0); - - if(clock_settings.plain[plain_seconds]) - { - draw_digit(second/10, DIGIT_XOFS(2), DIGIT_HEIGHT); - draw_digit(second%10, DIGIT_XOFS(2)+(DIGIT_WIDTH), DIGIT_HEIGHT); - } -} - - - -/**************************************** - * Draws the extras, IE border, digits... - ***************************************/ -void draw_extras(int year, int day, int month, int hour, int minute, int second) -{ - int i; - - struct tm* current_time = rb->get_time(); - - char moday[8]; - char dateyr[6]; - char tmhrmin[7]; - char tmsec[3]; - - /* american date readout */ - if(clock_settings.analog[analog_date] == 1) - rb->snprintf(moday, sizeof(moday), "%02d/%02d", month, day); - else - rb->snprintf(moday, sizeof(moday), "%02d.%02d", day, month); - rb->snprintf(dateyr, sizeof(dateyr), "%d", year); - rb->snprintf(tmhrmin, sizeof(tmhrmin), "%02d:%02d", hour, minute); - rb->snprintf(tmsec, sizeof(tmsec), "%02d", second); - - /* Analog Extras */ - if(clock_settings.clock == ANALOG) - { - if(clock_settings.analog[analog_time] != 0) /* Digital readout */ - { - draw_smalldigit(hour/10, SMALLDIGIT_WIDTH*0, 0); - draw_smalldigit(hour%10, SMALLDIGIT_WIDTH*1, 0); - draw_smalldigit(COLON, SMALLDIGIT_WIDTH*2, 0); - draw_smalldigit(minute/10, SMALLDIGIT_WIDTH*3, 0); - draw_smalldigit(minute%10, SMALLDIGIT_WIDTH*4, 0); - - draw_smalldigit(second/10, SMALLDIGIT_WIDTH*1.5, SMALLDIGIT_HEIGHT); - draw_smalldigit(second%10, SMALLDIGIT_WIDTH*2.5, SMALLDIGIT_HEIGHT); - - /* AM/PM indicator */ - if(clock_settings.analog[analog_time] == 2) - { - if(current_time->tm_hour > 12) /* PM */ - draw_digit(ICON_PM, LCD_WIDTH-DIGIT_WIDTH, DIGIT_HEIGHT/2-DIGIT_HEIGHT); - else /* AM */ - draw_digit(ICON_AM, LCD_WIDTH-DIGIT_WIDTH, DIGIT_HEIGHT/2-DIGIT_HEIGHT); - } - } - if(clock_settings.analog[analog_date] != 0) /* Date readout */ - { - if(clock_settings.analog[analog_date] == 1) - { - draw_smalldigit(month/10, SMALLDIGIT_WIDTH*0, - LCD_HEIGHT-SMALLDIGIT_HEIGHT*2); - draw_smalldigit(month%10, SMALLDIGIT_WIDTH*1, - LCD_HEIGHT-SMALLDIGIT_HEIGHT*2); - draw_smalldigit(SLASH, SMALLDIGIT_WIDTH*2, - LCD_HEIGHT-SMALLDIGIT_HEIGHT*2); - draw_smalldigit(day/10, SMALLDIGIT_WIDTH*3, - LCD_HEIGHT-SMALLDIGIT_HEIGHT*2); - draw_smalldigit(day%10, SMALLDIGIT_WIDTH*4, - LCD_HEIGHT-SMALLDIGIT_HEIGHT*2); - draw_smalldigit(year/1000, SMALLDIGIT_WIDTH*0.5, - LCD_HEIGHT-SMALLDIGIT_HEIGHT); - draw_smalldigit(year%1000/100, SMALLDIGIT_WIDTH*1.5, - LCD_HEIGHT-SMALLDIGIT_HEIGHT); - draw_smalldigit(year%100/10, SMALLDIGIT_WIDTH*2.5, - LCD_HEIGHT-SMALLDIGIT_HEIGHT); - draw_smalldigit(year%10, SMALLDIGIT_WIDTH*3.5, - LCD_HEIGHT-SMALLDIGIT_HEIGHT); - } - else if(clock_settings.analog[analog_date] == 2) - { - - draw_smalldigit(day/10, SMALLDIGIT_WIDTH*0, - LCD_HEIGHT-SMALLDIGIT_HEIGHT*2); - draw_smalldigit(day%10, SMALLDIGIT_WIDTH*1, - LCD_HEIGHT-SMALLDIGIT_HEIGHT*2); - draw_smalldigit(PERIOD, SMALLDIGIT_WIDTH*2, - LCD_HEIGHT-SMALLDIGIT_HEIGHT*2); - draw_smalldigit(month/10, SMALLDIGIT_WIDTH*3, - LCD_HEIGHT-SMALLDIGIT_HEIGHT*2); - draw_smalldigit(month%10, SMALLDIGIT_WIDTH*4, - LCD_HEIGHT-SMALLDIGIT_HEIGHT*2); - draw_smalldigit(year/1000, SMALLDIGIT_WIDTH*0.5, - LCD_HEIGHT-SMALLDIGIT_HEIGHT); - draw_smalldigit(year%1000/100, SMALLDIGIT_WIDTH*1.5, - LCD_HEIGHT-SMALLDIGIT_HEIGHT); - draw_smalldigit(year%100/10, SMALLDIGIT_WIDTH*2.5, - LCD_HEIGHT-SMALLDIGIT_HEIGHT); - draw_smalldigit(year%10, SMALLDIGIT_WIDTH*3.5, - LCD_HEIGHT-SMALLDIGIT_HEIGHT); - } - } - } - else if(clock_settings.clock == DIGITAL) - { - /* Date readout */ - if(clock_settings.digital[digital_date] == 1) /* american mode */ - { - draw_smallsegment(month/10, SMALLSEG_WIDTH*0+SMALLSEG_XOFS(10), - LCD_HEIGHT-SMALLSEG_HEIGHT*LCD_OFFSET*2); - draw_smallsegment(month%10, SMALLSEG_WIDTH*1+SMALLSEG_XOFS(10), - LCD_HEIGHT-SMALLSEG_HEIGHT*LCD_OFFSET*2); - draw_smallsegment(SLASH, SMALLSEG_WIDTH*2+SMALLSEG_XOFS(10), - LCD_HEIGHT-SMALLSEG_HEIGHT*LCD_OFFSET*2); - draw_smallsegment(day/10, SMALLSEG_WIDTH*3+SMALLSEG_XOFS(10), - LCD_HEIGHT-SMALLSEG_HEIGHT*LCD_OFFSET*2); - draw_smallsegment(day%10, SMALLSEG_WIDTH*4+SMALLSEG_XOFS(10), - LCD_HEIGHT-SMALLSEG_HEIGHT*LCD_OFFSET*2); - draw_smallsegment(SLASH, SMALLSEG_WIDTH*5+SMALLSEG_XOFS(10), - LCD_HEIGHT-SMALLSEG_HEIGHT*LCD_OFFSET*2); - draw_smallsegment(year/1000, SMALLSEG_WIDTH*6+SMALLSEG_XOFS(10), - LCD_HEIGHT-SMALLSEG_HEIGHT*LCD_OFFSET*2); - draw_smallsegment(year%1000/100, SMALLSEG_WIDTH*7+SMALLSEG_XOFS(10), - LCD_HEIGHT-SMALLSEG_HEIGHT*LCD_OFFSET*2); - draw_smallsegment(year%100/10, SMALLSEG_WIDTH*8+SMALLSEG_XOFS(10), - LCD_HEIGHT-SMALLSEG_HEIGHT*LCD_OFFSET*2); - draw_smallsegment(year%10, SMALLSEG_WIDTH*9+SMALLSEG_XOFS(10), - LCD_HEIGHT-SMALLSEG_HEIGHT*LCD_OFFSET*2); - } - else if(clock_settings.digital[digital_date] == 2) /* european mode */ - { - draw_smallsegment(day/10, SMALLSEG_WIDTH*0+SMALLSEG_XOFS(10), - LCD_HEIGHT-SMALLSEG_HEIGHT*LCD_OFFSET*2); - draw_smallsegment(day%10, SMALLSEG_WIDTH*1+SMALLSEG_XOFS(10), - LCD_HEIGHT-SMALLSEG_HEIGHT*LCD_OFFSET*2); - draw_smallsegment(PERIOD, SMALLSEG_WIDTH*2+SMALLSEG_XOFS(10), - LCD_HEIGHT-SMALLSEG_HEIGHT*LCD_OFFSET*2); - draw_smallsegment(month/10, SMALLSEG_WIDTH*3+SMALLSEG_XOFS(10), - LCD_HEIGHT-SMALLSEG_HEIGHT*LCD_OFFSET*2); - draw_smallsegment(month%10, SMALLSEG_WIDTH*4+SMALLSEG_XOFS(10), - LCD_HEIGHT-SMALLSEG_HEIGHT*LCD_OFFSET*2); - draw_smallsegment(PERIOD, SMALLSEG_WIDTH*5+SMALLSEG_XOFS(10), - LCD_HEIGHT-SMALLSEG_HEIGHT*LCD_OFFSET*2); - draw_smallsegment(year/1000, SMALLSEG_WIDTH*6+SMALLSEG_XOFS(10), - LCD_HEIGHT-SMALLSEG_HEIGHT*LCD_OFFSET*2); - draw_smallsegment(year%1000/100, SMALLSEG_WIDTH*7+SMALLSEG_XOFS(10), - LCD_HEIGHT-SMALLSEG_HEIGHT*LCD_OFFSET*2); - draw_smallsegment(year%100/10, SMALLSEG_WIDTH*8+SMALLSEG_XOFS(10), - LCD_HEIGHT-SMALLSEG_HEIGHT*LCD_OFFSET*2); - draw_smallsegment(year%10, SMALLSEG_WIDTH*9+SMALLSEG_XOFS(10), - LCD_HEIGHT-SMALLSEG_HEIGHT*LCD_OFFSET*2); - } - } - else if(clock_settings.clock == FULLSCREEN) /* Fullscreen mode */ - { - if(clock_settings.fullscreen[fullscreen_border]) - { - for(i=0; i < 60; i+=5) /* Draw the circle */ - rb->lcd_fillrect(xminute_full[i]-1, yminute_full[i]-1, 3, 3); - } - } - else if(clock_settings.clock == PLAIN) /* Plain mode */ - { - /* Date readout */ - if(clock_settings.plain[plain_date] == 1) /* american mode */ - { - draw_smalldigit(month/10, SMALLDIGIT_WIDTH*0+SMALLDIGIT_XOFS(10), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*LCD_OFFSET*2); - draw_smalldigit(month%10, SMALLDIGIT_WIDTH*1+SMALLDIGIT_XOFS(10), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*LCD_OFFSET*2); - draw_smalldigit(SLASH, SMALLDIGIT_WIDTH*2+SMALLDIGIT_XOFS(10), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*LCD_OFFSET*2); - draw_smalldigit(day/10, SMALLDIGIT_WIDTH*3+SMALLDIGIT_XOFS(10), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*LCD_OFFSET*2); - draw_smalldigit(day%10, SMALLDIGIT_WIDTH*4+SMALLDIGIT_XOFS(10), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*LCD_OFFSET*2); - draw_smalldigit(SLASH, SMALLDIGIT_WIDTH*5+SMALLDIGIT_XOFS(10), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*LCD_OFFSET*2); - draw_smalldigit(year/1000, SMALLDIGIT_WIDTH*6+SMALLDIGIT_XOFS(10), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*LCD_OFFSET*2); - draw_smalldigit(year%1000/100, SMALLDIGIT_WIDTH*7+SMALLDIGIT_XOFS(10), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*LCD_OFFSET*2); - draw_smalldigit(year%100/10, SMALLDIGIT_WIDTH*8+SMALLDIGIT_XOFS(10), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*LCD_OFFSET*2); - draw_smalldigit(year%10, SMALLDIGIT_WIDTH*9+SMALLDIGIT_XOFS(10), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*LCD_OFFSET*2); - } - else if(clock_settings.plain[plain_date] == 2) /* european mode */ - { - draw_smalldigit(day/10, SMALLDIGIT_WIDTH*0+SMALLDIGIT_XOFS(10), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*LCD_OFFSET*2); - draw_smalldigit(day%10, SMALLDIGIT_WIDTH*1+SMALLDIGIT_XOFS(10), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*LCD_OFFSET*2); - draw_smalldigit(PERIOD, SMALLDIGIT_WIDTH*2+SMALLDIGIT_XOFS(10), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*LCD_OFFSET*2); - draw_smalldigit(month/10, SMALLDIGIT_WIDTH*3+SMALLDIGIT_XOFS(10), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*LCD_OFFSET*2); - draw_smalldigit(month%10, SMALLDIGIT_WIDTH*4+SMALLDIGIT_XOFS(10), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*LCD_OFFSET*2); - draw_smalldigit(PERIOD, SMALLDIGIT_WIDTH*5+SMALLDIGIT_XOFS(10), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*LCD_OFFSET*2); - draw_smalldigit(year/1000, SMALLDIGIT_WIDTH*6+SMALLDIGIT_XOFS(10), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*LCD_OFFSET*2); - draw_smalldigit(year%1000/100, SMALLDIGIT_WIDTH*7+SMALLDIGIT_XOFS(10), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*LCD_OFFSET*2); - draw_smalldigit(year%100/10, SMALLDIGIT_WIDTH*8+SMALLDIGIT_XOFS(10), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*LCD_OFFSET*2); - draw_smalldigit(year%10, SMALLDIGIT_WIDTH*9+SMALLDIGIT_XOFS(10), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*LCD_OFFSET*2); - } - } -} - -/********************* - * Display the counter - ********************/ -void show_counter(void) -{ - - /* increment counter */ - if(counting) - passed_time = *rb->current_tick - start_tick; - else - passed_time = 0; - - displayed_value = counter + passed_time; - displayed_value = displayed_value / HZ; - - /* these are the REAL displayed values */ - count_s = displayed_value % 60; - count_m = displayed_value % 3600 / 60; - count_h = displayed_value / 3600; - - if(clock_settings.general[general_counter]) - { - if(clock_settings.clock == ANALOG) - { - draw_smalldigit(count_h/10, LCD_WIDTH-SMALLDIGIT_WIDTH*5, - LCD_HEIGHT-SMALLDIGIT_HEIGHT*2); - draw_smalldigit(count_h%10, LCD_WIDTH-SMALLDIGIT_WIDTH*4, - LCD_HEIGHT-SMALLDIGIT_HEIGHT*2); - draw_smalldigit(COLON, LCD_WIDTH-SMALLDIGIT_WIDTH*3, - LCD_HEIGHT-SMALLDIGIT_HEIGHT*2); - draw_smalldigit(count_m/10, LCD_WIDTH-SMALLDIGIT_WIDTH*2, - LCD_HEIGHT-SMALLDIGIT_HEIGHT*2); - draw_smalldigit(count_m%10, LCD_WIDTH-SMALLDIGIT_WIDTH, - LCD_HEIGHT-SMALLDIGIT_HEIGHT*2); - draw_smalldigit(count_s/10, LCD_WIDTH-SMALLDIGIT_WIDTH*3.5, - LCD_HEIGHT-SMALLDIGIT_HEIGHT); - draw_smalldigit(count_s%10, LCD_WIDTH-SMALLDIGIT_WIDTH*2.5, - LCD_HEIGHT-SMALLDIGIT_HEIGHT); - } - else if(clock_settings.clock == DIGITAL) - { - draw_smallsegment(count_h/10, SMALLSEG_WIDTH*0+SMALLSEG_XOFS(8), - LCD_HEIGHT-SMALLSEG_HEIGHT*LCD_OFFSET); - draw_smallsegment(count_h%10, SMALLSEG_WIDTH*1+SMALLSEG_XOFS(8), - LCD_HEIGHT-SMALLSEG_HEIGHT*LCD_OFFSET); - draw_smallsegment(COLON, SMALLSEG_WIDTH*2+SMALLSEG_XOFS(8), - LCD_HEIGHT-SMALLSEG_HEIGHT*LCD_OFFSET); - draw_smallsegment(count_m/10, SMALLSEG_WIDTH*3+SMALLSEG_XOFS(8), - LCD_HEIGHT-SMALLSEG_HEIGHT*LCD_OFFSET); - draw_smallsegment(count_m%10, SMALLSEG_WIDTH*4+SMALLSEG_XOFS(8), - LCD_HEIGHT-SMALLSEG_HEIGHT*LCD_OFFSET); - draw_smallsegment(COLON, SMALLSEG_WIDTH*5+SMALLSEG_XOFS(8), - LCD_HEIGHT-SMALLSEG_HEIGHT*LCD_OFFSET); - draw_smallsegment(count_s/10, SMALLSEG_WIDTH*6+SMALLSEG_XOFS(8), - LCD_HEIGHT-SMALLSEG_HEIGHT*LCD_OFFSET); - draw_smallsegment(count_s%10, SMALLSEG_WIDTH*7+SMALLSEG_XOFS(8), - LCD_HEIGHT-SMALLSEG_HEIGHT*LCD_OFFSET); - } - else if(clock_settings.clock == FULLSCREEN) - { - - draw_smalldigit(count_h/10, SMALLDIGIT_WIDTH*0+SMALLDIGIT_XOFS(8), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*1.5); - draw_smalldigit(count_h%10, SMALLDIGIT_WIDTH*1+SMALLDIGIT_XOFS(8), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*1.5); - draw_smalldigit(COLON, SMALLDIGIT_WIDTH*2+SMALLDIGIT_XOFS(8), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*1.5); - draw_smalldigit(count_m/10, SMALLDIGIT_WIDTH*3+SMALLDIGIT_XOFS(8), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*1.5); - draw_smalldigit(count_m%10, SMALLDIGIT_WIDTH*4+SMALLDIGIT_XOFS(8), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*1.5); - draw_smalldigit(COLON, SMALLDIGIT_WIDTH*5+SMALLDIGIT_XOFS(8), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*1.5); - draw_smalldigit(count_s/10, SMALLDIGIT_WIDTH*6+SMALLDIGIT_XOFS(8), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*1.5); - draw_smalldigit(count_s%10, SMALLDIGIT_WIDTH*7+SMALLDIGIT_XOFS(8), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*1.5); - } - else if(clock_settings.clock == PLAIN) - { - draw_smalldigit(count_h/10, SMALLDIGIT_WIDTH*0+SMALLDIGIT_XOFS(8), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*LCD_OFFSET); - draw_smalldigit(count_h%10, SMALLDIGIT_WIDTH*1+SMALLDIGIT_XOFS(8), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*LCD_OFFSET); - draw_smalldigit(COLON, SMALLDIGIT_WIDTH*2+SMALLDIGIT_XOFS(8), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*LCD_OFFSET); - draw_smalldigit(count_m/10, SMALLDIGIT_WIDTH*3+SMALLDIGIT_XOFS(8), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*LCD_OFFSET); - draw_smalldigit(count_m%10, SMALLDIGIT_WIDTH*4+SMALLDIGIT_XOFS(8), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*LCD_OFFSET); - draw_smalldigit(COLON, SMALLDIGIT_WIDTH*5+SMALLDIGIT_XOFS(8), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*LCD_OFFSET); - draw_smalldigit(count_s/10, SMALLDIGIT_WIDTH*6+SMALLDIGIT_XOFS(8), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*LCD_OFFSET); - draw_smalldigit(count_s%10, SMALLDIGIT_WIDTH*7+SMALLDIGIT_XOFS(8), - LCD_HEIGHT-SMALLDIGIT_HEIGHT*LCD_OFFSET); - } - } -} - -/* Menus */ - -/*************** - * Select a mode - **************/ -bool menu_mode_selector(void) -{ - int selection=clock_settings.clock-1; - - set_standard_colors(); - - MENUITEM_STRINGLIST(menu,"Mode Selector",NULL, "Analog", "Full-screen", - "Digital/LCD","Plain","Binary"); - - /* check for this, so if the user exits the menu without - * making a selection, it won't change to some weird value. */ - if(rb->do_menu(&menu, &selection) >=0){ - clock_settings.clock = selection+1; - return(true); - } - return(false); -} - -/********************** - * Analog settings menu - *********************/ -void menu_analog_settings(void) -{ - int selection=0, result=0; - - MENUITEM_STRINGLIST(menu,"Analog Mode Settings",NULL,"Show Date", - "Show Second Hand","Show Time Readout"); - - while(result>=0) - { - result=rb->do_menu(&menu, &selection); - switch(result) - { - case 0: - rb->set_option("Show Date", &clock_settings.analog[analog_date], - INT, date_format_text, 3, NULL); - break; - case 1: - rb->set_option("Show Second Hand", &clock_settings.analog[analog_secondhand], - INT, noyes_text, 2, NULL); - break; - case 2: - rb->set_option("Show Time", &clock_settings.analog[analog_time], - INT, analog_time_text, 3, NULL); - break; - } - } -} - -/*********************** - * Digital settings menu - **********************/ -void menu_digital_settings(void) -{ - int selection=0, result=0; - - MENUITEM_STRINGLIST(menu,"Digital/LCD Mode Settings",NULL,"Show Date", - "Show Seconds","Blinking Colon","Time Format"); - - while(result>=0) - { - result=rb->do_menu(&menu, &selection); - switch(result) - { - case 0: - rb->set_option("Show Date", &clock_settings.digital[digital_date], - INT, date_format_text, 3, NULL); - break; - case 1: - rb->set_option("Show Seconds", &clock_settings.digital[digital_seconds], - INT, noyes_text, 2, NULL); - break; - case 2: - rb->set_option("Blinking Colon", &clock_settings.digital[digital_blinkcolon], - INT, noyes_text, 2, NULL); - break; - case 3: - rb->set_option("Time Format", &clock_settings.digital[digital_format], - INT, time_format_text, 2, NULL); - break; - } - } -} - -/************************** - * Fullscreen settings menu - *************************/ -void menu_fullscreen_settings(void) -{ - int selection=0, result=0; - - MENUITEM_STRINGLIST(menu,"Fullscreen Mode Settings",NULL, - "Show Border","Show Second Hand"); - - while(result>=0) - { - result=rb->do_menu(&menu, &selection); - switch(result) - { - case 0: - rb->set_option("Show Border", &clock_settings.fullscreen[fullscreen_border], - INT, noyes_text, 2, NULL); - break; - case 1: - rb->set_option("Show Second Hand", &clock_settings.fullscreen[fullscreen_secondhand], - INT, noyes_text, 2, NULL); - break; - } - } -} - -/********************** - * Binary settings menu - *********************/ -void menu_binary_settings(void) -{ - int selection=0, result=0; - - MENUITEM_STRINGLIST(menu,"Binary Mode Settings",NULL,"Display Mode"); - - while(result>=0) - { - result=rb->do_menu(&menu, &selection); - switch(result) - { - case 0: - rb->set_option("Display Mode", &clock_settings.binary[binary_mode], - INT, binary_mode_text, 2, NULL); - } - - } -} - -/********************* - * Plain settings menu - ********************/ -void menu_plain_settings(void) -{ - int selection=0, result=0; - - MENUITEM_STRINGLIST(menu,"Plain Mode Settings",NULL,"Show Date", - "Show Seconds","Blinking Colon","Time Format"); - - while(result>=0) - { - result=rb->do_menu(&menu, &selection); - switch(result) - { - case 0: - rb->set_option("Show Date", &clock_settings.plain[plain_date], - INT, date_format_text, 3, NULL); - break; - case 1: - rb->set_option("Show Seconds", &clock_settings.plain[plain_seconds], - INT, noyes_text, 2, NULL); - break; - case 2: - rb->set_option("Blinking Colon", &clock_settings.plain[plain_blinkcolon], - INT, noyes_text, 2, NULL); - break; - case 3: - rb->set_option("Time Format", &clock_settings.plain[plain_format], - INT, time_format_text, 2, NULL); - break; - } - } -} - -/*********************************************************** - * Confirm resetting of settings, used in general_settings() - **********************************************************/ -void confirm_reset(void) -{ - int result=0; - - rb->set_option("Reset all settings?", &result, INT, noyes_text, 2, NULL); - - if(result == 1) /* reset! */ - { - reset_settings(); - rb->splash(HZ, "Settings reset!"); - } - else - rb->splash(HZ, "Settings NOT reset."); -} - -/************************************ - * General settings. Reset, save, etc - ***********************************/ -void menu_general_settings(void) -{ - int selection=0, result=0; - - MENUITEM_STRINGLIST(menu,"General Settings",NULL,"Reset Settings", - "Save Settings Now","Save On Exit","Show Counter", - "Backlight Settings","Idle Poweroff (temporary)"); - - while(result>=0) - { - result=rb->do_menu(&menu, &selection); - switch(result) - { - case 0: - confirm_reset(); - break; - - case 1: - save_settings(false); - rb->splash(HZ, "Settings saved"); - break; - - case 2: - rb->set_option("Save On Exit", &clock_settings.general[general_savesetting], - INT, noyes_text, 2, NULL); - - /* if we no longer save on exit, we better save now to remember that */ - if(clock_settings.general[general_savesetting] == 0) - save_settings(false); - break; - - case 3: - rb->set_option("Show Counter", &clock_settings.general[general_counter], - INT, noyes_text, 2, NULL); - break; - - case 4: - rb->set_option("Backlight Settings", &clock_settings.general[general_backlight], - INT, backlight_settings_text, 3, NULL); - break; - - case 5: - rb->set_option("Idle Poweroff (temporary)", &idle_poweroff, - BOOL, idle_poweroff_text, 2, NULL); - break; - } - - } -} - -/*********** - * Main menu - **********/ -void main_menu(void) -{ - int selection=0; - bool done = false; - - set_standard_colors(); - - MENUITEM_STRINGLIST(menu,"Clock Menu",NULL,"View Clock","Mode Selector", - "Mode Settings","General Settings","Quit"); - - while(!done) - { - switch(rb->do_menu(&menu, &selection)) - { - case 0: - rb->lcd_setfont(FONT_SYSFIXED); - done = true; - break; - - case 1: - done=menu_mode_selector(); - break; - - case 2: - switch(clock_settings.clock) - { - case ANALOG: menu_analog_settings();break; - case DIGITAL: menu_digital_settings();break; - case FULLSCREEN: menu_fullscreen_settings();break; - case BINARY: menu_binary_settings();break; - case PLAIN: menu_plain_settings();break; - } - break; - - case 3: - menu_general_settings(); - break; - - case 4: - exit_clock = true; - done = true; - break; - - default: - done=true; - break; - } - } - - rb->lcd_setfont(FONT_SYSFIXED); - set_digital_colors(); -} - -/********************************************************************** - * Plugin starts here - **********************************************************************/ -enum plugin_status plugin_start(struct plugin_api* api, void* parameter) -{ - int button; - - /* time/date ints */ - int hour, minute, second; - int temphour; - int last_second = -1; - int year, day, month; - - bool counter_btn_held = false; - - struct tm* current_time; - - (void)parameter; - rb = api; - -#if LCD_DEPTH > 1 - rb->lcd_set_backdrop(NULL); -#endif - - init_clock(); - - /* init xlcd functions */ - xlcd_init(rb); - - set_digital_colors(); - - while(!exit_clock) - { - /********************* - * Time info - *********************/ - current_time = rb->get_time(); - hour = current_time->tm_hour; - minute = current_time->tm_min; - second = current_time->tm_sec; - temphour = current_time->tm_hour; - - /********************* - * Date info - *********************/ - year = current_time->tm_year + 1900; - day = current_time->tm_mday; - month = current_time->tm_mon + 1; - - if(second != last_second) - { - rb->lcd_clear_display(); - - /* Analog mode */ - if(clock_settings.clock == ANALOG) - analog_clock(hour, minute, second); - /* Digital mode */ - else if(clock_settings.clock == DIGITAL) - { - if(clock_settings.digital[digital_blinkcolon]) - digital_clock(hour, minute, second, second & 1); - else - digital_clock(hour, minute, second, true); - } - /* Fullscreen mode */ - else if(clock_settings.clock == FULLSCREEN) - fullscreen_clock(hour, minute, second); - /* Binary mode */ - else if(clock_settings.clock == BINARY) - binary_clock(hour, minute, second); - /* Plain mode */ - else if(clock_settings.clock == PLAIN) - { - if(clock_settings.plain[plain_blinkcolon]) - plain_clock(hour, minute, second, second & 1); - else - plain_clock(hour, minute, second, true); - } - - /* show counter */ - show_counter(); - } - - if(clock_settings.analog[analog_time] == 2 && temphour == 0) - temphour = 12; - if(clock_settings.analog[analog_time] == 2 && temphour > 12) - temphour -= 12; - - /* all the "extras" - readouts/displays */ - draw_extras(year, day, month, temphour, minute, second); - - if(!idle_poweroff) - rb->reset_poweroff_timer(); - - rb->lcd_update(); - - /************************* - * Scan for button presses - ************************/ - button = pluginlib_getaction(rb, HZ/10, plugin_contexts, 2); - switch (button) - { - case ACTION_COUNTER_TOGGLE: /* start/stop counter */ - if(clock_settings.general[general_counter]) - { - if(!counter_btn_held) /* Ignore if the counter was reset */ - { - if(counting) - { - counting = false; - counter += passed_time; - } - else - { - counting = true; - start_tick = *rb->current_tick; - } - } - counter_btn_held = false; - } - break; - - case ACTION_COUNTER_RESET: /* reset counter */ - if(clock_settings.general[general_counter]) - { - counter_btn_held = true; /* Ignore the release event */ - counter = 0; - start_tick = *rb->current_tick; - } - break; - - case ACTION_MODE_NEXT: - if(clock_settings.clock < CLOCK_MODES) - clock_settings.clock++; - else - clock_settings.clock = 1; - - set_digital_colors(); - break; - - case ACTION_MODE_PREV: - if(clock_settings.clock > 1) - clock_settings.clock--; - else - clock_settings.clock = CLOCK_MODES; - - set_digital_colors(); - break; - - case ACTION_MENU: - main_menu(); - break; - - case ACTION_EXIT: - exit_clock=true; - break; - - default: - if(rb->default_event_handler_ex(button, cleanup, NULL) - == SYS_USB_CONNECTED) - return PLUGIN_USB_CONNECTED; - break; - } - } - - cleanup(NULL); - return PLUGIN_OK; -} diff --git a/apps/plugins/clock/Makefile b/apps/plugins/clock/Makefile new file mode 100644 index 0000000000..0481d3e1c2 --- /dev/null +++ b/apps/plugins/clock/Makefile @@ -0,0 +1,112 @@ +# __________ __ ___. +# Open \______ \ ____ ____ | | _\_ |__ _______ ___ +# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / +# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < +# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ +# \/ \/ \/ \/ \/ +# $$Id: $$ +# + +INCLUDES = -I$(APPSDIR) -I.. -I. -I$(APPSDIR)/plugins/lib \ + $(TARGET_INC) -I$(FIRMDIR)/include -I$(FIRMDIR)/export \ + -I$(FIRMDIR)/common -I$(FIRMDIR)/drivers -I$(OUTDIR) -I$(BUILDDIR) \ + -I$(BUILDDIR)/pluginbitmaps +CFLAGS = $(INCLUDES) $(GCCOPTS) $(TARGET) $(EXTRA_DEFINES) \ + -DTARGET_ID=$(TARGET_ID) -DMEM=${MEMORYSIZE} -DPLUGIN + +ifdef APPEXTRA + INCLUDES += $(patsubst %,-I$(APPSDIR)/%,$(subst :, ,$(APPEXTRA))) +endif + +LINKFILE := $(OBJDIR)/link.lds +DEPFILE = $(OBJDIR)/dep-clock + +# This sets up 'SRC' based on the files mentioned in SOURCES +include $(TOOLSDIR)/makesrc.inc + +SOURCES = $(SRC) +OBJS := $(SRC:%.c=$(OBJDIR)/%.o) +DIRS = . + +ifndef SIMVER + LDS := ../plugin.lds + OUTPUT = $(OUTDIR)/clock.rock +else ## simulators + OUTPUT = $(OUTDIR)/clock.rock +endif + +all: $(OUTPUT) + +ifndef SIMVER +$(OBJDIR)/clock.elf: $(OBJS) $(LINKFILE) $(BITMAPLIBS) + $(call PRINTS,LD $(@F))$(CC) $(GCCOPTS) -O -nostdlib -o $@ $(OBJS) -L$(BUILDDIR) -lplugin -lgcc \ + $(LINKBITMAPS) -T$(LINKFILE) -Wl,-Map,$(OBJDIR)/clock.map + +$(OUTPUT): $(OBJDIR)/clock.elf + $(call PRINTS,OBJCOPY $(@F))$(OC) -O binary $< $@ +else + +ifeq ($(SIMVER), x11) +################################################### +# This is the X11 simulator version + +$(OUTPUT): $(OBJS) + $(call PRINTS,LD $(@F))$(CC) $(CFLAGS) $(SHARED_FLAG) $(OBJS) -L$(BUILDDIR) -lplugin $(LINKBITMAPS) -o $@ +ifeq ($(findstring CYGWIN,$(UNAME)),CYGWIN) +# 'x' must be kept or you'll have "Win32 error 5" +# $ fgrep 5 /usr/include/w32api/winerror.h | head -1 +# #define ERROR_ACCESS_DENIED 5L +else + @chmod -x $@ +endif + +else # end of x11-simulator +ifeq ($(SIMVER), sdl) +################################################### +# This is the SDL simulator version + +$(OUTPUT): $(OBJS) + $(call PRINTS,LD $(@F))$(CC) $(CFLAGS) $(SHARED_FLAG) $(OBJS) -L$(BUILDDIR) -lplugin $(LINKBITMAPS) -o $@ +ifeq ($(findstring CYGWIN,$(UNAME)),CYGWIN) +# 'x' must be kept or you'll have "Win32 error 5" +# $ fgrep 5 /usr/include/w32api/winerror.h | head -1 +# #define ERROR_ACCESS_DENIED 5L +else + @chmod -x $@ +endif + +else # end of sdl-simulator +################################################### +# This is the win32 simulator version +DLLTOOLFLAGS = --export-all +DLLWRAPFLAGS = -s --entry _DllMain@12 --target=i386-mingw32 -mno-cygwin + +$(OUTPUT): $(OBJS) + $(call PRINTS,DLL $(@F))$(DLLTOOL) $(DLLTOOLFLAGS) -z $(OBJDIR)/$*.def $(OBJS) + $(SILENT)$(DLLWRAP) $(DLLWRAPFLAGS) --def $(OBJDIR)/$*.def $(OBJS) \ + $(BUILDDIR)/libplugin.a $(BITMAPLIBS) -o $@ +ifeq ($(findstring CYGWIN,$(UNAME)),CYGWIN) +# 'x' must be kept or you'll have "Win32 error 5" +# $ fgrep 5 /usr/include/w32api/winerror.h | head -1 +# #define ERROR_ACCESS_DENIED 5L +else + @chmod -x $@ +endif +endif # end of win32-simulator +endif +endif # end of simulator section + + +include $(TOOLSDIR)/make.inc + +# MEMORYSIZE should be passed on to this makefile with the chosen memory size +# given in number of MB +$(LINKFILE): $(LDS) + $(call PRINTS,build $(@F))cat $< | $(CC) -DMEMORYSIZE=$(MEMORYSIZE) $(INCLUDES) $(TARGET) \ + $(DEFINES) -E -P - >$@ + +clean: + $(call PRINTS,cleaning clock)rm -rf $(OBJDIR)/clock + $(SILENT)rm -f $(OBJDIR)/clock.* $(DEPFILE) + +-include $(DEPFILE) diff --git a/apps/plugins/clock/SOURCES b/apps/plugins/clock/SOURCES new file mode 100644 index 0000000000..28fae83093 --- /dev/null +++ b/apps/plugins/clock/SOURCES @@ -0,0 +1,10 @@ +clock.c +clock_bitmaps.c +clock_bitmap_strings.c +clock_counter.c +clock_draw.c +clock_draw_analog.c +clock_draw_binary.c +clock_draw_digital.c +clock_menu.c +clock_settings.c diff --git a/apps/plugins/clock/clock.c b/apps/plugins/clock/clock.c new file mode 100644 index 0000000000..46d167ba54 --- /dev/null +++ b/apps/plugins/clock/clock.c @@ -0,0 +1,199 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: clock.c 14095 2007-07-31 10:53:53Z nls $ + * + * Copyright (C) 2007 Kévin Ferrare + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "plugin.h" +#include "time.h" +#include "pluginlib_actions.h" +#include "xlcd.h" + +#include "clock.h" +#include "clock_counter.h" +#include "clock_draw.h" +#include "clock_menu.h" +#include "clock_settings.h" + +PLUGIN_HEADER + +/* Keymaps */ +const struct button_mapping* plugin_contexts[]={ + generic_actions, + generic_directions, +#if NB_SCREENS == 2 + remote_directions +#endif +}; +#define NB_ACTION_CONTEXTS sizeof(plugin_contexts)/sizeof(plugin_contexts[0]) +#define ACTION_COUNTER_TOGGLE PLA_FIRE +#define ACTION_COUNTER_RESET PLA_FIRE_REPEAT +#define ACTION_MENU PLA_MENU +#define ACTION_EXIT PLA_QUIT +#define ACTION_MODE_NEXT PLA_RIGHT +#define ACTION_MODE_PREV PLA_LEFT +#define ACTION_SKIN_NEXT PLA_UP +#define ACTION_SKIN_PREV PLA_DOWN + +extern struct plugin_api* rb; + +/************************** + * Cleanup on plugin return + *************************/ +void cleanup(void *parameter) +{ + (void)parameter; + clock_draw_restore_colors(); + if(clock_settings.general.save_settings == 1) + save_settings(); + + /* restore set backlight timeout */ + rb->backlight_set_timeout(rb->global_settings->backlight_timeout); +} + +/* puts the current time into the time struct */ +void clock_update_time( struct time* time){ + struct tm* current_time = rb->get_time(); + time->hour = current_time->tm_hour; + time->minute = current_time->tm_min; + time->second = current_time->tm_sec; + + /********************* + * Date info + *********************/ + time->year = current_time->tm_year + 1900; + time->day = current_time->tm_mday; + time->month = current_time->tm_mon + 1; + +} + +void format_date(char* buffer, struct time* time, enum date_format format){ + switch(format){ + case JAPANESE: + rb->snprintf(buffer, 20, "%04d/%02d/%02d", + time->year, time->month, time->day); + break; + case EUROPEAN: + rb->snprintf(buffer, 20, "%02d/%02d/%04d", + time->day, time->month, time->year); + break; + case ENGLISH: + rb->snprintf(buffer, 20, "%02d/%02d/%04d", + time->month, time->day, time->year); + break; + case NONE: + default: + break; + } +} + +/********************************************************************** + * Plugin starts here + **********************************************************************/ +enum plugin_status plugin_start(struct plugin_api* api, void* parameter){ + int button; + int last_second = -1; + bool redraw=true; + int i; + struct time time; + struct counter counter; + bool exit_clock = false; + (void)parameter; + rb = api; + +#if LCD_DEPTH > 1 + rb->lcd_set_backdrop(NULL); +#endif + + load_settings(); + + /* init xlcd functions */ + xlcd_init(rb); + counter_init(&counter); + clock_draw_set_colors(); + + while(!exit_clock){ + clock_update_time(&time); + + if(!clock_settings.general.idle_poweroff) + rb->reset_poweroff_timer(); + + /************************* + * Scan for button presses + ************************/ + button = pluginlib_getaction(rb, HZ/10, plugin_contexts, NB_ACTION_CONTEXTS); + redraw=true;/* we'll set it to false afterwards if there was no action */ + switch (button){ + case ACTION_COUNTER_TOGGLE: /* start/stop counter */ + if(clock_settings.general.show_counter) + counter_toggle(&counter); + break; + + case ACTION_COUNTER_RESET: /* reset counter */ + if(clock_settings.general.show_counter) + counter_reset(&counter); + break; + + case ACTION_MODE_NEXT: + clock_settings.mode++; + if(clock_settings.mode >= NB_CLOCK_MODES) + clock_settings.mode = 0; + break; + + case ACTION_MODE_PREV: + clock_settings.mode--; + if(clock_settings.mode < 0) + clock_settings.mode = NB_CLOCK_MODES-1; + break; + case ACTION_SKIN_PREV: + clock_settings_skin_next(&clock_settings); + break; + case ACTION_SKIN_NEXT: + clock_settings_skin_previous(&clock_settings); + break; + case ACTION_MENU: + clock_draw_restore_colors(); + exit_clock=main_menu(); + break; + + case ACTION_EXIT: + /*clock_draw_restore_colors(); + exit_clock=main_menu();*/ + exit_clock=true; + break; + + default: + redraw=false; + if(rb->default_event_handler_ex(button, cleanup, NULL) + == SYS_USB_CONNECTED) + return PLUGIN_USB_CONNECTED; + break; + } + if(time.second != last_second){ + last_second=time.second; + redraw=true; + } + if(redraw){ + clock_draw_set_colors(); + FOR_NB_SCREENS(i) + clock_draw(rb->screens[i], &time, &counter); + redraw=false; + } + } + + cleanup(NULL); + return PLUGIN_OK; +} diff --git a/apps/plugins/clock/clock.h b/apps/plugins/clock/clock.h new file mode 100644 index 0000000000..bd5b74fa56 --- /dev/null +++ b/apps/plugins/clock/clock.h @@ -0,0 +1,32 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ + * + * Copyright (C) 2007 Copyright Kévin Ferrare + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#ifndef _CLOCK_ +#define _CLOCK_ +#include "clock_settings.h" +extern struct plugin_api* rb; + +struct time{ + int year, day, month; + int hour, minute, second; +}; + +void format_date(char* buffer, struct time* time, enum date_format format); + +#endif /* _CLOCK_ */ diff --git a/apps/plugins/clock/clock_bitmap_strings.c b/apps/plugins/clock/clock_bitmap_strings.c new file mode 100644 index 0000000000..f2bef78f12 --- /dev/null +++ b/apps/plugins/clock/clock_bitmap_strings.c @@ -0,0 +1,46 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ + * + * Copyright (C) 2007 Copyright Kévin Ferrare + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "clock.h" +#include "clock_bitmap_strings.h" + +void draw_string(struct screen* display, const struct picture* bitmaps, + char* str, int x, int y){ + int i, bitmap_pos; + char c; + for(i=0;(c=str[i]);i++){ + bitmap_pos=-1; + if(c>='0'&&c<='9') + bitmap_pos=c-'0'; + else if(c==':') + bitmap_pos=10; + else if(c=='A' || c=='/')/* 'AM' in digits, '/' in smalldigits */ + bitmap_pos=11; + else if(c=='P' || c=='.')/* 'PM' in digits, '.' in smalldigits */ + bitmap_pos=12; + if(bitmap_pos>=0) + vertical_picture_draw_sprite(display, bitmaps, bitmap_pos, + x+i*bitmaps->width, y); + } +} + +void getstringsize(const struct picture* bitmaps, char* str, int *w, int *h ){ + *h=bitmaps->height; + *w=rb->strlen(str)*bitmaps->width; +} diff --git a/apps/plugins/clock/clock_bitmap_strings.h b/apps/plugins/clock/clock_bitmap_strings.h new file mode 100644 index 0000000000..61f5ac5953 --- /dev/null +++ b/apps/plugins/clock/clock_bitmap_strings.h @@ -0,0 +1,31 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ + * + * Copyright (C) 2007 Copyright Kévin Ferrare + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + + +#ifndef _CLOCK_BITMAP_STRINGS_ +#define _CLOCK_BITMAP_STRINGS_ +#include "plugin.h" +#include "picture.h" + +void draw_string(struct screen* display, const struct picture* bitmaps, + char* str, int x, int y); + +void getstringsize(const struct picture* bitmaps, char* str, int *w, int *h ); + +#endif /* _CLOCK_BITMAP_STRINGS_ */ diff --git a/apps/plugins/clock/clock_bitmaps.c b/apps/plugins/clock/clock_bitmaps.c new file mode 100644 index 0000000000..c8550d180a --- /dev/null +++ b/apps/plugins/clock/clock_bitmaps.c @@ -0,0 +1,105 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ + * + * Copyright (C) 2007 Copyright Kévin Ferrare + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + + +#include "clock_bitmaps.h" + +/* bitmaps */ +#include "clock_binary.h" +#include "clock_digits.h" +#include "clock_smalldigits.h" +#include "clock_segments.h" +#include "clock_smallsegments.h" + +#include "clock_logo.h" +#include "clock_messages.h" + +#if NB_SCREENS==2 +#include "clock_binary_remote.h" +#include "clock_digits_remote.h" +#include "clock_smalldigits_remote.h" +#include "clock_segments_remote.h" +#include "clock_smallsegments_remote.h" + +#include "clock_logo_remote.h" +#include "clock_messages_remote.h" + +#endif + + +const struct picture logos[]={ + {clock_logo, BMPWIDTH_clock_logo, BMPHEIGHT_clock_logo}, +#if NB_SCREENS==2 + {clock_logo_remote,BMPWIDTH_clock_logo_remote,BMPHEIGHT_clock_logo_remote} +#endif +}; + +const struct picture messages[]={ + {clock_messages,BMPWIDTH_clock_messages, + BMPHEIGHT_clock_messages/6}, +#if NB_SCREENS==2 + {clock_messages_remote,BMPWIDTH_clock_messages_remote, + BMPHEIGHT_clock_messages_remote/6} +#endif +}; + +const struct picture binary[]={ + {clock_binary, + BMPWIDTH_clock_binary, BMPHEIGHT_clock_binary/2 }, +#if NB_SCREENS==2 + {clock_binary_remote, + BMPWIDTH_clock_binary_remote,BMPHEIGHT_clock_binary_remote/2} +#endif +}; + +const struct picture digits[]={ + {clock_digits, + BMPWIDTH_clock_digits, BMPHEIGHT_clock_digits/13 }, +#if NB_SCREENS==2 + {clock_digits_remote, + BMPWIDTH_clock_digits_remote,BMPHEIGHT_clock_digits_remote/13} +#endif +}; + +const struct picture smalldigits[]={ + {clock_smalldigits, + BMPWIDTH_clock_smalldigits, BMPHEIGHT_clock_smalldigits/13 }, +#if NB_SCREENS==2 + {clock_smalldigits_remote, + BMPWIDTH_clock_smalldigits_remote,BMPHEIGHT_clock_smalldigits_remote/13} +#endif +}; + +const struct picture segments[]={ + {clock_segments, + BMPWIDTH_clock_segments, BMPHEIGHT_clock_segments/13 }, +#if NB_SCREENS==2 + {clock_segments_remote, + BMPWIDTH_clock_segments_remote,BMPHEIGHT_clock_segments_remote/13} +#endif +}; + +const struct picture smallsegments[]={ + {clock_smallsegments, + BMPWIDTH_clock_smallsegments, BMPHEIGHT_clock_smallsegments/13 }, +#if NB_SCREENS==2 + {clock_smallsegments_remote, + BMPWIDTH_clock_smallsegments_remote,BMPHEIGHT_clock_smallsegments_remote/13} +#endif +}; diff --git a/apps/plugins/clock/clock_bitmaps.h b/apps/plugins/clock/clock_bitmaps.h new file mode 100644 index 0000000000..a3986f3b4f --- /dev/null +++ b/apps/plugins/clock/clock_bitmaps.h @@ -0,0 +1,33 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ + * + * Copyright (C) 2007 Copyright Kévin Ferrare + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#ifndef _CLOCK_BITMAPS_ +#define _CLOCK_BITMAPS_ +#include "picture.h" + +extern const struct picture logos[]; +extern const struct picture messages[]; + +extern const struct picture binary[]; +extern const struct picture digits[]; +extern const struct picture smalldigits[]; +extern const struct picture segments[]; +extern const struct picture smallsegments[]; + +#endif diff --git a/apps/plugins/clock/clock_counter.c b/apps/plugins/clock/clock_counter.c new file mode 100644 index 0000000000..7137eeaf38 --- /dev/null +++ b/apps/plugins/clock/clock_counter.c @@ -0,0 +1,42 @@ +#include "clock_counter.h" +#include "clock_bitmap_strings.h" + +void counter_init(struct counter* counter){ + counter->ticks_since_started=0; + counter->ticks_at_last_unpause=0; + counter->paused=true; +} + +int counter_get_ticks_since_last_pause(struct counter* counter){ + if(!counter->paused) + return(*rb->current_tick - counter->ticks_at_last_unpause); + return(0); +} + +void counter_toggle(struct counter* counter){ + counter_pause(counter, !counter->paused); +} + +void counter_pause(struct counter* counter, bool pause){ + if(pause){ + counter->ticks_since_started+=counter_get_ticks_since_last_pause(counter); + }else{ + counter->ticks_at_last_unpause=*rb->current_tick; + } + counter->paused=pause; +} + +void counter_get_elapsed_time(struct counter* counter, struct time* elapsed_time){ + int total_time=counter_get_ticks_since_last_pause(counter); + total_time+=counter->ticks_since_started; + total_time/=HZ;/* converts ticks to seconds */ + + elapsed_time->second = total_time%60; + elapsed_time->minute = (total_time%3600) / 60; + elapsed_time->hour = total_time / 3600; + /* not yet ! */ + elapsed_time->day=0; + elapsed_time->month=0; + elapsed_time->year=0; +} + diff --git a/apps/plugins/clock/clock_counter.h b/apps/plugins/clock/clock_counter.h new file mode 100644 index 0000000000..25523d45f6 --- /dev/null +++ b/apps/plugins/clock/clock_counter.h @@ -0,0 +1,19 @@ +#ifndef _CLOCK_MESSAGE_ +#define _CLOCK_MESSAGE_ +#include "clock.h" +#include "plugin.h" +#include "picture.h" + +struct counter{ + int ticks_at_last_unpause;/* to count the time from last pause to now */ + int ticks_since_started;/* accumulated time */ + bool paused; +}; + +void counter_init(struct counter* counter); +void counter_toggle(struct counter* counter); +#define counter_reset(counter) counter_init(counter) +void counter_pause(struct counter* counter, bool paused); +void counter_get_elapsed_time(struct counter* counter, struct time* elapsed_time); + +#endif /* _CLOCK_MESSAGE_ */ diff --git a/apps/plugins/clock/clock_draw.c b/apps/plugins/clock/clock_draw.c new file mode 100644 index 0000000000..daf19f7363 --- /dev/null +++ b/apps/plugins/clock/clock_draw.c @@ -0,0 +1,103 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ + * + * Copyright (C) 2007 Copyright Kévin Ferrare + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "clock.h" +#include "clock_draw.h" +#include "clock_draw_digital.h" +#include "clock_draw_analog.h" +#include "clock_draw_binary.h" +#include "clock_settings.h" + +void black_background(struct screen* display){ +#if (LCD_DEPTH > 1) || (defined(LCD_REMOTE_DEPTH) && (LCD_REMOTE_DEPTH > 1)) + if(display->depth>1){ + display->set_background(LCD_BLACK); + display->clear_display(); + }else +#endif + { + display->clear_display(); + display->fillrect(0,0,display->width,display->height); + } +} + +void white_background(struct screen* display){ +#if (LCD_DEPTH > 1) || (defined(LCD_REMOTE_DEPTH) && (LCD_REMOTE_DEPTH > 1)) + if(display->depth>1){ +#if defined(HAVE_LCD_COLOR) + if(display->is_color)/* restore to the bitmap's background */ + display->set_background(LCD_RGBPACK(180,200,230)); + else +#endif + display->set_background(LCD_WHITE); + } +#endif + display->clear_display(); +} + +bool skin_require_black_background(int mode, int skin){ + return((mode==BINARY && skin==2) || (mode==DIGITAL && skin==1 )); +} + +void skin_set_background(struct screen* display, int mode, int skin){ + if(skin_require_black_background(mode, skin) ) + black_background(display); + else + white_background(display); +} + +void skin_restore_background(struct screen* display, int mode, int skin){ + if(skin_require_black_background(mode, skin) ) + white_background(display); +} + +void clock_draw_set_colors(void){ + int i; + FOR_NB_SCREENS(i) + skin_set_background(rb->screens[i], + clock_settings.mode, + clock_settings.skin[clock_settings.mode]); +} + +void clock_draw_restore_colors(void){ + int i; + FOR_NB_SCREENS(i){ + skin_restore_background(rb->screens[i], + clock_settings.mode, + clock_settings.skin[clock_settings.mode]); + rb->screens[i]->update(); + } +} + +void clock_draw(struct screen* display, struct time* time, + struct counter* counter){ + if(!clock_settings.general.show_counter) + counter=0; + int skin=clock_settings.skin[clock_settings.mode]; + skin_set_background(display, clock_settings.mode, skin); + if(clock_settings.mode == ANALOG) + analog_clock_draw(display, time, &clock_settings, counter, skin); + + else if(clock_settings.mode == DIGITAL) + digital_clock_draw(display, time, &clock_settings, counter, skin); + + else if(clock_settings.mode == BINARY) + binary_clock_draw(display, time, skin); + display->update(); +} diff --git a/apps/plugins/clock/clock_draw.h b/apps/plugins/clock/clock_draw.h new file mode 100644 index 0000000000..b589b7ee0e --- /dev/null +++ b/apps/plugins/clock/clock_draw.h @@ -0,0 +1,32 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ + * + * Copyright (C) 2007 Copyright Kévin Ferrare + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#ifndef _CLOCK_DRAW_ +#define _CLOCK_DRAW_ +#include "plugin.h" +#include "clock.h" +#include "clock_counter.h" + +void clock_draw_set_colors(void); +void clock_draw_restore_colors(void); + +void clock_draw(struct screen* display, struct time* time, + struct counter* counter); + +#endif /* _CLOCK_DRAW_ */ diff --git a/apps/plugins/clock/clock_draw_analog.c b/apps/plugins/clock/clock_draw_analog.c new file mode 100644 index 0000000000..1fd98773f2 --- /dev/null +++ b/apps/plugins/clock/clock_draw_analog.c @@ -0,0 +1,217 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ + * + * Copyright (C) 2007 Copyright Kévin Ferrare based on Zakk Roberts's work + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "clock_draw_analog.h" +#include "xlcd.h" +#include "fixedpoint.h" +#include "clock_bitmaps.h" +#include "clock_bitmap_strings.h" + +#define ANALOG_SECOND_RADIUS(screen, round) \ + ANALOG_MINUTE_RADIUS(screen, round) +#define ANALOG_MINUTE_RADIUS(screen, round) \ + (round?MIN(screen->height/2 -10, screen->width/2 -10):screen->height/2) +#define ANALOG_HOUR_RADIUS(screen, round) \ + (ANALOG_MINUTE_RADIUS(screen, round)/2) + +#define HOUR_ANGLE(hour, minute, second) (30*(hour) +(minute)/2) +#define MINUTE_ANGLE(minute, second) (6*(minute)+(second)/10) +#define SECOND_ANGLE(second) (6 * (second)) + +void polar_to_cartesian(int a, int r, int* x, int* y){ + *x = (sin_int(a) * r) >> 14; + *y = (sin_int(a-90) * r) >> 14; +} + +void polar_to_cartesian_screen_centered(struct screen * display, + int a, int r, int* x, int* y){ + polar_to_cartesian(a, r, x, y); + *x+=display->width/2; + *y+=display->height/2; +} + +void angle_to_square(int square_width, int square_height, + int a, int* x, int* y){ + a = (a+360-90)%360; + if(a>45 && a<=135){/* top line */ + a-=45; + *x=square_width-(square_width*2*a)/90; + *y=square_height; + }else if(a>135 && a<=225){/* left line */ + a-=135; + *x=-square_width; + *y=square_height-(square_height*2*a)/90; + }else if(a>225 && a<=315){/* bottom line */ + a-=225; + *x=(square_width*2*a)/90-square_width; + *y=-square_height; + }else if(a>315 || a<=45){/* right line */ + if(a>315) + a-=315; + else + a+=45; + *x=square_width; + *y=(square_height*2*a)/90-square_height; + } +} + +void angle_to_square_screen_centered(struct screen * display, + int square_width, int square_height, + int a, int* x, int* y){ + angle_to_square(square_width, square_height, a, x, y); + *x+=display->width/2; + *y+=display->height/2; +} + +void draw_hand(struct screen* display, int angle, + int radius, int thickness, bool round){ + int x1, y1; /* the longest */ + int x2, y2, x3, y3; /* the base */ + if(round){/* round clock */ + polar_to_cartesian_screen_centered(display, angle, + radius, &x1, &y1); + }else{/* fullscreen clock, hands describes square motions */ + int square_width, square_height; + /* radius is defined smallest between width and height */ + square_height=radius; + square_width=(radius*display->width)/display->height; + angle_to_square_screen_centered( + display, square_width, square_height, angle, &x1, &y1); + } + polar_to_cartesian_screen_centered(display, (angle+120)%360, + radius/40+thickness, &x2, &y2); + polar_to_cartesian_screen_centered(display, (angle+240)%360, + radius/40+thickness, &x3, &y3); + xlcd_filltriangle_screen(display, x1, y1, x2, y2, x3, y3); +} + +void draw_hands(struct screen* display, int hour, int minute, int second, + int thickness, bool round, bool draw_seconds){ + if(draw_seconds){ + draw_hand(display, SECOND_ANGLE(second), + ANALOG_SECOND_RADIUS(display, round), thickness, round); + } + draw_hand(display, MINUTE_ANGLE(minute, second), + ANALOG_MINUTE_RADIUS(display, round), thickness+2, round); + draw_hand(display, HOUR_ANGLE(hour, minute, second), + ANALOG_HOUR_RADIUS(display, round), thickness+2, round); +} + +/******************* + * Analog clock mode + ******************/ +void analog_clock_draw(struct screen* display, struct time* time, + struct clock_settings* settings, + struct counter* counter, + int skin){ + int i; + const struct picture* smalldigits_bitmaps = + &(smalldigits[display->screen_type]); + int hour=time->hour; + if(hour >= 12) + hour -= 12; + + /* show_date */ + /* show_digital_time*/ + + /* Crappy fake antialiasing (color LCDs only)! + * how this works is we draw a large mid-gray hr/min/sec hand, + * then the actual (slightly smaller) hand on top of those. + * End result: mid-gray edges to the black hands, smooths them out. */ +#ifdef HAVE_LCD_COLOR + if(display->is_color){ + display->set_foreground(LCD_RGBPACK(100,110,125)); + draw_hands(display, hour, time->minute, time->second, 2, + skin, settings->analog.show_seconds); + display->set_foreground(LCD_BLACK); + } +#endif + draw_hands(display, hour, time->minute, time->second, 0, skin, + settings->analog.show_seconds); + + if(settings->analog.show_border){ + /* Draws square dots every 5 minutes */ + int x, y; + int size=display->height/50;/* size of the square dots */ + if(size%2)/* a pair number */ + size++; + for(i=0; i < 60; i+=5){ + if(skin){ + polar_to_cartesian_screen_centered(display, MINUTE_ANGLE(i, 0), + ANALOG_MINUTE_RADIUS(display, skin), &x, &y); + }else{ + angle_to_square_screen_centered( + display, display->width/2-size/2, display->height/2-size/2, + MINUTE_ANGLE(i, 0), &x, &y); + } + display->fillrect(x-size/2, y-size/2, size, size); + } + } + + if(counter){ + char buffer[10]; + int second_str_w, hour_str_w, str_h; + struct time counter_time; + counter_get_elapsed_time(counter, &counter_time); + rb->snprintf(buffer, 10, "%02d:%02d", + counter_time.hour, counter_time.minute); + getstringsize(smalldigits_bitmaps, buffer, &hour_str_w, &str_h); + draw_string(display, smalldigits_bitmaps, buffer, + display->width-hour_str_w, + display->height-2*str_h); + + rb->snprintf(buffer, 10, "%02d", counter_time.second); + getstringsize(smalldigits_bitmaps, buffer, &second_str_w, &str_h); + draw_string(display, smalldigits_bitmaps, buffer, + display->width-(hour_str_w+second_str_w)/2, + display->height-str_h); + } + if(settings->analog.show_date && settings->general.date_format!=NONE){ + char buffer[10]; + int year_str_w, monthday_str_w, str_h; + if(settings->general.date_format==ENGLISH){ + rb->snprintf(buffer, 10, "%02d/%02d", time->month, time->day); + }else{ + rb->snprintf(buffer, 10, "%02d/%02d", time->day, time->month); + } + getstringsize(smalldigits_bitmaps, buffer, &monthday_str_w, &str_h); + draw_string(display, smalldigits_bitmaps, buffer, + 0, display->height-2*str_h); + rb->snprintf(buffer, 10, "%04d", time->year); + getstringsize(smalldigits_bitmaps, buffer, &year_str_w, &str_h); + draw_string(display, smalldigits_bitmaps, buffer, + (monthday_str_w-year_str_w)/2, display->height-str_h); + } + + /* Draw the cover over the center */ + display->drawline((display->width/2)-1, (display->height/2)+3, + (display->width/2)+1, (display->height/2)+3); + display->drawline((display->width/2)-3, (display->height/2)+2, + (display->width/2)+3, (display->height/2)+2); + display->drawline((display->width/2)-4, (display->height/2)+1, + (display->width/2)+4, (display->height/2)+1); + display->drawline((display->width/2)-4, display->height/2, + (display->width/2)+4, display->height/2); + display->drawline((display->width/2)-4, (display->height/2)-1, + (display->width/2)+4, (display->height/2)-1); + display->drawline((display->width/2)-3, (display->height/2)-2, + (display->width/2)+3, (display->height/2)-2); + display->drawline((display->width/2)-1, (display->height/2)-3, + (display->width/2)+1, (display->height/2)-3); +} diff --git a/apps/plugins/clock/clock_draw_analog.h b/apps/plugins/clock/clock_draw_analog.h new file mode 100644 index 0000000000..4b8f3f8432 --- /dev/null +++ b/apps/plugins/clock/clock_draw_analog.h @@ -0,0 +1,32 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ + * + * Copyright (C) 2007 Copyright Kévin Ferrare + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#ifndef _ANALOG_CLOCK_ +#define _ANALOG_CLOCK_ +#include "plugin.h" +#include "clock.h" +#include "clock_counter.h" +#include "clock_settings.h" + +void analog_clock_draw(struct screen* display, struct time* time, + struct clock_settings* settings, + struct counter* counter, + int skin); + +#endif /* _ANALOG_CLOCK_ */ diff --git a/apps/plugins/clock/clock_draw_binary.c b/apps/plugins/clock/clock_draw_binary.c new file mode 100644 index 0000000000..5bc84f1583 --- /dev/null +++ b/apps/plugins/clock/clock_draw_binary.c @@ -0,0 +1,51 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ + * + * Copyright (C) 2007 Copyright Kévin Ferrare + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include "clock_draw_binary.h" +#include "clock_bitmap_strings.h" +#include "clock_bitmaps.h" +#include "picture.h" + +const struct picture* binary_skin[]={binary,digits,segments}; + +void print_binary(char* buffer, int number, int nb_bits){ + int i; + int mask=1; + buffer[nb_bits]='\0'; + for(i=0; ihour,time->minute,time->second + }; + char buffer[9]; + int i; + const struct picture* binary_bitmaps = &(binary_skin[skin][display->screen_type]); + for(i=0;i<3;i++){ + print_binary(buffer, lines_values[i], 6); + draw_string(display, binary_bitmaps, buffer, 0, + binary_bitmaps->height*i); + } +} diff --git a/apps/plugins/clock/clock_draw_binary.h b/apps/plugins/clock/clock_draw_binary.h new file mode 100644 index 0000000000..323a640442 --- /dev/null +++ b/apps/plugins/clock/clock_draw_binary.h @@ -0,0 +1,27 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ + * + * Copyright (C) 2007 Copyright Kévin Ferrare + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#ifndef _BINARY_CLOCK_ +#define _BINARY_CLOCK_ +#include "plugin.h" +#include "clock.h" + +void binary_clock_draw(struct screen* display, struct time* time, int skin); + +#endif /* _BINARY_CLOCK_ */ diff --git a/apps/plugins/clock/clock_draw_digital.c b/apps/plugins/clock/clock_draw_digital.c new file mode 100644 index 0000000000..9fff47c520 --- /dev/null +++ b/apps/plugins/clock/clock_draw_digital.c @@ -0,0 +1,87 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ + * + * Copyright (C) 2007 Copyright Kévin Ferrare + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "clock.h" +#include "clock_draw_digital.h" +#include "clock_bitmap_strings.h" +#include "clock_bitmaps.h" +#include "picture.h" + +const struct picture* digits_skin[]={digits,segments}; +const struct picture* smalldigits_skin[]={smalldigits,smallsegments}; + +#define buffer_printf(buffer, buffer_pos, ... ) \ + buffer_pos+=rb->snprintf(&buffer[buffer_pos], sizeof(buffer)-buffer_pos, __VA_ARGS__); + +void digital_clock_draw(struct screen* display, + struct time* time, + struct clock_settings* settings, + struct counter* counter, + int skin){ + bool display_colon; + const struct picture* digits_bitmaps = &(digits_skin[skin][display->screen_type]); + const struct picture* smalldigits_bitmaps = &(smalldigits_skin[skin][display->screen_type]); + int hour=time->hour; + int str_w, str_h; + char buffer[20]; + int buffer_pos=0; + + if(settings->digital.blinkcolon){ + display_colon=(time->second%2==0); + } + else + display_colon=true; + + if(settings->general.hour_format==H12){/* AM/PM format */ + if(hour>12){ + buffer_printf(buffer, buffer_pos, "P");/* AM */ + /* readjust the hour to 12-hour format + * ( 13:00+ -> 1:00+ ) */ + hour -= 12; + }else + buffer_printf(buffer, buffer_pos, "A");/* AM */ + } + buffer_printf(buffer, buffer_pos, "%02d", hour); + buffer_printf(buffer, buffer_pos, "%c", display_colon?':':' '); + buffer_printf(buffer, buffer_pos, "%02d", time->minute); + getstringsize(digits_bitmaps, buffer, &str_w, &str_h); + draw_string(display, digits_bitmaps, buffer, (display->width-str_w)/2, 0); + if(settings->digital.show_seconds){ + buffer_pos=0; + buffer_printf(buffer, buffer_pos, "%02d", time->second); + getstringsize(digits_bitmaps, buffer, &str_w, &str_h); + draw_string(display, digits_bitmaps, buffer, (display->width-str_w)/2, + digits_bitmaps->height); + } + if(settings->general.date_format!=NONE){ + format_date(buffer, time, settings->general.date_format); + getstringsize(smalldigits_bitmaps, buffer, &str_w, &str_h); + draw_string(display, smalldigits_bitmaps, buffer, (display->width-str_w)/2, + display->height-smalldigits_bitmaps->height*2); + } + if(counter){ + struct time counter_time; + counter_get_elapsed_time(counter, &counter_time); + rb->snprintf(buffer, 20, "%02d:%02d:%02d", + counter_time.hour, counter_time.minute, counter_time.second); + getstringsize(smalldigits_bitmaps, buffer, &str_w, &str_h); + draw_string(display, smalldigits_bitmaps, buffer, (display->width-str_w)/2, + display->height-str_h); + } +} diff --git a/apps/plugins/clock/clock_draw_digital.h b/apps/plugins/clock/clock_draw_digital.h new file mode 100644 index 0000000000..b967e67571 --- /dev/null +++ b/apps/plugins/clock/clock_draw_digital.h @@ -0,0 +1,31 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ + * + * Copyright (C) 2007 Copyright Kévin Ferrare + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#ifndef _DIGITAL_CLOCK_ +#define _DIGITAL_CLOCK_ +#include "plugin.h" +#include "clock.h" +#include "clock_counter.h" +#include "clock_settings.h" + +void digital_clock_draw(struct screen* display, struct time* time, + struct clock_settings* settings, + struct counter* counter, int skin); + +#endif /* _DIGITAL_CLOCK_ */ diff --git a/apps/plugins/clock/clock_menu.c b/apps/plugins/clock/clock_menu.c new file mode 100644 index 0000000000..3310dbf929 --- /dev/null +++ b/apps/plugins/clock/clock_menu.c @@ -0,0 +1,246 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ + * + * Copyright (C) 2003 Zakk Roberts + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "clock.h" +#include "clock_bitmaps.h" +#include "clock_settings.h" + +/* Option structs (possible selections per each option) */ +static const struct opt_items noyes_text[] = { + { "No", -1 }, + { "Yes", -1 } +}; + +static const struct opt_items backlight_settings_text[] = { + { "Always Off", -1 }, + { "Rockbox setting", -1 }, + { "Always On", -1 } +}; + +static const struct opt_items idle_poweroff_text[] = { + { "Disabled", -1 }, + { "Enabled", -1 } +}; + +static const struct opt_items date_format_text[] = { + { "No date", -1 }, + { "English format", -1 }, + { "European format", -1 }, + { "Japanese format", -1 }, +}; + +static const struct opt_items hour_format_text[] = { + { "24-hour Format", -1 }, + { "12-hour Format", -1 } +}; + +/*************** + * Select a mode, returs true when the mode has been selected + * (we go back to clock display then) + **************/ +bool menu_mode_selector(void){ + MENUITEM_STRINGLIST(menu,"Mode Selector",NULL, "Analog", + "Digital", "Binary"); + if(rb->do_menu(&menu, &clock_settings.mode) >=0) + return(true); + return(false); +} + +/********************** + * Analog settings menu + *********************/ +void menu_analog_settings(void) +{ + int selection=0, result=0; + + MENUITEM_STRINGLIST(menu,"Analog Mode Settings",NULL,"Show Date", + "Show Second Hand","Show Border"); + + while(result>=0){ + result=rb->do_menu(&menu, &selection); + switch(result){ + case 0: + rb->set_option("Show Date", &clock_settings.analog.show_date, + BOOL, noyes_text, 2, NULL); + break; + case 1: + rb->set_option("Show Second Hand", + &clock_settings.analog.show_seconds, + BOOL, noyes_text, 2, NULL); + break; + case 2: + rb->set_option("Show Border", + &clock_settings.analog.show_border, + BOOL, noyes_text, 2, NULL); + break; + } + } +} + +/*********************** + * Digital settings menu + **********************/ +void menu_digital_settings(void){ + int selection=0, result=0; + + MENUITEM_STRINGLIST(menu,"Digital Mode Settings",NULL,"Show Seconds", + "Blinking Colon"); + + while(result>=0){ + result=rb->do_menu(&menu, &selection); + switch(result){ + case 0: + rb->set_option("Show Seconds", + &clock_settings.digital.show_seconds, + BOOL, noyes_text, 2, NULL); + break; + case 1: + rb->set_option("Blinking Colon", + &clock_settings.digital.blinkcolon, + BOOL, noyes_text, 2, NULL); + break; + } + } +} + +/*********************************************************** + * Confirm resetting of settings, used in general_settings() + **********************************************************/ +void confirm_reset(void){ + int result=0; + + rb->set_option("Reset all settings?", &result, INT, noyes_text, 2, NULL); + + if(result == 1){ /* reset! */ + clock_settings_reset(&clock_settings); + rb->splash(HZ, "Settings reset!"); + } + else + rb->splash(HZ, "Settings NOT reset."); +} + +/************************************ + * General settings. Reset, save, etc + ***********************************/ +void menu_general_settings(void){ + int selection=0, result=0; + + MENUITEM_STRINGLIST(menu,"General Settings",NULL, + "Hour format","Date format","Show Counter", + "Reset Settings","Save Settings Now", + "Save On Exit","Backlight Settings", + "Idle Poweroff (temporary)"); + + while(result>=0){ + result=rb->do_menu(&menu, &selection); + switch(result){ + case 0: + rb->set_option("Hour format", + &clock_settings.general.hour_format, + INT, hour_format_text, 2, NULL); + break; + case 1: + rb->set_option("Date format", + &clock_settings.general.date_format, + INT, date_format_text, 4, NULL); + break; + case 2: + rb->set_option("Show Counter", &clock_settings.general.show_counter, + BOOL, noyes_text, 2, NULL); + break; + case 3: + confirm_reset(); + break; + + case 4: + save_settings_wo_gui(); + rb->splash(HZ, "Settings saved"); + break; + + case 5: + rb->set_option("Save On Exit", + &clock_settings.general.save_settings, + BOOL, noyes_text, 2, NULL); + + /* if we no longer save on exit, + we better save now to remember that */ + if(!clock_settings.general.save_settings) + save_settings_wo_gui(); + break; + case 6: + rb->set_option("Backlight Settings", + &clock_settings.general.backlight, + INT, backlight_settings_text, 3, NULL); + apply_backlight_setting(clock_settings.general.backlight); + break; + + case 7: + rb->set_option("Idle Poweroff (temporary)", + &clock_settings.general.idle_poweroff, + BOOL, idle_poweroff_text, 2, NULL); + break; + } + } +} + +/*********** + * Main menu + **********/ +bool main_menu(void){ + int selection=0; + bool done = false; + bool exit_clock=false; + + MENUITEM_STRINGLIST(menu,"Clock Menu",NULL,"View Clock","Mode Selector", + "Mode Settings","General Settings","Quit"); + + while(!done){ + switch(rb->do_menu(&menu, &selection)){ + case 0: + done = true; + break; + + case 1: + done=menu_mode_selector(); + break; + + case 2: + switch(clock_settings.mode){ + case ANALOG: menu_analog_settings();break; + case DIGITAL: menu_digital_settings();break; + case BINARY: /* no settings */;break; + } + break; + + case 3: + menu_general_settings(); + break; + + case 4: + exit_clock = true; + done = true; + break; + + default: + done=true; + break; + } + } + return(exit_clock); +} diff --git a/apps/plugins/clock/clock_menu.h b/apps/plugins/clock/clock_menu.h new file mode 100644 index 0000000000..c02a42ce2a --- /dev/null +++ b/apps/plugins/clock/clock_menu.h @@ -0,0 +1,7 @@ + +#ifndef _CLOCK_MENU_ +#define _CLOCK_MENU_ + +bool main_menu(void); + +#endif /* _CLOCK_MENU_ */ diff --git a/apps/plugins/clock/clock_settings.c b/apps/plugins/clock/clock_settings.c new file mode 100644 index 0000000000..9bd7c90d3b --- /dev/null +++ b/apps/plugins/clock/clock_settings.c @@ -0,0 +1,200 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ + * + * Copyright (C) 2007 Copyright Kévin Ferrare based on Zakk Roberts's work + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "clock.h" +#include "clock_bitmaps.h" +#include "clock_draw.h" +#include "clock_settings.h" +#include "picture.h" + +static int max_skin[]={ + [ANALOG]=2, + [BINARY]=3, + [DIGITAL]=2, +}; + +enum message{ + MESSAGE_LOADING, + MESSAGE_LOADED, + MESSAGE_ERRLOAD, + MESSAGE_SAVING, + MESSAGE_SAVED, + MESSAGE_ERRSAVE +}; + +enum settings_file_status{ + LOADED, ERRLOAD, + SAVED, ERRSAVE +}; + +struct clock_settings clock_settings; + +void clock_settings_reset(struct clock_settings* settings){ + settings->mode = ANALOG; + int i; + for(i=0;iskin[i]=0; + } + settings->general.hour_format = H12; + settings->general.date_format = EUROPEAN; + settings->general.show_counter = true; + settings->general.save_settings = true; + settings->general.idle_poweroff=true; + settings->general.backlight = ROCKBOX_SETTING; + + settings->analog.show_date = false; + settings->analog.show_seconds = true; + settings->analog.show_border = true; + + settings->digital.show_seconds = true; + settings->digital.blinkcolon = false; + apply_backlight_setting(settings->general.backlight); +} + +void apply_backlight_setting(int backlight_setting) +{ + if(backlight_setting == ALWAS_OFF) + rb->backlight_set_timeout(0); + else if(backlight_setting == ROCKBOX_SETTING) + rb->backlight_set_timeout(rb->global_settings->backlight_timeout); + else if(backlight_setting == ALWAYS_ON) + rb->backlight_set_timeout(1); +} + +void clock_settings_skin_next(struct clock_settings* settings){ + settings->skin[settings->mode]++; + if(settings->skin[settings->mode]>=max_skin[settings->mode]) + settings->skin[settings->mode]=0; +} + +void clock_settings_skin_previous(struct clock_settings* settings){ + settings->skin[settings->mode]--; + if(settings->skin[settings->mode]<0) + settings->skin[settings->mode]=max_skin[settings->mode]-1; +} + +enum settings_file_status clock_settings_load(struct clock_settings* settings, + char* filename){ + int fd = rb->open(filename, O_RDONLY); + if(fd >= 0){ /* does file exist? */ + /* basic consistency check */ + if(rb->filesize(fd) == sizeof(*settings)){ + rb->read(fd, settings, sizeof(*settings)); + rb->close(fd); + apply_backlight_setting(settings->general.backlight); + return(LOADED); + } + } + /* Initializes the settings with default values at least */ + clock_settings_reset(settings); + return(ERRLOAD); +} + +enum settings_file_status clock_settings_save(struct clock_settings* settings, + char* filename){ + int fd = rb->creat(filename); + if(fd >= 0){ /* does file exist? */ + rb->write (fd, settings, sizeof(*settings)); + rb->close(fd); + return(SAVED); + } + return(ERRSAVE); +} + +void draw_logo(struct screen* display){ +#ifdef HAVE_LCD_COLOR + if(display->is_color){ + display->set_foreground(LCD_BLACK); + display->set_background(LCD_RGBPACK(180,200,230)); + } +#endif + + const struct picture* logo = &(logos[display->screen_type]); + display->clear_display(); + picture_draw(display, logo, 0, 0); +} + +void draw_message(struct screen* display, int msg, int y){ + const struct picture* message = &(messages[display->screen_type]); + display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); + display->fillrect(0, display->height-message->height, + display->width, message->height); + display->set_drawmode(DRMODE_SOLID); + vertical_picture_draw_sprite(display, message, msg, + 0, display->height-(message->height*y)); +} + +void load_settings(void){ + int i; + struct screen* display; + FOR_NB_SCREENS(i){ + display=rb->screens[i]; + display->clear_display(); + draw_logo(display); + draw_message(display, MESSAGE_LOADING, 1); + display->update(); + } + + enum settings_file_status load_status= + clock_settings_load(&clock_settings, settings_filename); + + FOR_NB_SCREENS(i){ + display=rb->screens[i]; + if(load_status==LOADED) + draw_message(display, MESSAGE_LOADED, 1); + else + draw_message(display, MESSAGE_ERRLOAD, 1); + display->update(); + } +#ifndef SIMULATOR + rb->ata_sleep(); +#endif + rb->sleep(HZ); +} + +void save_settings(void){ + int i; + struct screen* display; + FOR_NB_SCREENS(i){ + display=rb->screens[i]; + display->clear_display(); + draw_logo(display); + + draw_message(display, MESSAGE_SAVING, 1); + + display->update(); + } + enum settings_file_status load_status= + clock_settings_save(&clock_settings, settings_filename); + + FOR_NB_SCREENS(i){ + display=rb->screens[i]; + + if(load_status==SAVED) + draw_message(display, MESSAGE_SAVED, 1); + else + draw_message(display, MESSAGE_ERRSAVE, 1); + display->update(); + } + rb->sleep(HZ); +} + +void save_settings_wo_gui(void){ + clock_settings_save(&clock_settings, settings_filename); +} diff --git a/apps/plugins/clock/clock_settings.h b/apps/plugins/clock/clock_settings.h new file mode 100644 index 0000000000..fadf3d5e63 --- /dev/null +++ b/apps/plugins/clock/clock_settings.h @@ -0,0 +1,91 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ + * + * Copyright (C) 2007 Copyright Kévin Ferrare based on Zakk Roberts's work + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#ifndef _CLOCK_SETTINGS_ +#define _CLOCK_SETTINGS_ +#include "plugin.h" + +enum date_format{ + NONE, + ENGLISH, + EUROPEAN, + JAPANESE, +}; + +enum hour_format{ + H24, + H12 +}; + +enum clock_modes{ + ANALOG, + DIGITAL, + BINARY, + NB_CLOCK_MODES +}; + +enum backlight_handling{ + ALWAS_OFF, + ROCKBOX_SETTING, + ALWAYS_ON +}; + + +struct general_settings{ + int hour_format;/* 0:24h, 1:12h*/ + int date_format; + bool show_counter; + bool save_settings; + bool idle_poweroff; + int backlight; +}; + +struct analog_settings{ + bool show_date; + bool show_seconds; + bool show_border; +}; + +struct digital_settings{ + int show_seconds; + int blinkcolon; +}; + +struct clock_settings{ + int mode; /* clock mode */ + int skin[NB_CLOCK_MODES];/* how does each mode looks like */ + struct general_settings general; + struct analog_settings analog; + struct digital_settings digital; +}; + +extern struct clock_settings clock_settings; + +/* settings are saved to this location */ +#define settings_filename "/.rockbox/rocks/.clock_settings" + +void clock_settings_skin_next(struct clock_settings* settings); +void clock_settings_skin_previous(struct clock_settings* settings); +void apply_backlight_setting(int backlight_setting); +void clock_settings_reset(struct clock_settings* settings); +void load_settings(void); +void save_settings(void); +void save_settings_wo_gui(void); + +#endif /* _CLOCK_SETTINGS_ */ diff --git a/apps/plugins/lib/SOURCES b/apps/plugins/lib/SOURCES index 03a990acda..88d362a670 100644 --- a/apps/plugins/lib/SOURCES +++ b/apps/plugins/lib/SOURCES @@ -21,6 +21,7 @@ profile_plugin.c #endif #ifdef HAVE_LCD_BITMAP checkbox.c +picture.c xlcd_core.c xlcd_draw.c xlcd_scroll.c diff --git a/apps/plugins/lib/picture.c b/apps/plugins/lib/picture.c new file mode 100644 index 0000000000..f214dfcdfd --- /dev/null +++ b/apps/plugins/lib/picture.c @@ -0,0 +1,70 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ + * + * Copyright (C) 2007 Copyright Kévin Ferrare + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "picture.h" + +void picture_draw(struct screen* display, const struct picture* picture, + int x, int y){ + display->bitmap( + picture->data, + x, y, + picture->width, picture->height + ); +} + +/** + * Draws a part of the given picture on the given screen + * Use it when the data contains multiple pictures from top to bottom. + * In that case, picture.height represents the height of one picture, + * not the whole set. + * @param display the screen where to display the picture + * @param picture the picture's data, only a part will be displayed + * @param yoffset display the data in the picture from yoffset to + * yoffset+picture.height + * @param x abscissa where to put the picture + * @param y ordinate where to put the picture + */ +void vertical_picture_draw_part(struct screen* display, const struct picture* picture, + int yoffset, + int x, int y){ + display->bitmap_part( + picture->data, + /*slice into picture->data */ + 0, yoffset, + picture->width, + /* Position on the screen */ + x, y, picture->width, picture->height + ); +} + +/** + * Draws a part of the given picture on the given screen + * Use it when the data contains multiple pictures from top to bottom. + * + * @param display the screen where to display the picture + * @param picture the picture's data, only a part will be displayed + * @param sprite_no display that sprite in the picture + * @param x abscissa where to put the picture + * @param y ordinate where to put the picture + */ +void vertical_picture_draw_sprite(struct screen* display, const struct picture* picture, + int sprite_no, + int x, int y){ + vertical_picture_draw_part(display, picture, sprite_no*picture->height, x, y); +} diff --git a/apps/plugins/lib/picture.h b/apps/plugins/lib/picture.h new file mode 100644 index 0000000000..4bd550a2f3 --- /dev/null +++ b/apps/plugins/lib/picture.h @@ -0,0 +1,40 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ + * + * Copyright (C) 2007 Copyright Kévin Ferrare + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#ifndef _PICTURE_ +#define _PICTURE_ +#include "plugin.h" + +struct picture{ + const void* data; + int width; + int height; +}; + +void picture_draw(struct screen* display, const struct picture* picture, + int x, int y); + +void vertical_picture_draw_part(struct screen* display, const struct picture* picture, + int yoffset, + int x, int y); + +void vertical_picture_draw_sprite(struct screen* display, const struct picture* picture, + int sprite_no, + int x, int y); +#endif diff --git a/apps/plugins/lib/xlcd.h b/apps/plugins/lib/xlcd.h index 473c51c732..59a048228b 100644 --- a/apps/plugins/lib/xlcd.h +++ b/apps/plugins/lib/xlcd.h @@ -28,7 +28,8 @@ void xlcd_init(struct plugin_api* newrb); void xlcd_filltriangle(int x1, int y1, int x2, int y2, int x3, int y3); - +void xlcd_filltriangle_screen(struct screen* display, + int x1, int y1, int x2, int y2, int x3, int y3); #if LCD_DEPTH >= 8 void xlcd_gray_bitmap_part(const unsigned char *src, int src_x, int src_y, int stride, int x, int y, int width, int height); diff --git a/apps/plugins/lib/xlcd_draw.c b/apps/plugins/lib/xlcd_draw.c index 3ccdea9139..accf3b4f4b 100644 --- a/apps/plugins/lib/xlcd_draw.c +++ b/apps/plugins/lib/xlcd_draw.c @@ -25,46 +25,58 @@ #ifdef HAVE_LCD_BITMAP #include "xlcd.h" -#if (LCD_DEPTH >= 8) || (LCD_PIXELFORMAT == HORIZONTAL_PACKING) -/* draw a filled triangle, using horizontal lines for speed */ -void xlcd_filltriangle(int x1, int y1, int x2, int y2, int x3, int y3) +/* sort the given coordinates by increasing x value */ +void sort_points_by_increasing_x(int* x1, int* y1, + int* x2, int* y2, + int* x3, int* y3) { int x, y; - long fp_x1, fp_x2, fp_dx1, fp_dx2; - - /* sort vertices by increasing y value */ - if (y1 > y3) + if (*x1 > *x3) { - if (y2 < y3) /* y2 < y3 < y1 */ + if (*x2 < *x3) /* x2 < x3 < x1 */ { - x = x1; x1 = x2; x2 = x3; x3 = x; - y = y1; y1 = y2; y2 = y3; y3 = y; + x = *x1; *x1 = *x2; *x2 = *x3; *x3 = x; + y = *y1; *y1 = *y2; *y2 = *y3; *y3 = y; } - else if (y2 > y1) /* y3 < y1 < y2 */ + else if (*x2 > *x1) /* x3 < x1 < x2 */ { - x = x1; x1 = x3; x3 = x2; x2 = x; - y = y1; y1 = y3; y3 = y2; y2 = y; + x = *x1; *x1 = *x3; *x3 = *x2; *x2 = x; + y = *y1; *y1 = *y3; *y3 = *y2; *y2 = y; } - else /* y3 <= y2 <= y1 */ + else /* x3 <= x2 <= x1 */ { - x = x1; x1 = x3; x3 = x; - y = y1; y1 = y3; y3 = y; + x = *x1; *x1 = *x3; *x3 = x; + y = *y1; *y1 = *y3; *y3 = y; } } else { - if (y2 < y1) /* y2 < y1 <= y3 */ + if (*x2 < *x1) /* x2 < x1 <= x3 */ { - x = x1; x1 = x2; x2 = x; - y = y1; y1 = y2; y2 = y; + x = *x1; *x1 = *x2; *x2 = x; + y = *y1; *y1 = *y2; *y2 = y; } - else if (y2 > y3) /* y1 <= y3 < y2 */ + else if (*x2 > *x3) /* x1 <= x3 < x2 */ { - x = x2; x2 = x3; x3 = x; - y = y2; y2 = y3; y3 = y; + x = *x2; *x2 = *x3; *x3 = x; + y = *y2; *y2 = *y3; *y3 = y; } /* else already sorted */ } +} + +#define sort_points_by_increasing_y(x1, y1, x2, y2, x3, y3) \ + sort_points_by_increasing_x(y1, x1, y2, x2, y3, x3) + +/* draw a filled triangle, using horizontal lines for speed */ +void xlcd_filltriangle_horizontal(struct screen* display, + int x1, int y1, + int x2, int y2, + int x3, int y3) +{ + long fp_x1, fp_x2, fp_dx1, fp_dx2; + int y; + sort_points_by_increasing_y(&x1, &y1, &x2, &y2, &x3, &y3); if (y1 < y3) /* draw */ { @@ -72,12 +84,12 @@ void xlcd_filltriangle(int x1, int y1, int x2, int y2, int x3, int y3) fp_x1 = (x1 << 16) + (1<<15) + (fp_dx1 >> 1); if (y1 < y2) /* first part */ - { + { fp_dx2 = ((x2 - x1) << 16) / (y2 - y1); fp_x2 = (x1 << 16) + (1<<15) + (fp_dx2 >> 1); for (y = y1; y < y2; y++) { - _xlcd_rb->lcd_hline(fp_x1 >> 16, fp_x2 >> 16, y); + display->hline(fp_x1 >> 16, fp_x2 >> 16, y); fp_x1 += fp_dx1; fp_x2 += fp_dx2; } @@ -88,53 +100,23 @@ void xlcd_filltriangle(int x1, int y1, int x2, int y2, int x3, int y3) fp_x2 = (x2 << 16) + (1<<15) + (fp_dx2 >> 1); for (y = y2; y < y3; y++) { - _xlcd_rb->lcd_hline(fp_x1 >> 16, fp_x2 >> 16, y); + display->hline(fp_x1 >> 16, fp_x2 >> 16, y); fp_x1 += fp_dx1; fp_x2 += fp_dx2; } } } -} -#else /* (LCD_DEPTH < 8) && (LCD_PIXELFORMAT == VERTICAL_PACKING) */ +} + /* draw a filled triangle, using vertical lines for speed */ -void xlcd_filltriangle(int x1, int y1, int x2, int y2, int x3, int y3) +void xlcd_filltriangle_vertical(struct screen* display, + int x1, int y1, + int x2, int y2, + int x3, int y3) { - int x, y; long fp_y1, fp_y2, fp_dy1, fp_dy2; - - /* sort vertices by increasing x value */ - if (x1 > x3) - { - if (x2 < x3) /* x2 < x3 < x1 */ - { - x = x1; x1 = x2; x2 = x3; x3 = x; - y = y1; y1 = y2; y2 = y3; y3 = y; - } - else if (x2 > x1) /* x3 < x1 < x2 */ - { - x = x1; x1 = x3; x3 = x2; x2 = x; - y = y1; y1 = y3; y3 = y2; y2 = y; - } - else /* x3 <= x2 <= x1 */ - { - x = x1; x1 = x3; x3 = x; - y = y1; y1 = y3; y3 = y; - } - } - else - { - if (x2 < x1) /* x2 < x1 <= x3 */ - { - x = x1; x1 = x2; x2 = x; - y = y1; y1 = y2; y2 = y; - } - else if (x2 > x3) /* x1 <= x3 < x2 */ - { - x = x2; x2 = x3; x3 = x; - y = y2; y2 = y3; y3 = y; - } - /* else already sorted */ - } + int x; + sort_points_by_increasing_x(&x1, &y1, &x2, &y2, &x3, &y3); if (x1 < x3) /* draw */ { @@ -142,12 +124,12 @@ void xlcd_filltriangle(int x1, int y1, int x2, int y2, int x3, int y3) fp_y1 = (y1 << 16) + (1<<15) + (fp_dy1 >> 1); if (x1 < x2) /* first part */ - { + { fp_dy2 = ((y2 - y1) << 16) / (x2 - x1); fp_y2 = (y1 << 16) + (1<<15) + (fp_dy2 >> 1); for (x = x1; x < x2; x++) { - _xlcd_rb->lcd_vline(x, fp_y1 >> 16, fp_y2 >> 16); + display->vline(x, fp_y1 >> 16, fp_y2 >> 16); fp_y1 += fp_dy1; fp_y2 += fp_dy2; } @@ -158,14 +140,33 @@ void xlcd_filltriangle(int x1, int y1, int x2, int y2, int x3, int y3) fp_y2 = (y2 << 16) + (1<<15) + (fp_dy2 >> 1); for (x = x2; x < x3; x++) { - _xlcd_rb->lcd_vline(x, fp_y1 >> 16, fp_y2 >> 16); + display->vline(x, fp_y1 >> 16, fp_y2 >> 16); fp_y1 += fp_dy1; fp_y2 += fp_dy2; } } } } -#endif /* LCD_DEPTH, LCD_PIXELFORMAT */ + +void xlcd_filltriangle(int x1, int y1, + int x2, int y2, + int x3, int y3) +{ + /* default is main screen */ + xlcd_filltriangle_screen(_xlcd_rb->screens[SCREEN_MAIN], + x1, y1, x2, y2, x3, y3); +} + +void xlcd_filltriangle_screen(struct screen* display, + int x1, int y1, + int x2, int y2, + int x3, int y3) +{ + if(display->pixel_format==HORIZONTAL_PACKING || display->depth>=8) + xlcd_filltriangle_horizontal(display, x1, y1, x2, y2, x3, y3); + else + xlcd_filltriangle_vertical(display, x1, y1, x2, y2, x3, y3); +} #if LCD_DEPTH >= 8 -- cgit v1.2.3