2007-08-04 03:01:46 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id: clock.c 14095 2007-07-31 10:53:53Z nls $
|
|
|
|
*
|
2008-05-05 10:32:46 +00:00
|
|
|
* Copyright (C) 2007 Kévin Ferrare, graphic design 2003 Zakk Roberts
|
2007-08-04 03:01:46 +00:00
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2007-08-04 03:01:46 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "plugin.h"
|
|
|
|
#include "time.h"
|
2008-11-20 11:27:31 +00:00
|
|
|
#include "lib/pluginlib_actions.h"
|
|
|
|
#include "lib/xlcd.h"
|
2007-08-04 03:01:46 +00:00
|
|
|
|
|
|
|
#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,
|
2008-01-23 08:25:04 +00:00
|
|
|
generic_increase_decrease,
|
2007-08-04 03:01:46 +00:00
|
|
|
generic_directions,
|
|
|
|
#if NB_SCREENS == 2
|
|
|
|
remote_directions
|
|
|
|
#endif
|
|
|
|
};
|
2008-01-23 08:25:04 +00:00
|
|
|
#define PLA_ARRAY_COUNT sizeof(plugin_contexts)/sizeof(plugin_contexts[0])
|
2007-08-05 14:38:33 +00:00
|
|
|
|
2007-08-04 03:01:46 +00:00
|
|
|
#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
|
2007-08-05 14:38:33 +00:00
|
|
|
#define ACTION_MODE_NEXT_REPEAT PLA_RIGHT_REPEAT
|
2007-08-04 03:01:46 +00:00
|
|
|
#define ACTION_MODE_PREV PLA_LEFT
|
2007-08-05 14:38:33 +00:00
|
|
|
#define ACTION_MODE_PREV_REPEAT PLA_LEFT_REPEAT
|
2008-01-23 08:25:04 +00:00
|
|
|
#define ACTION_SKIN_NEXT PLA_INC
|
|
|
|
#define ACTION_SKIN_NEXT_REPEAT PLA_INC_REPEAT
|
|
|
|
#define ACTION_SKIN_PREV PLA_DEC
|
|
|
|
#define ACTION_SKIN_PREV_REPEAT PLA_DEC_REPEAT
|
2007-08-04 03:01:46 +00:00
|
|
|
|
2008-05-13 09:57:56 +00:00
|
|
|
extern const struct plugin_api* rb;
|
2007-08-04 03:01:46 +00:00
|
|
|
|
|
|
|
/**************************
|
|
|
|
* 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
|
|
|
|
**********************************************************************/
|
2008-05-13 09:57:56 +00:00
|
|
|
enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter){
|
2007-08-04 03:01:46 +00:00
|
|
|
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
|
|
|
|
************************/
|
2008-01-23 08:25:04 +00:00
|
|
|
button = pluginlib_getaction(rb, HZ/10, plugin_contexts, PLA_ARRAY_COUNT);
|
2007-08-04 03:01:46 +00:00
|
|
|
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;
|
|
|
|
|
2007-08-05 14:38:33 +00:00
|
|
|
case ACTION_MODE_NEXT_REPEAT:
|
2007-08-04 03:01:46 +00:00
|
|
|
case ACTION_MODE_NEXT:
|
|
|
|
clock_settings.mode++;
|
|
|
|
if(clock_settings.mode >= NB_CLOCK_MODES)
|
|
|
|
clock_settings.mode = 0;
|
|
|
|
break;
|
|
|
|
|
2007-08-05 14:38:33 +00:00
|
|
|
case ACTION_MODE_PREV_REPEAT:
|
2007-08-04 03:01:46 +00:00
|
|
|
case ACTION_MODE_PREV:
|
|
|
|
clock_settings.mode--;
|
|
|
|
if(clock_settings.mode < 0)
|
|
|
|
clock_settings.mode = NB_CLOCK_MODES-1;
|
|
|
|
break;
|
2007-08-05 14:38:33 +00:00
|
|
|
case ACTION_SKIN_PREV_REPEAT:
|
2007-08-04 03:01:46 +00:00
|
|
|
case ACTION_SKIN_PREV:
|
|
|
|
clock_settings_skin_next(&clock_settings);
|
|
|
|
break;
|
2007-08-05 14:38:33 +00:00
|
|
|
case ACTION_SKIN_NEXT_REPEAT:
|
2007-08-04 03:01:46 +00:00
|
|
|
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:
|
|
|
|
exit_clock=true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if(rb->default_event_handler_ex(button, cleanup, NULL)
|
|
|
|
== SYS_USB_CONNECTED)
|
|
|
|
return PLUGIN_USB_CONNECTED;
|
2007-08-04 15:13:28 +00:00
|
|
|
if(time.second != last_second){
|
|
|
|
last_second=time.second;
|
|
|
|
redraw=true;
|
|
|
|
}else
|
|
|
|
redraw=false;
|
2007-08-04 03:01:46 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-08-04 15:13:28 +00:00
|
|
|
|
2007-08-04 03:01:46 +00:00
|
|
|
if(redraw){
|
|
|
|
clock_draw_set_colors();
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
clock_draw(rb->screens[i], &time, &counter);
|
|
|
|
redraw=false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup(NULL);
|
|
|
|
return PLUGIN_OK;
|
|
|
|
}
|