diff options
Diffstat (limited to 'apps/plugins/clock')
22 files changed, 1753 insertions, 0 deletions
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 @@ | |||
1 | # __________ __ ___. | ||
2 | # Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
3 | # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
4 | # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
5 | # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
6 | # \/ \/ \/ \/ \/ | ||
7 | # $$Id: $$ | ||
8 | # | ||
9 | |||
10 | INCLUDES = -I$(APPSDIR) -I.. -I. -I$(APPSDIR)/plugins/lib \ | ||
11 | $(TARGET_INC) -I$(FIRMDIR)/include -I$(FIRMDIR)/export \ | ||
12 | -I$(FIRMDIR)/common -I$(FIRMDIR)/drivers -I$(OUTDIR) -I$(BUILDDIR) \ | ||
13 | -I$(BUILDDIR)/pluginbitmaps | ||
14 | CFLAGS = $(INCLUDES) $(GCCOPTS) $(TARGET) $(EXTRA_DEFINES) \ | ||
15 | -DTARGET_ID=$(TARGET_ID) -DMEM=${MEMORYSIZE} -DPLUGIN | ||
16 | |||
17 | ifdef APPEXTRA | ||
18 | INCLUDES += $(patsubst %,-I$(APPSDIR)/%,$(subst :, ,$(APPEXTRA))) | ||
19 | endif | ||
20 | |||
21 | LINKFILE := $(OBJDIR)/link.lds | ||
22 | DEPFILE = $(OBJDIR)/dep-clock | ||
23 | |||
24 | # This sets up 'SRC' based on the files mentioned in SOURCES | ||
25 | include $(TOOLSDIR)/makesrc.inc | ||
26 | |||
27 | SOURCES = $(SRC) | ||
28 | OBJS := $(SRC:%.c=$(OBJDIR)/%.o) | ||
29 | DIRS = . | ||
30 | |||
31 | ifndef SIMVER | ||
32 | LDS := ../plugin.lds | ||
33 | OUTPUT = $(OUTDIR)/clock.rock | ||
34 | else ## simulators | ||
35 | OUTPUT = $(OUTDIR)/clock.rock | ||
36 | endif | ||
37 | |||
38 | all: $(OUTPUT) | ||
39 | |||
40 | ifndef SIMVER | ||
41 | $(OBJDIR)/clock.elf: $(OBJS) $(LINKFILE) $(BITMAPLIBS) | ||
42 | $(call PRINTS,LD $(@F))$(CC) $(GCCOPTS) -O -nostdlib -o $@ $(OBJS) -L$(BUILDDIR) -lplugin -lgcc \ | ||
43 | $(LINKBITMAPS) -T$(LINKFILE) -Wl,-Map,$(OBJDIR)/clock.map | ||
44 | |||
45 | $(OUTPUT): $(OBJDIR)/clock.elf | ||
46 | $(call PRINTS,OBJCOPY $(@F))$(OC) -O binary $< $@ | ||
47 | else | ||
48 | |||
49 | ifeq ($(SIMVER), x11) | ||
50 | ################################################### | ||
51 | # This is the X11 simulator version | ||
52 | |||
53 | $(OUTPUT): $(OBJS) | ||
54 | $(call PRINTS,LD $(@F))$(CC) $(CFLAGS) $(SHARED_FLAG) $(OBJS) -L$(BUILDDIR) -lplugin $(LINKBITMAPS) -o $@ | ||
55 | ifeq ($(findstring CYGWIN,$(UNAME)),CYGWIN) | ||
56 | # 'x' must be kept or you'll have "Win32 error 5" | ||
57 | # $ fgrep 5 /usr/include/w32api/winerror.h | head -1 | ||
58 | # #define ERROR_ACCESS_DENIED 5L | ||
59 | else | ||
60 | @chmod -x $@ | ||
61 | endif | ||
62 | |||
63 | else # end of x11-simulator | ||
64 | ifeq ($(SIMVER), sdl) | ||
65 | ################################################### | ||
66 | # This is the SDL simulator version | ||
67 | |||
68 | $(OUTPUT): $(OBJS) | ||
69 | $(call PRINTS,LD $(@F))$(CC) $(CFLAGS) $(SHARED_FLAG) $(OBJS) -L$(BUILDDIR) -lplugin $(LINKBITMAPS) -o $@ | ||
70 | ifeq ($(findstring CYGWIN,$(UNAME)),CYGWIN) | ||
71 | # 'x' must be kept or you'll have "Win32 error 5" | ||
72 | # $ fgrep 5 /usr/include/w32api/winerror.h | head -1 | ||
73 | # #define ERROR_ACCESS_DENIED 5L | ||
74 | else | ||
75 | @chmod -x $@ | ||
76 | endif | ||
77 | |||
78 | else # end of sdl-simulator | ||
79 | ################################################### | ||
80 | # This is the win32 simulator version | ||
81 | DLLTOOLFLAGS = --export-all | ||
82 | DLLWRAPFLAGS = -s --entry _DllMain@12 --target=i386-mingw32 -mno-cygwin | ||
83 | |||
84 | $(OUTPUT): $(OBJS) | ||
85 | $(call PRINTS,DLL $(@F))$(DLLTOOL) $(DLLTOOLFLAGS) -z $(OBJDIR)/$*.def $(OBJS) | ||
86 | $(SILENT)$(DLLWRAP) $(DLLWRAPFLAGS) --def $(OBJDIR)/$*.def $(OBJS) \ | ||
87 | $(BUILDDIR)/libplugin.a $(BITMAPLIBS) -o $@ | ||
88 | ifeq ($(findstring CYGWIN,$(UNAME)),CYGWIN) | ||
89 | # 'x' must be kept or you'll have "Win32 error 5" | ||
90 | # $ fgrep 5 /usr/include/w32api/winerror.h | head -1 | ||
91 | # #define ERROR_ACCESS_DENIED 5L | ||
92 | else | ||
93 | @chmod -x $@ | ||
94 | endif | ||
95 | endif # end of win32-simulator | ||
96 | endif | ||
97 | endif # end of simulator section | ||
98 | |||
99 | |||
100 | include $(TOOLSDIR)/make.inc | ||
101 | |||
102 | # MEMORYSIZE should be passed on to this makefile with the chosen memory size | ||
103 | # given in number of MB | ||
104 | $(LINKFILE): $(LDS) | ||
105 | $(call PRINTS,build $(@F))cat $< | $(CC) -DMEMORYSIZE=$(MEMORYSIZE) $(INCLUDES) $(TARGET) \ | ||
106 | $(DEFINES) -E -P - >$@ | ||
107 | |||
108 | clean: | ||
109 | $(call PRINTS,cleaning clock)rm -rf $(OBJDIR)/clock | ||
110 | $(SILENT)rm -f $(OBJDIR)/clock.* $(DEPFILE) | ||
111 | |||
112 | -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 @@ | |||
1 | clock.c | ||
2 | clock_bitmaps.c | ||
3 | clock_bitmap_strings.c | ||
4 | clock_counter.c | ||
5 | clock_draw.c | ||
6 | clock_draw_analog.c | ||
7 | clock_draw_binary.c | ||
8 | clock_draw_digital.c | ||
9 | clock_menu.c | ||
10 | 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 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: clock.c 14095 2007-07-31 10:53:53Z nls $ | ||
9 | * | ||
10 | * Copyright (C) 2007 Kévin Ferrare | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #include "plugin.h" | ||
21 | #include "time.h" | ||
22 | #include "pluginlib_actions.h" | ||
23 | #include "xlcd.h" | ||
24 | |||
25 | #include "clock.h" | ||
26 | #include "clock_counter.h" | ||
27 | #include "clock_draw.h" | ||
28 | #include "clock_menu.h" | ||
29 | #include "clock_settings.h" | ||
30 | |||
31 | PLUGIN_HEADER | ||
32 | |||
33 | /* Keymaps */ | ||
34 | const struct button_mapping* plugin_contexts[]={ | ||
35 | generic_actions, | ||
36 | generic_directions, | ||
37 | #if NB_SCREENS == 2 | ||
38 | remote_directions | ||
39 | #endif | ||
40 | }; | ||
41 | #define NB_ACTION_CONTEXTS sizeof(plugin_contexts)/sizeof(plugin_contexts[0]) | ||
42 | #define ACTION_COUNTER_TOGGLE PLA_FIRE | ||
43 | #define ACTION_COUNTER_RESET PLA_FIRE_REPEAT | ||
44 | #define ACTION_MENU PLA_MENU | ||
45 | #define ACTION_EXIT PLA_QUIT | ||
46 | #define ACTION_MODE_NEXT PLA_RIGHT | ||
47 | #define ACTION_MODE_PREV PLA_LEFT | ||
48 | #define ACTION_SKIN_NEXT PLA_UP | ||
49 | #define ACTION_SKIN_PREV PLA_DOWN | ||
50 | |||
51 | extern struct plugin_api* rb; | ||
52 | |||
53 | /************************** | ||
54 | * Cleanup on plugin return | ||
55 | *************************/ | ||
56 | void cleanup(void *parameter) | ||
57 | { | ||
58 | (void)parameter; | ||
59 | clock_draw_restore_colors(); | ||
60 | if(clock_settings.general.save_settings == 1) | ||
61 | save_settings(); | ||
62 | |||
63 | /* restore set backlight timeout */ | ||
64 | rb->backlight_set_timeout(rb->global_settings->backlight_timeout); | ||
65 | } | ||
66 | |||
67 | /* puts the current time into the time struct */ | ||
68 | void clock_update_time( struct time* time){ | ||
69 | struct tm* current_time = rb->get_time(); | ||
70 | time->hour = current_time->tm_hour; | ||
71 | time->minute = current_time->tm_min; | ||
72 | time->second = current_time->tm_sec; | ||
73 | |||
74 | /********************* | ||
75 | * Date info | ||
76 | *********************/ | ||
77 | time->year = current_time->tm_year + 1900; | ||
78 | time->day = current_time->tm_mday; | ||
79 | time->month = current_time->tm_mon + 1; | ||
80 | |||
81 | } | ||
82 | |||
83 | void format_date(char* buffer, struct time* time, enum date_format format){ | ||
84 | switch(format){ | ||
85 | case JAPANESE: | ||
86 | rb->snprintf(buffer, 20, "%04d/%02d/%02d", | ||
87 | time->year, time->month, time->day); | ||
88 | break; | ||
89 | case EUROPEAN: | ||
90 | rb->snprintf(buffer, 20, "%02d/%02d/%04d", | ||
91 | time->day, time->month, time->year); | ||
92 | break; | ||
93 | case ENGLISH: | ||
94 | rb->snprintf(buffer, 20, "%02d/%02d/%04d", | ||
95 | time->month, time->day, time->year); | ||
96 | break; | ||
97 | case NONE: | ||
98 | default: | ||
99 | break; | ||
100 | } | ||
101 | } | ||
102 | |||
103 | /********************************************************************** | ||
104 | * Plugin starts here | ||
105 | **********************************************************************/ | ||
106 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter){ | ||
107 | int button; | ||
108 | int last_second = -1; | ||
109 | bool redraw=true; | ||
110 | int i; | ||
111 | struct time time; | ||
112 | struct counter counter; | ||
113 | bool exit_clock = false; | ||
114 | (void)parameter; | ||
115 | rb = api; | ||
116 | |||
117 | #if LCD_DEPTH > 1 | ||
118 | rb->lcd_set_backdrop(NULL); | ||
119 | #endif | ||
120 | |||
121 | load_settings(); | ||
122 | |||
123 | /* init xlcd functions */ | ||
124 | xlcd_init(rb); | ||
125 | counter_init(&counter); | ||
126 | clock_draw_set_colors(); | ||
127 | |||
128 | while(!exit_clock){ | ||
129 | clock_update_time(&time); | ||
130 | |||
131 | if(!clock_settings.general.idle_poweroff) | ||
132 | rb->reset_poweroff_timer(); | ||
133 | |||
134 | /************************* | ||
135 | * Scan for button presses | ||
136 | ************************/ | ||
137 | button = pluginlib_getaction(rb, HZ/10, plugin_contexts, NB_ACTION_CONTEXTS); | ||
138 | redraw=true;/* we'll set it to false afterwards if there was no action */ | ||
139 | switch (button){ | ||
140 | case ACTION_COUNTER_TOGGLE: /* start/stop counter */ | ||
141 | if(clock_settings.general.show_counter) | ||
142 | counter_toggle(&counter); | ||
143 | break; | ||
144 | |||
145 | case ACTION_COUNTER_RESET: /* reset counter */ | ||
146 | if(clock_settings.general.show_counter) | ||
147 | counter_reset(&counter); | ||
148 | break; | ||
149 | |||
150 | case ACTION_MODE_NEXT: | ||
151 | clock_settings.mode++; | ||
152 | if(clock_settings.mode >= NB_CLOCK_MODES) | ||
153 | clock_settings.mode = 0; | ||
154 | break; | ||
155 | |||
156 | case ACTION_MODE_PREV: | ||
157 | clock_settings.mode--; | ||
158 | if(clock_settings.mode < 0) | ||
159 | clock_settings.mode = NB_CLOCK_MODES-1; | ||
160 | break; | ||
161 | case ACTION_SKIN_PREV: | ||
162 | clock_settings_skin_next(&clock_settings); | ||
163 | break; | ||
164 | case ACTION_SKIN_NEXT: | ||
165 | clock_settings_skin_previous(&clock_settings); | ||
166 | break; | ||
167 | case ACTION_MENU: | ||
168 | clock_draw_restore_colors(); | ||
169 | exit_clock=main_menu(); | ||
170 | break; | ||
171 | |||
172 | case ACTION_EXIT: | ||
173 | /*clock_draw_restore_colors(); | ||
174 | exit_clock=main_menu();*/ | ||
175 | exit_clock=true; | ||
176 | break; | ||
177 | |||
178 | default: | ||
179 | redraw=false; | ||
180 | if(rb->default_event_handler_ex(button, cleanup, NULL) | ||
181 | == SYS_USB_CONNECTED) | ||
182 | return PLUGIN_USB_CONNECTED; | ||
183 | break; | ||
184 | } | ||
185 | if(time.second != last_second){ | ||
186 | last_second=time.second; | ||
187 | redraw=true; | ||
188 | } | ||
189 | if(redraw){ | ||
190 | clock_draw_set_colors(); | ||
191 | FOR_NB_SCREENS(i) | ||
192 | clock_draw(rb->screens[i], &time, &counter); | ||
193 | redraw=false; | ||
194 | } | ||
195 | } | ||
196 | |||
197 | cleanup(NULL); | ||
198 | return PLUGIN_OK; | ||
199 | } | ||
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 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ | ||
9 | * | ||
10 | * Copyright (C) 2007 Copyright Kévin Ferrare | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #ifndef _CLOCK_ | ||
21 | #define _CLOCK_ | ||
22 | #include "clock_settings.h" | ||
23 | extern struct plugin_api* rb; | ||
24 | |||
25 | struct time{ | ||
26 | int year, day, month; | ||
27 | int hour, minute, second; | ||
28 | }; | ||
29 | |||
30 | void format_date(char* buffer, struct time* time, enum date_format format); | ||
31 | |||
32 | #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 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ | ||
9 | * | ||
10 | * Copyright (C) 2007 Copyright Kévin Ferrare | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #include "clock.h" | ||
21 | #include "clock_bitmap_strings.h" | ||
22 | |||
23 | void draw_string(struct screen* display, const struct picture* bitmaps, | ||
24 | char* str, int x, int y){ | ||
25 | int i, bitmap_pos; | ||
26 | char c; | ||
27 | for(i=0;(c=str[i]);i++){ | ||
28 | bitmap_pos=-1; | ||
29 | if(c>='0'&&c<='9') | ||
30 | bitmap_pos=c-'0'; | ||
31 | else if(c==':') | ||
32 | bitmap_pos=10; | ||
33 | else if(c=='A' || c=='/')/* 'AM' in digits, '/' in smalldigits */ | ||
34 | bitmap_pos=11; | ||
35 | else if(c=='P' || c=='.')/* 'PM' in digits, '.' in smalldigits */ | ||
36 | bitmap_pos=12; | ||
37 | if(bitmap_pos>=0) | ||
38 | vertical_picture_draw_sprite(display, bitmaps, bitmap_pos, | ||
39 | x+i*bitmaps->width, y); | ||
40 | } | ||
41 | } | ||
42 | |||
43 | void getstringsize(const struct picture* bitmaps, char* str, int *w, int *h ){ | ||
44 | *h=bitmaps->height; | ||
45 | *w=rb->strlen(str)*bitmaps->width; | ||
46 | } | ||
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 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ | ||
9 | * | ||
10 | * Copyright (C) 2007 Copyright Kévin Ferrare | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | |||
21 | #ifndef _CLOCK_BITMAP_STRINGS_ | ||
22 | #define _CLOCK_BITMAP_STRINGS_ | ||
23 | #include "plugin.h" | ||
24 | #include "picture.h" | ||
25 | |||
26 | void draw_string(struct screen* display, const struct picture* bitmaps, | ||
27 | char* str, int x, int y); | ||
28 | |||
29 | void getstringsize(const struct picture* bitmaps, char* str, int *w, int *h ); | ||
30 | |||
31 | #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 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ | ||
9 | * | ||
10 | * Copyright (C) 2007 Copyright Kévin Ferrare | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | |||
21 | #include "clock_bitmaps.h" | ||
22 | |||
23 | /* bitmaps */ | ||
24 | #include "clock_binary.h" | ||
25 | #include "clock_digits.h" | ||
26 | #include "clock_smalldigits.h" | ||
27 | #include "clock_segments.h" | ||
28 | #include "clock_smallsegments.h" | ||
29 | |||
30 | #include "clock_logo.h" | ||
31 | #include "clock_messages.h" | ||
32 | |||
33 | #if NB_SCREENS==2 | ||
34 | #include "clock_binary_remote.h" | ||
35 | #include "clock_digits_remote.h" | ||
36 | #include "clock_smalldigits_remote.h" | ||
37 | #include "clock_segments_remote.h" | ||
38 | #include "clock_smallsegments_remote.h" | ||
39 | |||
40 | #include "clock_logo_remote.h" | ||
41 | #include "clock_messages_remote.h" | ||
42 | |||
43 | #endif | ||
44 | |||
45 | |||
46 | const struct picture logos[]={ | ||
47 | {clock_logo, BMPWIDTH_clock_logo, BMPHEIGHT_clock_logo}, | ||
48 | #if NB_SCREENS==2 | ||
49 | {clock_logo_remote,BMPWIDTH_clock_logo_remote,BMPHEIGHT_clock_logo_remote} | ||
50 | #endif | ||
51 | }; | ||
52 | |||
53 | const struct picture messages[]={ | ||
54 | {clock_messages,BMPWIDTH_clock_messages, | ||
55 | BMPHEIGHT_clock_messages/6}, | ||
56 | #if NB_SCREENS==2 | ||
57 | {clock_messages_remote,BMPWIDTH_clock_messages_remote, | ||
58 | BMPHEIGHT_clock_messages_remote/6} | ||
59 | #endif | ||
60 | }; | ||
61 | |||
62 | const struct picture binary[]={ | ||
63 | {clock_binary, | ||
64 | BMPWIDTH_clock_binary, BMPHEIGHT_clock_binary/2 }, | ||
65 | #if NB_SCREENS==2 | ||
66 | {clock_binary_remote, | ||
67 | BMPWIDTH_clock_binary_remote,BMPHEIGHT_clock_binary_remote/2} | ||
68 | #endif | ||
69 | }; | ||
70 | |||
71 | const struct picture digits[]={ | ||
72 | {clock_digits, | ||
73 | BMPWIDTH_clock_digits, BMPHEIGHT_clock_digits/13 }, | ||
74 | #if NB_SCREENS==2 | ||
75 | {clock_digits_remote, | ||
76 | BMPWIDTH_clock_digits_remote,BMPHEIGHT_clock_digits_remote/13} | ||
77 | #endif | ||
78 | }; | ||
79 | |||
80 | const struct picture smalldigits[]={ | ||
81 | {clock_smalldigits, | ||
82 | BMPWIDTH_clock_smalldigits, BMPHEIGHT_clock_smalldigits/13 }, | ||
83 | #if NB_SCREENS==2 | ||
84 | {clock_smalldigits_remote, | ||
85 | BMPWIDTH_clock_smalldigits_remote,BMPHEIGHT_clock_smalldigits_remote/13} | ||
86 | #endif | ||
87 | }; | ||
88 | |||
89 | const struct picture segments[]={ | ||
90 | {clock_segments, | ||
91 | BMPWIDTH_clock_segments, BMPHEIGHT_clock_segments/13 }, | ||
92 | #if NB_SCREENS==2 | ||
93 | {clock_segments_remote, | ||
94 | BMPWIDTH_clock_segments_remote,BMPHEIGHT_clock_segments_remote/13} | ||
95 | #endif | ||
96 | }; | ||
97 | |||
98 | const struct picture smallsegments[]={ | ||
99 | {clock_smallsegments, | ||
100 | BMPWIDTH_clock_smallsegments, BMPHEIGHT_clock_smallsegments/13 }, | ||
101 | #if NB_SCREENS==2 | ||
102 | {clock_smallsegments_remote, | ||
103 | BMPWIDTH_clock_smallsegments_remote,BMPHEIGHT_clock_smallsegments_remote/13} | ||
104 | #endif | ||
105 | }; | ||
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 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ | ||
9 | * | ||
10 | * Copyright (C) 2007 Copyright Kévin Ferrare | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #ifndef _CLOCK_BITMAPS_ | ||
21 | #define _CLOCK_BITMAPS_ | ||
22 | #include "picture.h" | ||
23 | |||
24 | extern const struct picture logos[]; | ||
25 | extern const struct picture messages[]; | ||
26 | |||
27 | extern const struct picture binary[]; | ||
28 | extern const struct picture digits[]; | ||
29 | extern const struct picture smalldigits[]; | ||
30 | extern const struct picture segments[]; | ||
31 | extern const struct picture smallsegments[]; | ||
32 | |||
33 | #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 @@ | |||
1 | #include "clock_counter.h" | ||
2 | #include "clock_bitmap_strings.h" | ||
3 | |||
4 | void counter_init(struct counter* counter){ | ||
5 | counter->ticks_since_started=0; | ||
6 | counter->ticks_at_last_unpause=0; | ||
7 | counter->paused=true; | ||
8 | } | ||
9 | |||
10 | int counter_get_ticks_since_last_pause(struct counter* counter){ | ||
11 | if(!counter->paused) | ||
12 | return(*rb->current_tick - counter->ticks_at_last_unpause); | ||
13 | return(0); | ||
14 | } | ||
15 | |||
16 | void counter_toggle(struct counter* counter){ | ||
17 | counter_pause(counter, !counter->paused); | ||
18 | } | ||
19 | |||
20 | void counter_pause(struct counter* counter, bool pause){ | ||
21 | if(pause){ | ||
22 | counter->ticks_since_started+=counter_get_ticks_since_last_pause(counter); | ||
23 | }else{ | ||
24 | counter->ticks_at_last_unpause=*rb->current_tick; | ||
25 | } | ||
26 | counter->paused=pause; | ||
27 | } | ||
28 | |||
29 | void counter_get_elapsed_time(struct counter* counter, struct time* elapsed_time){ | ||
30 | int total_time=counter_get_ticks_since_last_pause(counter); | ||
31 | total_time+=counter->ticks_since_started; | ||
32 | total_time/=HZ;/* converts ticks to seconds */ | ||
33 | |||
34 | elapsed_time->second = total_time%60; | ||
35 | elapsed_time->minute = (total_time%3600) / 60; | ||
36 | elapsed_time->hour = total_time / 3600; | ||
37 | /* not yet ! */ | ||
38 | elapsed_time->day=0; | ||
39 | elapsed_time->month=0; | ||
40 | elapsed_time->year=0; | ||
41 | } | ||
42 | |||
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 @@ | |||
1 | #ifndef _CLOCK_MESSAGE_ | ||
2 | #define _CLOCK_MESSAGE_ | ||
3 | #include "clock.h" | ||
4 | #include "plugin.h" | ||
5 | #include "picture.h" | ||
6 | |||
7 | struct counter{ | ||
8 | int ticks_at_last_unpause;/* to count the time from last pause to now */ | ||
9 | int ticks_since_started;/* accumulated time */ | ||
10 | bool paused; | ||
11 | }; | ||
12 | |||
13 | void counter_init(struct counter* counter); | ||
14 | void counter_toggle(struct counter* counter); | ||
15 | #define counter_reset(counter) counter_init(counter) | ||
16 | void counter_pause(struct counter* counter, bool paused); | ||
17 | void counter_get_elapsed_time(struct counter* counter, struct time* elapsed_time); | ||
18 | |||
19 | #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 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ | ||
9 | * | ||
10 | * Copyright (C) 2007 Copyright Kévin Ferrare | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #include "clock.h" | ||
21 | #include "clock_draw.h" | ||
22 | #include "clock_draw_digital.h" | ||
23 | #include "clock_draw_analog.h" | ||
24 | #include "clock_draw_binary.h" | ||
25 | #include "clock_settings.h" | ||
26 | |||
27 | void black_background(struct screen* display){ | ||
28 | #if (LCD_DEPTH > 1) || (defined(LCD_REMOTE_DEPTH) && (LCD_REMOTE_DEPTH > 1)) | ||
29 | if(display->depth>1){ | ||
30 | display->set_background(LCD_BLACK); | ||
31 | display->clear_display(); | ||
32 | }else | ||
33 | #endif | ||
34 | { | ||
35 | display->clear_display(); | ||
36 | display->fillrect(0,0,display->width,display->height); | ||
37 | } | ||
38 | } | ||
39 | |||
40 | void white_background(struct screen* display){ | ||
41 | #if (LCD_DEPTH > 1) || (defined(LCD_REMOTE_DEPTH) && (LCD_REMOTE_DEPTH > 1)) | ||
42 | if(display->depth>1){ | ||
43 | #if defined(HAVE_LCD_COLOR) | ||
44 | if(display->is_color)/* restore to the bitmap's background */ | ||
45 | display->set_background(LCD_RGBPACK(180,200,230)); | ||
46 | else | ||
47 | #endif | ||
48 | display->set_background(LCD_WHITE); | ||
49 | } | ||
50 | #endif | ||
51 | display->clear_display(); | ||
52 | } | ||
53 | |||
54 | bool skin_require_black_background(int mode, int skin){ | ||
55 | return((mode==BINARY && skin==2) || (mode==DIGITAL && skin==1 )); | ||
56 | } | ||
57 | |||
58 | void skin_set_background(struct screen* display, int mode, int skin){ | ||
59 | if(skin_require_black_background(mode, skin) ) | ||
60 | black_background(display); | ||
61 | else | ||
62 | white_background(display); | ||
63 | } | ||
64 | |||
65 | void skin_restore_background(struct screen* display, int mode, int skin){ | ||
66 | if(skin_require_black_background(mode, skin) ) | ||
67 | white_background(display); | ||
68 | } | ||
69 | |||
70 | void clock_draw_set_colors(void){ | ||
71 | int i; | ||
72 | FOR_NB_SCREENS(i) | ||
73 | skin_set_background(rb->screens[i], | ||
74 | clock_settings.mode, | ||
75 | clock_settings.skin[clock_settings.mode]); | ||
76 | } | ||
77 | |||
78 | void clock_draw_restore_colors(void){ | ||
79 | int i; | ||
80 | FOR_NB_SCREENS(i){ | ||
81 | skin_restore_background(rb->screens[i], | ||
82 | clock_settings.mode, | ||
83 | clock_settings.skin[clock_settings.mode]); | ||
84 | rb->screens[i]->update(); | ||
85 | } | ||
86 | } | ||
87 | |||
88 | void clock_draw(struct screen* display, struct time* time, | ||
89 | struct counter* counter){ | ||
90 | if(!clock_settings.general.show_counter) | ||
91 | counter=0; | ||
92 | int skin=clock_settings.skin[clock_settings.mode]; | ||
93 | skin_set_background(display, clock_settings.mode, skin); | ||
94 | if(clock_settings.mode == ANALOG) | ||
95 | analog_clock_draw(display, time, &clock_settings, counter, skin); | ||
96 | |||
97 | else if(clock_settings.mode == DIGITAL) | ||
98 | digital_clock_draw(display, time, &clock_settings, counter, skin); | ||
99 | |||
100 | else if(clock_settings.mode == BINARY) | ||
101 | binary_clock_draw(display, time, skin); | ||
102 | display->update(); | ||
103 | } | ||
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 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ | ||
9 | * | ||
10 | * Copyright (C) 2007 Copyright Kévin Ferrare | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #ifndef _CLOCK_DRAW_ | ||
21 | #define _CLOCK_DRAW_ | ||
22 | #include "plugin.h" | ||
23 | #include "clock.h" | ||
24 | #include "clock_counter.h" | ||
25 | |||
26 | void clock_draw_set_colors(void); | ||
27 | void clock_draw_restore_colors(void); | ||
28 | |||
29 | void clock_draw(struct screen* display, struct time* time, | ||
30 | struct counter* counter); | ||
31 | |||
32 | #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 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ | ||
9 | * | ||
10 | * Copyright (C) 2007 Copyright Kévin Ferrare based on Zakk Roberts's work | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #include "clock_draw_analog.h" | ||
21 | #include "xlcd.h" | ||
22 | #include "fixedpoint.h" | ||
23 | #include "clock_bitmaps.h" | ||
24 | #include "clock_bitmap_strings.h" | ||
25 | |||
26 | #define ANALOG_SECOND_RADIUS(screen, round) \ | ||
27 | ANALOG_MINUTE_RADIUS(screen, round) | ||
28 | #define ANALOG_MINUTE_RADIUS(screen, round) \ | ||
29 | (round?MIN(screen->height/2 -10, screen->width/2 -10):screen->height/2) | ||
30 | #define ANALOG_HOUR_RADIUS(screen, round) \ | ||
31 | (ANALOG_MINUTE_RADIUS(screen, round)/2) | ||
32 | |||
33 | #define HOUR_ANGLE(hour, minute, second) (30*(hour) +(minute)/2) | ||
34 | #define MINUTE_ANGLE(minute, second) (6*(minute)+(second)/10) | ||
35 | #define SECOND_ANGLE(second) (6 * (second)) | ||
36 | |||
37 | void polar_to_cartesian(int a, int r, int* x, int* y){ | ||
38 | *x = (sin_int(a) * r) >> 14; | ||
39 | *y = (sin_int(a-90) * r) >> 14; | ||
40 | } | ||
41 | |||
42 | void polar_to_cartesian_screen_centered(struct screen * display, | ||
43 | int a, int r, int* x, int* y){ | ||
44 | polar_to_cartesian(a, r, x, y); | ||
45 | *x+=display->width/2; | ||
46 | *y+=display->height/2; | ||
47 | } | ||
48 | |||
49 | void angle_to_square(int square_width, int square_height, | ||
50 | int a, int* x, int* y){ | ||
51 | a = (a+360-90)%360; | ||
52 | if(a>45 && a<=135){/* top line */ | ||
53 | a-=45; | ||
54 | *x=square_width-(square_width*2*a)/90; | ||
55 | *y=square_height; | ||
56 | }else if(a>135 && a<=225){/* left line */ | ||
57 | a-=135; | ||
58 | *x=-square_width; | ||
59 | *y=square_height-(square_height*2*a)/90; | ||
60 | }else if(a>225 && a<=315){/* bottom line */ | ||
61 | a-=225; | ||
62 | *x=(square_width*2*a)/90-square_width; | ||
63 | *y=-square_height; | ||
64 | }else if(a>315 || a<=45){/* right line */ | ||
65 | if(a>315) | ||
66 | a-=315; | ||
67 | else | ||
68 | a+=45; | ||
69 | *x=square_width; | ||
70 | *y=(square_height*2*a)/90-square_height; | ||
71 | } | ||
72 | } | ||
73 | |||
74 | void angle_to_square_screen_centered(struct screen * display, | ||
75 | int square_width, int square_height, | ||
76 | int a, int* x, int* y){ | ||
77 | angle_to_square(square_width, square_height, a, x, y); | ||
78 | *x+=display->width/2; | ||
79 | *y+=display->height/2; | ||
80 | } | ||
81 | |||
82 | void draw_hand(struct screen* display, int angle, | ||
83 | int radius, int thickness, bool round){ | ||
84 | int x1, y1; /* the longest */ | ||
85 | int x2, y2, x3, y3; /* the base */ | ||
86 | if(round){/* round clock */ | ||
87 | polar_to_cartesian_screen_centered(display, angle, | ||
88 | radius, &x1, &y1); | ||
89 | }else{/* fullscreen clock, hands describes square motions */ | ||
90 | int square_width, square_height; | ||
91 | /* radius is defined smallest between width and height */ | ||
92 | square_height=radius; | ||
93 | square_width=(radius*display->width)/display->height; | ||
94 | angle_to_square_screen_centered( | ||
95 | display, square_width, square_height, angle, &x1, &y1); | ||
96 | } | ||
97 | polar_to_cartesian_screen_centered(display, (angle+120)%360, | ||
98 | radius/40+thickness, &x2, &y2); | ||
99 | polar_to_cartesian_screen_centered(display, (angle+240)%360, | ||
100 | radius/40+thickness, &x3, &y3); | ||
101 | xlcd_filltriangle_screen(display, x1, y1, x2, y2, x3, y3); | ||
102 | } | ||
103 | |||
104 | void draw_hands(struct screen* display, int hour, int minute, int second, | ||
105 | int thickness, bool round, bool draw_seconds){ | ||
106 | if(draw_seconds){ | ||
107 | draw_hand(display, SECOND_ANGLE(second), | ||
108 | ANALOG_SECOND_RADIUS(display, round), thickness, round); | ||
109 | } | ||
110 | draw_hand(display, MINUTE_ANGLE(minute, second), | ||
111 | ANALOG_MINUTE_RADIUS(display, round), thickness+2, round); | ||
112 | draw_hand(display, HOUR_ANGLE(hour, minute, second), | ||
113 | ANALOG_HOUR_RADIUS(display, round), thickness+2, round); | ||
114 | } | ||
115 | |||
116 | /******************* | ||
117 | * Analog clock mode | ||
118 | ******************/ | ||
119 | void analog_clock_draw(struct screen* display, struct time* time, | ||
120 | struct clock_settings* settings, | ||
121 | struct counter* counter, | ||
122 | int skin){ | ||
123 | int i; | ||
124 | const struct picture* smalldigits_bitmaps = | ||
125 | &(smalldigits[display->screen_type]); | ||
126 | int hour=time->hour; | ||
127 | if(hour >= 12) | ||
128 | hour -= 12; | ||
129 | |||
130 | /* show_date */ | ||
131 | /* show_digital_time*/ | ||
132 | |||
133 | /* Crappy fake antialiasing (color LCDs only)! | ||
134 | * how this works is we draw a large mid-gray hr/min/sec hand, | ||
135 | * then the actual (slightly smaller) hand on top of those. | ||
136 | * End result: mid-gray edges to the black hands, smooths them out. */ | ||
137 | #ifdef HAVE_LCD_COLOR | ||
138 | if(display->is_color){ | ||
139 | display->set_foreground(LCD_RGBPACK(100,110,125)); | ||
140 | draw_hands(display, hour, time->minute, time->second, 2, | ||
141 | skin, settings->analog.show_seconds); | ||
142 | display->set_foreground(LCD_BLACK); | ||
143 | } | ||
144 | #endif | ||
145 | draw_hands(display, hour, time->minute, time->second, 0, skin, | ||
146 | settings->analog.show_seconds); | ||
147 | |||
148 | if(settings->analog.show_border){ | ||
149 | /* Draws square dots every 5 minutes */ | ||
150 | int x, y; | ||
151 | int size=display->height/50;/* size of the square dots */ | ||
152 | if(size%2)/* a pair number */ | ||
153 | size++; | ||
154 | for(i=0; i < 60; i+=5){ | ||
155 | if(skin){ | ||
156 | polar_to_cartesian_screen_centered(display, MINUTE_ANGLE(i, 0), | ||
157 | ANALOG_MINUTE_RADIUS(display, skin), &x, &y); | ||
158 | }else{ | ||
159 | angle_to_square_screen_centered( | ||
160 | display, display->width/2-size/2, display->height/2-size/2, | ||
161 | MINUTE_ANGLE(i, 0), &x, &y); | ||
162 | } | ||
163 | display->fillrect(x-size/2, y-size/2, size, size); | ||
164 | } | ||
165 | } | ||
166 | |||
167 | if(counter){ | ||
168 | char buffer[10]; | ||
169 | int second_str_w, hour_str_w, str_h; | ||
170 | struct time counter_time; | ||
171 | counter_get_elapsed_time(counter, &counter_time); | ||
172 | rb->snprintf(buffer, 10, "%02d:%02d", | ||
173 | counter_time.hour, counter_time.minute); | ||
174 | getstringsize(smalldigits_bitmaps, buffer, &hour_str_w, &str_h); | ||
175 | draw_string(display, smalldigits_bitmaps, buffer, | ||
176 | display->width-hour_str_w, | ||
177 | display->height-2*str_h); | ||
178 | |||
179 | rb->snprintf(buffer, 10, "%02d", counter_time.second); | ||
180 | getstringsize(smalldigits_bitmaps, buffer, &second_str_w, &str_h); | ||
181 | draw_string(display, smalldigits_bitmaps, buffer, | ||
182 | display->width-(hour_str_w+second_str_w)/2, | ||
183 | display->height-str_h); | ||
184 | } | ||
185 | if(settings->analog.show_date && settings->general.date_format!=NONE){ | ||
186 | char buffer[10]; | ||
187 | int year_str_w, monthday_str_w, str_h; | ||
188 | if(settings->general.date_format==ENGLISH){ | ||
189 | rb->snprintf(buffer, 10, "%02d/%02d", time->month, time->day); | ||
190 | }else{ | ||
191 | rb->snprintf(buffer, 10, "%02d/%02d", time->day, time->month); | ||
192 | } | ||
193 | getstringsize(smalldigits_bitmaps, buffer, &monthday_str_w, &str_h); | ||
194 | draw_string(display, smalldigits_bitmaps, buffer, | ||
195 | 0, display->height-2*str_h); | ||
196 | rb->snprintf(buffer, 10, "%04d", time->year); | ||
197 | getstringsize(smalldigits_bitmaps, buffer, &year_str_w, &str_h); | ||
198 | draw_string(display, smalldigits_bitmaps, buffer, | ||
199 | (monthday_str_w-year_str_w)/2, display->height-str_h); | ||
200 | } | ||
201 | |||
202 | /* Draw the cover over the center */ | ||
203 | display->drawline((display->width/2)-1, (display->height/2)+3, | ||
204 | (display->width/2)+1, (display->height/2)+3); | ||
205 | display->drawline((display->width/2)-3, (display->height/2)+2, | ||
206 | (display->width/2)+3, (display->height/2)+2); | ||
207 | display->drawline((display->width/2)-4, (display->height/2)+1, | ||
208 | (display->width/2)+4, (display->height/2)+1); | ||
209 | display->drawline((display->width/2)-4, display->height/2, | ||
210 | (display->width/2)+4, display->height/2); | ||
211 | display->drawline((display->width/2)-4, (display->height/2)-1, | ||
212 | (display->width/2)+4, (display->height/2)-1); | ||
213 | display->drawline((display->width/2)-3, (display->height/2)-2, | ||
214 | (display->width/2)+3, (display->height/2)-2); | ||
215 | display->drawline((display->width/2)-1, (display->height/2)-3, | ||
216 | (display->width/2)+1, (display->height/2)-3); | ||
217 | } | ||
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 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ | ||
9 | * | ||
10 | * Copyright (C) 2007 Copyright Kévin Ferrare | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #ifndef _ANALOG_CLOCK_ | ||
21 | #define _ANALOG_CLOCK_ | ||
22 | #include "plugin.h" | ||
23 | #include "clock.h" | ||
24 | #include "clock_counter.h" | ||
25 | #include "clock_settings.h" | ||
26 | |||
27 | void analog_clock_draw(struct screen* display, struct time* time, | ||
28 | struct clock_settings* settings, | ||
29 | struct counter* counter, | ||
30 | int skin); | ||
31 | |||
32 | #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 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ | ||
9 | * | ||
10 | * Copyright (C) 2007 Copyright Kévin Ferrare | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include "clock_draw_binary.h" | ||
20 | #include "clock_bitmap_strings.h" | ||
21 | #include "clock_bitmaps.h" | ||
22 | #include "picture.h" | ||
23 | |||
24 | const struct picture* binary_skin[]={binary,digits,segments}; | ||
25 | |||
26 | void print_binary(char* buffer, int number, int nb_bits){ | ||
27 | int i; | ||
28 | int mask=1; | ||
29 | buffer[nb_bits]='\0'; | ||
30 | for(i=0; i<nb_bits; i++){ | ||
31 | if((number & mask) !=0) | ||
32 | buffer[nb_bits-i-1]='1'; | ||
33 | else | ||
34 | buffer[nb_bits-i-1]='0'; | ||
35 | mask=mask<<1; | ||
36 | } | ||
37 | } | ||
38 | |||
39 | void binary_clock_draw(struct screen* display, struct time* time, int skin){ | ||
40 | int lines_values[]={ | ||
41 | time->hour,time->minute,time->second | ||
42 | }; | ||
43 | char buffer[9]; | ||
44 | int i; | ||
45 | const struct picture* binary_bitmaps = &(binary_skin[skin][display->screen_type]); | ||
46 | for(i=0;i<3;i++){ | ||
47 | print_binary(buffer, lines_values[i], 6); | ||
48 | draw_string(display, binary_bitmaps, buffer, 0, | ||
49 | binary_bitmaps->height*i); | ||
50 | } | ||
51 | } | ||
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 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ | ||
9 | * | ||
10 | * Copyright (C) 2007 Copyright Kévin Ferrare | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #ifndef _BINARY_CLOCK_ | ||
21 | #define _BINARY_CLOCK_ | ||
22 | #include "plugin.h" | ||
23 | #include "clock.h" | ||
24 | |||
25 | void binary_clock_draw(struct screen* display, struct time* time, int skin); | ||
26 | |||
27 | #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 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ | ||
9 | * | ||
10 | * Copyright (C) 2007 Copyright Kévin Ferrare | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #include "clock.h" | ||
21 | #include "clock_draw_digital.h" | ||
22 | #include "clock_bitmap_strings.h" | ||
23 | #include "clock_bitmaps.h" | ||
24 | #include "picture.h" | ||
25 | |||
26 | const struct picture* digits_skin[]={digits,segments}; | ||
27 | const struct picture* smalldigits_skin[]={smalldigits,smallsegments}; | ||
28 | |||
29 | #define buffer_printf(buffer, buffer_pos, ... ) \ | ||
30 | buffer_pos+=rb->snprintf(&buffer[buffer_pos], sizeof(buffer)-buffer_pos, __VA_ARGS__); | ||
31 | |||
32 | void digital_clock_draw(struct screen* display, | ||
33 | struct time* time, | ||
34 | struct clock_settings* settings, | ||
35 | struct counter* counter, | ||
36 | int skin){ | ||
37 | bool display_colon; | ||
38 | const struct picture* digits_bitmaps = &(digits_skin[skin][display->screen_type]); | ||
39 | const struct picture* smalldigits_bitmaps = &(smalldigits_skin[skin][display->screen_type]); | ||
40 | int hour=time->hour; | ||
41 | int str_w, str_h; | ||
42 | char buffer[20]; | ||
43 | int buffer_pos=0; | ||
44 | |||
45 | if(settings->digital.blinkcolon){ | ||
46 | display_colon=(time->second%2==0); | ||
47 | } | ||
48 | else | ||
49 | display_colon=true; | ||
50 | |||
51 | if(settings->general.hour_format==H12){/* AM/PM format */ | ||
52 | if(hour>12){ | ||
53 | buffer_printf(buffer, buffer_pos, "P");/* AM */ | ||
54 | /* readjust the hour to 12-hour format | ||
55 | * ( 13:00+ -> 1:00+ ) */ | ||
56 | hour -= 12; | ||
57 | }else | ||
58 | buffer_printf(buffer, buffer_pos, "A");/* AM */ | ||
59 | } | ||
60 | buffer_printf(buffer, buffer_pos, "%02d", hour); | ||
61 | buffer_printf(buffer, buffer_pos, "%c", display_colon?':':' '); | ||
62 | buffer_printf(buffer, buffer_pos, "%02d", time->minute); | ||
63 | getstringsize(digits_bitmaps, buffer, &str_w, &str_h); | ||
64 | draw_string(display, digits_bitmaps, buffer, (display->width-str_w)/2, 0); | ||
65 | if(settings->digital.show_seconds){ | ||
66 | buffer_pos=0; | ||
67 | buffer_printf(buffer, buffer_pos, "%02d", time->second); | ||
68 | getstringsize(digits_bitmaps, buffer, &str_w, &str_h); | ||
69 | draw_string(display, digits_bitmaps, buffer, (display->width-str_w)/2, | ||
70 | digits_bitmaps->height); | ||
71 | } | ||
72 | if(settings->general.date_format!=NONE){ | ||
73 | format_date(buffer, time, settings->general.date_format); | ||
74 | getstringsize(smalldigits_bitmaps, buffer, &str_w, &str_h); | ||
75 | draw_string(display, smalldigits_bitmaps, buffer, (display->width-str_w)/2, | ||
76 | display->height-smalldigits_bitmaps->height*2); | ||
77 | } | ||
78 | if(counter){ | ||
79 | struct time counter_time; | ||
80 | counter_get_elapsed_time(counter, &counter_time); | ||
81 | rb->snprintf(buffer, 20, "%02d:%02d:%02d", | ||
82 | counter_time.hour, counter_time.minute, counter_time.second); | ||
83 | getstringsize(smalldigits_bitmaps, buffer, &str_w, &str_h); | ||
84 | draw_string(display, smalldigits_bitmaps, buffer, (display->width-str_w)/2, | ||
85 | display->height-str_h); | ||
86 | } | ||
87 | } | ||
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 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ | ||
9 | * | ||
10 | * Copyright (C) 2007 Copyright Kévin Ferrare | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #ifndef _DIGITAL_CLOCK_ | ||
21 | #define _DIGITAL_CLOCK_ | ||
22 | #include "plugin.h" | ||
23 | #include "clock.h" | ||
24 | #include "clock_counter.h" | ||
25 | #include "clock_settings.h" | ||
26 | |||
27 | void digital_clock_draw(struct screen* display, struct time* time, | ||
28 | struct clock_settings* settings, | ||
29 | struct counter* counter, int skin); | ||
30 | |||
31 | #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 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ | ||
9 | * | ||
10 | * Copyright (C) 2003 Zakk Roberts | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #include "clock.h" | ||
21 | #include "clock_bitmaps.h" | ||
22 | #include "clock_settings.h" | ||
23 | |||
24 | /* Option structs (possible selections per each option) */ | ||
25 | static const struct opt_items noyes_text[] = { | ||
26 | { "No", -1 }, | ||
27 | { "Yes", -1 } | ||
28 | }; | ||
29 | |||
30 | static const struct opt_items backlight_settings_text[] = { | ||
31 | { "Always Off", -1 }, | ||
32 | { "Rockbox setting", -1 }, | ||
33 | { "Always On", -1 } | ||
34 | }; | ||
35 | |||
36 | static const struct opt_items idle_poweroff_text[] = { | ||
37 | { "Disabled", -1 }, | ||
38 | { "Enabled", -1 } | ||
39 | }; | ||
40 | |||
41 | static const struct opt_items date_format_text[] = { | ||
42 | { "No date", -1 }, | ||
43 | { "English format", -1 }, | ||
44 | { "European format", -1 }, | ||
45 | { "Japanese format", -1 }, | ||
46 | }; | ||
47 | |||
48 | static const struct opt_items hour_format_text[] = { | ||
49 | { "24-hour Format", -1 }, | ||
50 | { "12-hour Format", -1 } | ||
51 | }; | ||
52 | |||
53 | /*************** | ||
54 | * Select a mode, returs true when the mode has been selected | ||
55 | * (we go back to clock display then) | ||
56 | **************/ | ||
57 | bool menu_mode_selector(void){ | ||
58 | MENUITEM_STRINGLIST(menu,"Mode Selector",NULL, "Analog", | ||
59 | "Digital", "Binary"); | ||
60 | if(rb->do_menu(&menu, &clock_settings.mode) >=0) | ||
61 | return(true); | ||
62 | return(false); | ||
63 | } | ||
64 | |||
65 | /********************** | ||
66 | * Analog settings menu | ||
67 | *********************/ | ||
68 | void menu_analog_settings(void) | ||
69 | { | ||
70 | int selection=0, result=0; | ||
71 | |||
72 | MENUITEM_STRINGLIST(menu,"Analog Mode Settings",NULL,"Show Date", | ||
73 | "Show Second Hand","Show Border"); | ||
74 | |||
75 | while(result>=0){ | ||
76 | result=rb->do_menu(&menu, &selection); | ||
77 | switch(result){ | ||
78 | case 0: | ||
79 | rb->set_option("Show Date", &clock_settings.analog.show_date, | ||
80 | BOOL, noyes_text, 2, NULL); | ||
81 | break; | ||
82 | case 1: | ||
83 | rb->set_option("Show Second Hand", | ||
84 | &clock_settings.analog.show_seconds, | ||
85 | BOOL, noyes_text, 2, NULL); | ||
86 | break; | ||
87 | case 2: | ||
88 | rb->set_option("Show Border", | ||
89 | &clock_settings.analog.show_border, | ||
90 | BOOL, noyes_text, 2, NULL); | ||
91 | break; | ||
92 | } | ||
93 | } | ||
94 | } | ||
95 | |||
96 | /*********************** | ||
97 | * Digital settings menu | ||
98 | **********************/ | ||
99 | void menu_digital_settings(void){ | ||
100 | int selection=0, result=0; | ||
101 | |||
102 | MENUITEM_STRINGLIST(menu,"Digital Mode Settings",NULL,"Show Seconds", | ||
103 | "Blinking Colon"); | ||
104 | |||
105 | while(result>=0){ | ||
106 | result=rb->do_menu(&menu, &selection); | ||
107 | switch(result){ | ||
108 | case 0: | ||
109 | rb->set_option("Show Seconds", | ||
110 | &clock_settings.digital.show_seconds, | ||
111 | BOOL, noyes_text, 2, NULL); | ||
112 | break; | ||
113 | case 1: | ||
114 | rb->set_option("Blinking Colon", | ||
115 | &clock_settings.digital.blinkcolon, | ||
116 | BOOL, noyes_text, 2, NULL); | ||
117 | break; | ||
118 | } | ||
119 | } | ||
120 | } | ||
121 | |||
122 | /*********************************************************** | ||
123 | * Confirm resetting of settings, used in general_settings() | ||
124 | **********************************************************/ | ||
125 | void confirm_reset(void){ | ||
126 | int result=0; | ||
127 | |||
128 | rb->set_option("Reset all settings?", &result, INT, noyes_text, 2, NULL); | ||
129 | |||
130 | if(result == 1){ /* reset! */ | ||
131 | clock_settings_reset(&clock_settings); | ||
132 | rb->splash(HZ, "Settings reset!"); | ||
133 | } | ||
134 | else | ||
135 | rb->splash(HZ, "Settings NOT reset."); | ||
136 | } | ||
137 | |||
138 | /************************************ | ||
139 | * General settings. Reset, save, etc | ||
140 | ***********************************/ | ||
141 | void menu_general_settings(void){ | ||
142 | int selection=0, result=0; | ||
143 | |||
144 | MENUITEM_STRINGLIST(menu,"General Settings",NULL, | ||
145 | "Hour format","Date format","Show Counter", | ||
146 | "Reset Settings","Save Settings Now", | ||
147 | "Save On Exit","Backlight Settings", | ||
148 | "Idle Poweroff (temporary)"); | ||
149 | |||
150 | while(result>=0){ | ||
151 | result=rb->do_menu(&menu, &selection); | ||
152 | switch(result){ | ||
153 | case 0: | ||
154 | rb->set_option("Hour format", | ||
155 | &clock_settings.general.hour_format, | ||
156 | INT, hour_format_text, 2, NULL); | ||
157 | break; | ||
158 | case 1: | ||
159 | rb->set_option("Date format", | ||
160 | &clock_settings.general.date_format, | ||
161 | INT, date_format_text, 4, NULL); | ||
162 | break; | ||
163 | case 2: | ||
164 | rb->set_option("Show Counter", &clock_settings.general.show_counter, | ||
165 | BOOL, noyes_text, 2, NULL); | ||
166 | break; | ||
167 | case 3: | ||
168 | confirm_reset(); | ||
169 | break; | ||
170 | |||
171 | case 4: | ||
172 | save_settings_wo_gui(); | ||
173 | rb->splash(HZ, "Settings saved"); | ||
174 | break; | ||
175 | |||
176 | case 5: | ||
177 | rb->set_option("Save On Exit", | ||
178 | &clock_settings.general.save_settings, | ||
179 | BOOL, noyes_text, 2, NULL); | ||
180 | |||
181 | /* if we no longer save on exit, | ||
182 | we better save now to remember that */ | ||
183 | if(!clock_settings.general.save_settings) | ||
184 | save_settings_wo_gui(); | ||
185 | break; | ||
186 | case 6: | ||
187 | rb->set_option("Backlight Settings", | ||
188 | &clock_settings.general.backlight, | ||
189 | INT, backlight_settings_text, 3, NULL); | ||
190 | apply_backlight_setting(clock_settings.general.backlight); | ||
191 | break; | ||
192 | |||
193 | case 7: | ||
194 | rb->set_option("Idle Poweroff (temporary)", | ||
195 | &clock_settings.general.idle_poweroff, | ||
196 | BOOL, idle_poweroff_text, 2, NULL); | ||
197 | break; | ||
198 | } | ||
199 | } | ||
200 | } | ||
201 | |||
202 | /*********** | ||
203 | * Main menu | ||
204 | **********/ | ||
205 | bool main_menu(void){ | ||
206 | int selection=0; | ||
207 | bool done = false; | ||
208 | bool exit_clock=false; | ||
209 | |||
210 | MENUITEM_STRINGLIST(menu,"Clock Menu",NULL,"View Clock","Mode Selector", | ||
211 | "Mode Settings","General Settings","Quit"); | ||
212 | |||
213 | while(!done){ | ||
214 | switch(rb->do_menu(&menu, &selection)){ | ||
215 | case 0: | ||
216 | done = true; | ||
217 | break; | ||
218 | |||
219 | case 1: | ||
220 | done=menu_mode_selector(); | ||
221 | break; | ||
222 | |||
223 | case 2: | ||
224 | switch(clock_settings.mode){ | ||
225 | case ANALOG: menu_analog_settings();break; | ||
226 | case DIGITAL: menu_digital_settings();break; | ||
227 | case BINARY: /* no settings */;break; | ||
228 | } | ||
229 | break; | ||
230 | |||
231 | case 3: | ||
232 | menu_general_settings(); | ||
233 | break; | ||
234 | |||
235 | case 4: | ||
236 | exit_clock = true; | ||
237 | done = true; | ||
238 | break; | ||
239 | |||
240 | default: | ||
241 | done=true; | ||
242 | break; | ||
243 | } | ||
244 | } | ||
245 | return(exit_clock); | ||
246 | } | ||
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 @@ | |||
1 | |||
2 | #ifndef _CLOCK_MENU_ | ||
3 | #define _CLOCK_MENU_ | ||
4 | |||
5 | bool main_menu(void); | ||
6 | |||
7 | #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 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ | ||
9 | * | ||
10 | * Copyright (C) 2007 Copyright Kévin Ferrare based on Zakk Roberts's work | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #include "clock.h" | ||
21 | #include "clock_bitmaps.h" | ||
22 | #include "clock_draw.h" | ||
23 | #include "clock_settings.h" | ||
24 | #include "picture.h" | ||
25 | |||
26 | static int max_skin[]={ | ||
27 | [ANALOG]=2, | ||
28 | [BINARY]=3, | ||
29 | [DIGITAL]=2, | ||
30 | }; | ||
31 | |||
32 | enum message{ | ||
33 | MESSAGE_LOADING, | ||
34 | MESSAGE_LOADED, | ||
35 | MESSAGE_ERRLOAD, | ||
36 | MESSAGE_SAVING, | ||
37 | MESSAGE_SAVED, | ||
38 | MESSAGE_ERRSAVE | ||
39 | }; | ||
40 | |||
41 | enum settings_file_status{ | ||
42 | LOADED, ERRLOAD, | ||
43 | SAVED, ERRSAVE | ||
44 | }; | ||
45 | |||
46 | struct clock_settings clock_settings; | ||
47 | |||
48 | void clock_settings_reset(struct clock_settings* settings){ | ||
49 | settings->mode = ANALOG; | ||
50 | int i; | ||
51 | for(i=0;i<NB_CLOCK_MODES;i++){ | ||
52 | settings->skin[i]=0; | ||
53 | } | ||
54 | settings->general.hour_format = H12; | ||
55 | settings->general.date_format = EUROPEAN; | ||
56 | settings->general.show_counter = true; | ||
57 | settings->general.save_settings = true; | ||
58 | settings->general.idle_poweroff=true; | ||
59 | settings->general.backlight = ROCKBOX_SETTING; | ||
60 | |||
61 | settings->analog.show_date = false; | ||
62 | settings->analog.show_seconds = true; | ||
63 | settings->analog.show_border = true; | ||
64 | |||
65 | settings->digital.show_seconds = true; | ||
66 | settings->digital.blinkcolon = false; | ||
67 | apply_backlight_setting(settings->general.backlight); | ||
68 | } | ||
69 | |||
70 | void apply_backlight_setting(int backlight_setting) | ||
71 | { | ||
72 | if(backlight_setting == ALWAS_OFF) | ||
73 | rb->backlight_set_timeout(0); | ||
74 | else if(backlight_setting == ROCKBOX_SETTING) | ||
75 | rb->backlight_set_timeout(rb->global_settings->backlight_timeout); | ||
76 | else if(backlight_setting == ALWAYS_ON) | ||
77 | rb->backlight_set_timeout(1); | ||
78 | } | ||
79 | |||
80 | void clock_settings_skin_next(struct clock_settings* settings){ | ||
81 | settings->skin[settings->mode]++; | ||
82 | if(settings->skin[settings->mode]>=max_skin[settings->mode]) | ||
83 | settings->skin[settings->mode]=0; | ||
84 | } | ||
85 | |||
86 | void clock_settings_skin_previous(struct clock_settings* settings){ | ||
87 | settings->skin[settings->mode]--; | ||
88 | if(settings->skin[settings->mode]<0) | ||
89 | settings->skin[settings->mode]=max_skin[settings->mode]-1; | ||
90 | } | ||
91 | |||
92 | enum settings_file_status clock_settings_load(struct clock_settings* settings, | ||
93 | char* filename){ | ||
94 | int fd = rb->open(filename, O_RDONLY); | ||
95 | if(fd >= 0){ /* does file exist? */ | ||
96 | /* basic consistency check */ | ||
97 | if(rb->filesize(fd) == sizeof(*settings)){ | ||
98 | rb->read(fd, settings, sizeof(*settings)); | ||
99 | rb->close(fd); | ||
100 | apply_backlight_setting(settings->general.backlight); | ||
101 | return(LOADED); | ||
102 | } | ||
103 | } | ||
104 | /* Initializes the settings with default values at least */ | ||
105 | clock_settings_reset(settings); | ||
106 | return(ERRLOAD); | ||
107 | } | ||
108 | |||
109 | enum settings_file_status clock_settings_save(struct clock_settings* settings, | ||
110 | char* filename){ | ||
111 | int fd = rb->creat(filename); | ||
112 | if(fd >= 0){ /* does file exist? */ | ||
113 | rb->write (fd, settings, sizeof(*settings)); | ||
114 | rb->close(fd); | ||
115 | return(SAVED); | ||
116 | } | ||
117 | return(ERRSAVE); | ||
118 | } | ||
119 | |||
120 | void draw_logo(struct screen* display){ | ||
121 | #ifdef HAVE_LCD_COLOR | ||
122 | if(display->is_color){ | ||
123 | display->set_foreground(LCD_BLACK); | ||
124 | display->set_background(LCD_RGBPACK(180,200,230)); | ||
125 | } | ||
126 | #endif | ||
127 | |||
128 | const struct picture* logo = &(logos[display->screen_type]); | ||
129 | display->clear_display(); | ||
130 | picture_draw(display, logo, 0, 0); | ||
131 | } | ||
132 | |||
133 | void draw_message(struct screen* display, int msg, int y){ | ||
134 | const struct picture* message = &(messages[display->screen_type]); | ||
135 | display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); | ||
136 | display->fillrect(0, display->height-message->height, | ||
137 | display->width, message->height); | ||
138 | display->set_drawmode(DRMODE_SOLID); | ||
139 | vertical_picture_draw_sprite(display, message, msg, | ||
140 | 0, display->height-(message->height*y)); | ||
141 | } | ||
142 | |||
143 | void load_settings(void){ | ||
144 | int i; | ||
145 | struct screen* display; | ||
146 | FOR_NB_SCREENS(i){ | ||
147 | display=rb->screens[i]; | ||
148 | display->clear_display(); | ||
149 | draw_logo(display); | ||
150 | draw_message(display, MESSAGE_LOADING, 1); | ||
151 | display->update(); | ||
152 | } | ||
153 | |||
154 | enum settings_file_status load_status= | ||
155 | clock_settings_load(&clock_settings, settings_filename); | ||
156 | |||
157 | FOR_NB_SCREENS(i){ | ||
158 | display=rb->screens[i]; | ||
159 | if(load_status==LOADED) | ||
160 | draw_message(display, MESSAGE_LOADED, 1); | ||
161 | else | ||
162 | draw_message(display, MESSAGE_ERRLOAD, 1); | ||
163 | display->update(); | ||
164 | } | ||
165 | #ifndef SIMULATOR | ||
166 | rb->ata_sleep(); | ||
167 | #endif | ||
168 | rb->sleep(HZ); | ||
169 | } | ||
170 | |||
171 | void save_settings(void){ | ||
172 | int i; | ||
173 | struct screen* display; | ||
174 | FOR_NB_SCREENS(i){ | ||
175 | display=rb->screens[i]; | ||
176 | display->clear_display(); | ||
177 | draw_logo(display); | ||
178 | |||
179 | draw_message(display, MESSAGE_SAVING, 1); | ||
180 | |||
181 | display->update(); | ||
182 | } | ||
183 | enum settings_file_status load_status= | ||
184 | clock_settings_save(&clock_settings, settings_filename); | ||
185 | |||
186 | FOR_NB_SCREENS(i){ | ||
187 | display=rb->screens[i]; | ||
188 | |||
189 | if(load_status==SAVED) | ||
190 | draw_message(display, MESSAGE_SAVED, 1); | ||
191 | else | ||
192 | draw_message(display, MESSAGE_ERRSAVE, 1); | ||
193 | display->update(); | ||
194 | } | ||
195 | rb->sleep(HZ); | ||
196 | } | ||
197 | |||
198 | void save_settings_wo_gui(void){ | ||
199 | clock_settings_save(&clock_settings, settings_filename); | ||
200 | } | ||
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 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: jackpot.c 14034 2007-07-28 05:42:55Z kevin $ | ||
9 | * | ||
10 | * Copyright (C) 2007 Copyright Kévin Ferrare based on Zakk Roberts's work | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #ifndef _CLOCK_SETTINGS_ | ||
21 | #define _CLOCK_SETTINGS_ | ||
22 | #include "plugin.h" | ||
23 | |||
24 | enum date_format{ | ||
25 | NONE, | ||
26 | ENGLISH, | ||
27 | EUROPEAN, | ||
28 | JAPANESE, | ||
29 | }; | ||
30 | |||
31 | enum hour_format{ | ||
32 | H24, | ||
33 | H12 | ||
34 | }; | ||
35 | |||
36 | enum clock_modes{ | ||
37 | ANALOG, | ||
38 | DIGITAL, | ||
39 | BINARY, | ||
40 | NB_CLOCK_MODES | ||
41 | }; | ||
42 | |||
43 | enum backlight_handling{ | ||
44 | ALWAS_OFF, | ||
45 | ROCKBOX_SETTING, | ||
46 | ALWAYS_ON | ||
47 | }; | ||
48 | |||
49 | |||
50 | struct general_settings{ | ||
51 | int hour_format;/* 0:24h, 1:12h*/ | ||
52 | int date_format; | ||
53 | bool show_counter; | ||
54 | bool save_settings; | ||
55 | bool idle_poweroff; | ||
56 | int backlight; | ||
57 | }; | ||
58 | |||
59 | struct analog_settings{ | ||
60 | bool show_date; | ||
61 | bool show_seconds; | ||
62 | bool show_border; | ||
63 | }; | ||
64 | |||
65 | struct digital_settings{ | ||
66 | int show_seconds; | ||
67 | int blinkcolon; | ||
68 | }; | ||
69 | |||
70 | struct clock_settings{ | ||
71 | int mode; /* clock mode */ | ||
72 | int skin[NB_CLOCK_MODES];/* how does each mode looks like */ | ||
73 | struct general_settings general; | ||
74 | struct analog_settings analog; | ||
75 | struct digital_settings digital; | ||
76 | }; | ||
77 | |||
78 | extern struct clock_settings clock_settings; | ||
79 | |||
80 | /* settings are saved to this location */ | ||
81 | #define settings_filename "/.rockbox/rocks/.clock_settings" | ||
82 | |||
83 | void clock_settings_skin_next(struct clock_settings* settings); | ||
84 | void clock_settings_skin_previous(struct clock_settings* settings); | ||
85 | void apply_backlight_setting(int backlight_setting); | ||
86 | void clock_settings_reset(struct clock_settings* settings); | ||
87 | void load_settings(void); | ||
88 | void save_settings(void); | ||
89 | void save_settings_wo_gui(void); | ||
90 | |||
91 | #endif /* _CLOCK_SETTINGS_ */ | ||