diff options
author | Kevin Ferrare <kevin@rockbox.org> | 2007-08-04 03:01:46 +0000 |
---|---|---|
committer | Kevin Ferrare <kevin@rockbox.org> | 2007-08-04 03:01:46 +0000 |
commit | 93b2f9fd447b73fff736d71826880ef9ac64bd94 (patch) | |
tree | 1a4f54016c312738d66fb9dd2348ea0ef14f1255 /apps/plugins/clock | |
parent | ffbbc60f38ddc8aeadc9cea1102077e22ca84a1a (diff) |
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
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 @@ +# __________ __ ___. +# 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; i<nb_bits; i++){ + if((number & mask) !=0) + buffer[nb_bits-i-1]='1'; + else + buffer[nb_bits-i-1]='0'; + mask=mask<<1; + } +} + +void binary_clock_draw(struct screen* display, struct time* time, int skin){ + int lines_values[]={ + time->hour,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;i<NB_CLOCK_MODES;i++){ + settings->skin[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_ */ |