2002-06-27 00:20:00 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 by wavey@wavey.org
|
2002-07-15 11:02:12 +00:00
|
|
|
* RTC config saving code (C) 2002 by hessu@hes.iki.fi
|
2002-06-27 00:20:00 +00:00
|
|
|
*
|
|
|
|
* 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 <stdio.h>
|
|
|
|
#include "config.h"
|
2002-07-28 16:09:44 +00:00
|
|
|
#include "kernel.h"
|
2002-06-27 00:20:00 +00:00
|
|
|
#include "settings.h"
|
|
|
|
#include "disk.h"
|
|
|
|
#include "panic.h"
|
|
|
|
#include "debug.h"
|
2002-06-27 01:08:11 +00:00
|
|
|
#include "button.h"
|
|
|
|
#include "lcd.h"
|
2002-06-28 11:54:47 +00:00
|
|
|
#include "mpeg.h"
|
2002-07-15 11:02:12 +00:00
|
|
|
#include "string.h"
|
2002-07-28 16:09:44 +00:00
|
|
|
#include "ata.h"
|
2002-08-13 17:16:09 +00:00
|
|
|
#include "fat.h"
|
2002-07-28 16:09:44 +00:00
|
|
|
#include "power.h"
|
2002-07-30 07:56:16 +00:00
|
|
|
#include "backlight.h"
|
2002-08-06 10:52:51 +00:00
|
|
|
#include "powermgmt.h"
|
2002-08-20 19:37:00 +00:00
|
|
|
#include "status.h"
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
#include "icons.h"
|
|
|
|
#endif
|
2002-06-27 00:20:00 +00:00
|
|
|
|
|
|
|
struct user_settings global_settings;
|
2002-08-30 13:24:03 +00:00
|
|
|
char rockboxdir[] = "/.rockbox/"; /* config/font/data file directory */
|
2002-06-27 00:20:00 +00:00
|
|
|
|
2002-08-14 21:30:06 +00:00
|
|
|
#define CONFIG_BLOCK_VERSION 1
|
2002-08-16 14:41:47 +00:00
|
|
|
#define CONFIG_BLOCK_SIZE 512
|
|
|
|
#define RTC_BLOCK_SIZE 44
|
2002-08-13 17:16:09 +00:00
|
|
|
|
2002-07-15 11:02:12 +00:00
|
|
|
/********************************************
|
|
|
|
|
|
|
|
Config block as saved on the battery-packed RTC user RAM memory block
|
|
|
|
of 44 bytes, starting at offset 0x14 of the RTC memory space.
|
|
|
|
|
|
|
|
offset abs
|
|
|
|
0x00 0x14 "Roc" header signature: 0x52 0x6f 0x63
|
|
|
|
0x03 0x17 <version byte: 0x0>
|
|
|
|
0x04 0x18 <volume byte>
|
|
|
|
0x05 0x19 <balance byte>
|
|
|
|
0x06 0x1a <bass byte>
|
|
|
|
0x07 0x1b <treble byte>
|
|
|
|
0x08 0x1c <loudness byte>
|
|
|
|
0x09 0x1d <bass boost byte>
|
|
|
|
0x0a 0x1e <contrast byte>
|
|
|
|
0x0b 0x1f <backlight byte>
|
|
|
|
0x0c 0x20 <poweroff timer byte>
|
|
|
|
0x0d 0x21 <resume settings byte>
|
2002-08-28 05:34:28 +00:00
|
|
|
0x0e 0x22 <shuffle,mp3filter,sort_case,discharge,statusbar,show_hidden>
|
2002-07-15 11:02:12 +00:00
|
|
|
0x0f 0x23 <scroll speed & WPS display byte>
|
2002-08-29 04:50:39 +00:00
|
|
|
0x10 0x24 <ff/rewind accleration rate>
|
2002-07-25 15:55:22 +00:00
|
|
|
0x11 0x25 <AVC byte>
|
2002-08-16 14:41:47 +00:00
|
|
|
0x12 0x26 <(int) Resume playlist index, or -1 if no playlist resume>
|
2002-08-28 05:34:28 +00:00
|
|
|
0x16 0x2a <(int) Byte offset into resume file>
|
2002-08-28 19:34:07 +00:00
|
|
|
0x1a 0x2e <time until disk spindown>
|
2002-08-06 10:52:51 +00:00
|
|
|
|
2002-07-15 11:02:12 +00:00
|
|
|
<all unused space filled with 0xff>
|
|
|
|
|
|
|
|
the geeky but useless statistics part:
|
|
|
|
0x24 <total uptime in seconds: 32 bits uint, actually unused for now>
|
2002-08-06 10:52:51 +00:00
|
|
|
|
2002-07-15 11:02:12 +00:00
|
|
|
0x2a <checksum 2 bytes: xor of 0x0-0x29>
|
|
|
|
|
|
|
|
Config memory is reset to 0xff and initialized with 'factory defaults' if
|
|
|
|
a valid header & checksum is not found. Config version number is only
|
|
|
|
increased when information is _relocated_ or space is _reused_ so that old
|
|
|
|
versions can read and modify configuration changed by new versions. New
|
|
|
|
versions should check for the value of '0xff' in each config memory
|
|
|
|
location used, and reset the setting in question with a factory default if
|
|
|
|
needed. Memory locations not used by a given version should not be
|
|
|
|
modified unless the header & checksum test fails.
|
|
|
|
|
2002-08-16 14:41:47 +00:00
|
|
|
|
|
|
|
Rest of config block, only saved to disk:
|
|
|
|
|
|
|
|
0xF8 (int) Playlist shuffle seed
|
|
|
|
0xFC (char[260]) Resume playlist (path/to/dir or path/to/playlist.m3u)
|
|
|
|
|
2002-07-15 11:02:12 +00:00
|
|
|
*************************************/
|
|
|
|
|
|
|
|
#include "rtc.h"
|
2002-08-16 14:41:47 +00:00
|
|
|
static unsigned char config_block[CONFIG_BLOCK_SIZE];
|
2002-07-15 11:02:12 +00:00
|
|
|
|
|
|
|
/*
|
2002-08-16 14:41:47 +00:00
|
|
|
* Calculates the checksum for the config block and returns it
|
2002-07-15 11:02:12 +00:00
|
|
|
*/
|
|
|
|
|
2002-08-16 14:41:47 +00:00
|
|
|
static unsigned short calculate_config_checksum(unsigned char* buf)
|
2002-07-15 11:02:12 +00:00
|
|
|
{
|
2002-08-13 17:16:09 +00:00
|
|
|
unsigned int i;
|
|
|
|
unsigned char cksum[2];
|
2002-07-15 11:02:12 +00:00
|
|
|
cksum[0] = cksum[1] = 0;
|
|
|
|
|
2002-08-16 14:41:47 +00:00
|
|
|
for (i=0; i < RTC_BLOCK_SIZE - 2; i+=2 ) {
|
|
|
|
cksum[0] ^= buf[i];
|
|
|
|
cksum[1] ^= buf[i+1];
|
2002-07-15 11:02:12 +00:00
|
|
|
}
|
2002-08-13 17:16:09 +00:00
|
|
|
|
|
|
|
return (cksum[0] << 8) | cksum[1];
|
2002-07-15 11:02:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* initialize the config block buffer
|
|
|
|
*/
|
|
|
|
static void init_config_buffer( void )
|
|
|
|
{
|
|
|
|
DEBUGF( "init_config_buffer()\n" );
|
|
|
|
|
|
|
|
/* reset to 0xff - all unused */
|
2002-08-16 14:41:47 +00:00
|
|
|
memset(config_block, 0xff, CONFIG_BLOCK_SIZE);
|
2002-07-15 11:02:12 +00:00
|
|
|
/* insert header */
|
2002-08-16 14:41:47 +00:00
|
|
|
config_block[0] = 'R';
|
|
|
|
config_block[1] = 'o';
|
|
|
|
config_block[2] = 'c';
|
|
|
|
config_block[3] = CONFIG_BLOCK_VERSION;
|
2002-07-15 11:02:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-08-13 17:16:09 +00:00
|
|
|
* save the config block buffer to disk or RTC RAM
|
2002-07-15 11:02:12 +00:00
|
|
|
*/
|
|
|
|
static int save_config_buffer( void )
|
|
|
|
{
|
2002-08-13 17:16:09 +00:00
|
|
|
unsigned short chksum;
|
|
|
|
#ifdef HAVE_RTC
|
|
|
|
unsigned int i;
|
|
|
|
#endif
|
|
|
|
|
2002-07-15 11:02:12 +00:00
|
|
|
DEBUGF( "save_config_buffer()\n" );
|
|
|
|
|
|
|
|
/* update the checksum in the end of the block before saving */
|
2002-08-16 14:41:47 +00:00
|
|
|
chksum = calculate_config_checksum(config_block);
|
|
|
|
config_block[ RTC_BLOCK_SIZE - 2 ] = chksum >> 8;
|
|
|
|
config_block[ RTC_BLOCK_SIZE - 1 ] = chksum & 0xff;
|
2002-08-13 17:16:09 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_RTC
|
2002-07-15 11:02:12 +00:00
|
|
|
/* FIXME: okay, it _would_ be cleaner and faster to implement rtc_write so
|
|
|
|
that it would write a number of bytes at a time since the RTC chip
|
|
|
|
supports that, but this will have to do for now 8-) */
|
2002-08-16 14:41:47 +00:00
|
|
|
for (i=0; i < RTC_BLOCK_SIZE; i++ ) {
|
|
|
|
int r = rtc_write(0x14+i, config_block[i]);
|
2002-07-15 11:02:12 +00:00
|
|
|
if (r) {
|
2002-08-13 17:33:23 +00:00
|
|
|
DEBUGF( "save_config_buffer: rtc_write failed at addr 0x%02x: %d\n", 14+i, r );
|
2002-07-15 11:02:12 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
2002-08-13 17:16:09 +00:00
|
|
|
|
2002-08-16 14:41:47 +00:00
|
|
|
#endif
|
2002-08-13 17:16:09 +00:00
|
|
|
|
2002-08-16 14:41:47 +00:00
|
|
|
if (fat_startsector() != 0)
|
|
|
|
ata_delayed_write( 61, config_block);
|
2002-08-13 17:16:09 +00:00
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
|
2002-07-15 11:02:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-06-27 00:20:00 +00:00
|
|
|
/*
|
2002-08-13 17:16:09 +00:00
|
|
|
* load the config block buffer from disk or RTC RAM
|
2002-06-27 00:20:00 +00:00
|
|
|
*/
|
2002-07-15 11:02:12 +00:00
|
|
|
static int load_config_buffer( void )
|
2002-06-27 00:20:00 +00:00
|
|
|
{
|
2002-08-13 17:16:09 +00:00
|
|
|
unsigned short chksum;
|
2002-08-16 14:41:47 +00:00
|
|
|
bool correct = false;
|
2002-08-13 17:16:09 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_RTC
|
|
|
|
unsigned int i;
|
2002-08-16 14:41:47 +00:00
|
|
|
unsigned char rtc_block[RTC_BLOCK_SIZE];
|
2002-08-13 17:16:09 +00:00
|
|
|
#endif
|
2002-07-15 11:02:12 +00:00
|
|
|
|
|
|
|
DEBUGF( "load_config_buffer()\n" );
|
2002-08-13 17:16:09 +00:00
|
|
|
|
2002-08-16 14:41:47 +00:00
|
|
|
if (fat_startsector() != 0) {
|
|
|
|
ata_read_sectors( 61, 1, config_block);
|
|
|
|
|
|
|
|
/* calculate the checksum, check it and the header */
|
|
|
|
chksum = calculate_config_checksum(config_block);
|
|
|
|
|
|
|
|
if (config_block[0] == 'R' &&
|
|
|
|
config_block[1] == 'o' &&
|
|
|
|
config_block[2] == 'c' &&
|
|
|
|
config_block[3] == CONFIG_BLOCK_VERSION &&
|
|
|
|
(chksum >> 8) == config_block[RTC_BLOCK_SIZE - 2] &&
|
|
|
|
(chksum & 0xff) == config_block[RTC_BLOCK_SIZE - 1])
|
|
|
|
{
|
|
|
|
DEBUGF( "load_config_buffer: header & checksum test ok\n" );
|
|
|
|
correct = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-13 17:16:09 +00:00
|
|
|
#ifdef HAVE_RTC
|
2002-08-16 14:41:47 +00:00
|
|
|
/* read rtc block */
|
|
|
|
for (i=0; i < RTC_BLOCK_SIZE; i++ )
|
|
|
|
rtc_block[i] = rtc_read(0x14+i);
|
|
|
|
|
|
|
|
chksum = calculate_config_checksum(rtc_block);
|
2002-08-13 17:16:09 +00:00
|
|
|
|
2002-08-16 14:41:47 +00:00
|
|
|
/* if rtc block is ok, use that */
|
|
|
|
if (rtc_block[0] == 'R' &&
|
|
|
|
rtc_block[1] == 'o' &&
|
|
|
|
rtc_block[2] == 'c' &&
|
|
|
|
rtc_block[3] == CONFIG_BLOCK_VERSION &&
|
|
|
|
(chksum >> 8) == rtc_block[RTC_BLOCK_SIZE - 2] &&
|
|
|
|
(chksum & 0xff) == rtc_block[RTC_BLOCK_SIZE - 1])
|
2002-08-13 17:16:09 +00:00
|
|
|
{
|
2002-08-16 14:41:47 +00:00
|
|
|
memcpy(config_block, rtc_block, RTC_BLOCK_SIZE);
|
|
|
|
correct = true;
|
2002-08-13 17:16:09 +00:00
|
|
|
}
|
2002-08-16 14:41:47 +00:00
|
|
|
#endif
|
2002-07-28 16:09:44 +00:00
|
|
|
|
2002-08-16 14:41:47 +00:00
|
|
|
if ( !correct ) {
|
|
|
|
/* if checksum is not valid, clear the config buffer */
|
|
|
|
DEBUGF( "load_config_buffer: header & checksum test failed\n" );
|
|
|
|
init_config_buffer();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2002-07-28 16:09:44 +00:00
|
|
|
}
|
|
|
|
|
2002-06-27 00:20:00 +00:00
|
|
|
/*
|
2002-07-15 11:02:12 +00:00
|
|
|
* persist all runtime user settings to disk or RTC RAM
|
2002-06-27 00:20:00 +00:00
|
|
|
*/
|
2002-07-15 11:02:12 +00:00
|
|
|
int settings_save( void )
|
2002-06-27 00:20:00 +00:00
|
|
|
{
|
2002-07-15 11:02:12 +00:00
|
|
|
DEBUGF( "settings_save()\n" );
|
|
|
|
|
|
|
|
/* update the config block buffer with current
|
|
|
|
settings and save the block in the RTC */
|
2002-08-16 14:41:47 +00:00
|
|
|
config_block[0x4] = (unsigned char)global_settings.volume;
|
|
|
|
config_block[0x5] = (unsigned char)global_settings.balance;
|
|
|
|
config_block[0x6] = (unsigned char)global_settings.bass;
|
|
|
|
config_block[0x7] = (unsigned char)global_settings.treble;
|
|
|
|
config_block[0x8] = (unsigned char)global_settings.loudness;
|
|
|
|
config_block[0x9] = (unsigned char)global_settings.bass_boost;
|
2002-07-15 11:02:12 +00:00
|
|
|
|
2002-08-16 14:41:47 +00:00
|
|
|
config_block[0xa] = (unsigned char)global_settings.contrast;
|
|
|
|
config_block[0xb] = (unsigned char)global_settings.backlight;
|
|
|
|
config_block[0xc] = (unsigned char)global_settings.poweroff;
|
|
|
|
config_block[0xd] = (unsigned char)global_settings.resume;
|
2002-07-15 11:02:12 +00:00
|
|
|
|
2002-08-16 14:41:47 +00:00
|
|
|
config_block[0xe] = (unsigned char)
|
2002-07-15 11:02:12 +00:00
|
|
|
((global_settings.playlist_shuffle & 1) |
|
2002-07-22 16:39:17 +00:00
|
|
|
((global_settings.mp3filter & 1) << 1) |
|
2002-08-06 10:52:51 +00:00
|
|
|
((global_settings.sort_case & 1) << 2) |
|
2002-08-07 10:50:46 +00:00
|
|
|
((global_settings.discharge & 1) << 3) |
|
2002-08-22 15:47:30 +00:00
|
|
|
((global_settings.statusbar & 1) << 4) |
|
2002-08-30 13:49:32 +00:00
|
|
|
((global_settings.show_hidden_files & 1) << 5) |
|
|
|
|
((global_settings.scrollbar & 1) << 6));
|
2002-07-15 11:02:12 +00:00
|
|
|
|
2002-08-16 14:41:47 +00:00
|
|
|
config_block[0xf] = (unsigned char)
|
2002-07-15 11:02:12 +00:00
|
|
|
((global_settings.scroll_speed << 3) |
|
|
|
|
(global_settings.wps_display & 7));
|
|
|
|
|
2002-08-29 04:50:39 +00:00
|
|
|
config_block[0x10] = (unsigned char)global_settings.ff_rewind_accel;
|
2002-08-16 14:41:47 +00:00
|
|
|
config_block[0x11] = (unsigned char)global_settings.avc;
|
2002-08-26 13:21:14 +00:00
|
|
|
config_block[0x1a] = (unsigned char)global_settings.disk_spindown;
|
|
|
|
|
2002-08-16 14:41:47 +00:00
|
|
|
memcpy(&config_block[0x12], &global_settings.resume_index, 4);
|
|
|
|
memcpy(&config_block[0x16], &global_settings.resume_offset, 4);
|
|
|
|
memcpy(&config_block[0xF8], &global_settings.resume_seed, 4);
|
|
|
|
|
|
|
|
memcpy(&config_block[0x24], &global_settings.total_uptime, 4);
|
|
|
|
strncpy(&config_block[0xFC], global_settings.resume_file, MAX_PATH);
|
2002-07-15 11:02:12 +00:00
|
|
|
|
2002-08-16 14:41:47 +00:00
|
|
|
DEBUGF("+Resume file %s\n",global_settings.resume_file);
|
|
|
|
DEBUGF("+Resume index %X offset %X\n",
|
|
|
|
global_settings.resume_index,
|
|
|
|
global_settings.resume_offset);
|
|
|
|
DEBUGF("+Resume shuffle %s seed %X\n",
|
|
|
|
global_settings.playlist_shuffle?"on":"off",
|
|
|
|
global_settings.resume_seed);
|
|
|
|
|
2002-07-28 16:09:44 +00:00
|
|
|
if(save_config_buffer())
|
|
|
|
{
|
|
|
|
lcd_clear_display();
|
|
|
|
#ifdef HAVE_LCD_CHARCELLS
|
|
|
|
lcd_puts(0, 0, "Save failed");
|
|
|
|
lcd_puts(0, 1, "Batt. low?");
|
|
|
|
#else
|
|
|
|
lcd_puts(4, 2, "Save failed");
|
|
|
|
lcd_puts(2, 4, "Is battery low?");
|
|
|
|
lcd_update();
|
|
|
|
#endif
|
|
|
|
sleep(HZ*2);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
2002-06-27 00:20:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-07-15 11:02:12 +00:00
|
|
|
* load settings from disk or RTC RAM
|
2002-06-27 00:20:00 +00:00
|
|
|
*/
|
2002-07-15 11:02:12 +00:00
|
|
|
void settings_load(void)
|
2002-06-27 00:20:00 +00:00
|
|
|
{
|
2002-07-15 11:02:12 +00:00
|
|
|
unsigned char c;
|
|
|
|
|
2002-06-27 00:20:00 +00:00
|
|
|
DEBUGF( "reload_all_settings()\n" );
|
|
|
|
|
|
|
|
/* populate settings with default values */
|
2002-07-15 11:02:12 +00:00
|
|
|
settings_reset();
|
2002-06-27 00:20:00 +00:00
|
|
|
|
2002-07-15 11:02:12 +00:00
|
|
|
/* load the buffer from the RTC (resets it to all-unused if the block
|
|
|
|
is invalid) and decode the settings which are set in the block */
|
|
|
|
if (!load_config_buffer()) {
|
2002-08-16 14:41:47 +00:00
|
|
|
if (config_block[0x4] != 0xFF)
|
|
|
|
global_settings.volume = config_block[0x4];
|
|
|
|
if (config_block[0x5] != 0xFF)
|
|
|
|
global_settings.balance = config_block[0x5];
|
|
|
|
if (config_block[0x6] != 0xFF)
|
|
|
|
global_settings.bass = config_block[0x6];
|
|
|
|
if (config_block[0x7] != 0xFF)
|
|
|
|
global_settings.treble = config_block[0x7];
|
|
|
|
if (config_block[0x8] != 0xFF)
|
|
|
|
global_settings.loudness = config_block[0x8];
|
|
|
|
if (config_block[0x9] != 0xFF)
|
|
|
|
global_settings.bass_boost = config_block[0x9];
|
2002-07-15 11:02:12 +00:00
|
|
|
|
2002-08-16 14:41:47 +00:00
|
|
|
if (config_block[0xa] != 0xFF) {
|
|
|
|
global_settings.contrast = config_block[0xa];
|
2002-08-13 17:16:09 +00:00
|
|
|
if ( global_settings.contrast < MIN_CONTRAST_SETTING )
|
2002-08-13 17:20:25 +00:00
|
|
|
global_settings.contrast = DEFAULT_CONTRAST_SETTING;
|
2002-08-13 17:16:09 +00:00
|
|
|
}
|
2002-08-16 14:41:47 +00:00
|
|
|
if (config_block[0xb] != 0xFF)
|
|
|
|
global_settings.backlight = config_block[0xb];
|
|
|
|
if (config_block[0xc] != 0xFF)
|
|
|
|
global_settings.poweroff = config_block[0xc];
|
|
|
|
if (config_block[0xd] != 0xFF)
|
|
|
|
global_settings.resume = config_block[0xd];
|
|
|
|
if (config_block[0xe] != 0xFF) {
|
|
|
|
global_settings.playlist_shuffle = config_block[0xe] & 1;
|
|
|
|
global_settings.mp3filter = (config_block[0xe] >> 1) & 1;
|
|
|
|
global_settings.sort_case = (config_block[0xe] >> 2) & 1;
|
|
|
|
global_settings.discharge = (config_block[0xe] >> 3) & 1;
|
|
|
|
global_settings.statusbar = (config_block[0xe] >> 4) & 1;
|
2002-08-22 15:47:30 +00:00
|
|
|
global_settings.show_hidden_files = (config_block[0xe] >> 5) & 1;
|
2002-08-30 13:49:32 +00:00
|
|
|
global_settings.scrollbar = (config_block[0xe] >> 6) & 1;
|
2002-07-15 11:02:12 +00:00
|
|
|
}
|
2002-08-06 10:52:51 +00:00
|
|
|
|
2002-08-16 14:41:47 +00:00
|
|
|
c = config_block[0xf] >> 3;
|
2002-07-15 11:02:12 +00:00
|
|
|
if (c != 31)
|
|
|
|
global_settings.scroll_speed = c;
|
|
|
|
|
2002-08-16 14:41:47 +00:00
|
|
|
c = config_block[0xf] & 7;
|
2002-07-15 11:02:12 +00:00
|
|
|
if (c != 7)
|
|
|
|
global_settings.wps_display = c;
|
2002-07-25 15:55:22 +00:00
|
|
|
|
2002-08-16 14:41:47 +00:00
|
|
|
if (config_block[0x10] != 0xFF)
|
2002-08-29 04:50:39 +00:00
|
|
|
global_settings.ff_rewind_accel = config_block[0x10];
|
2002-08-16 14:41:47 +00:00
|
|
|
|
|
|
|
if (config_block[0x11] != 0xFF)
|
|
|
|
global_settings.avc = config_block[0x11];
|
|
|
|
|
|
|
|
if (config_block[0x12] != 0xFF)
|
|
|
|
memcpy(&global_settings.resume_index, &config_block[0x12], 4);
|
|
|
|
|
|
|
|
if (config_block[0x16] != 0xFF)
|
|
|
|
memcpy(&global_settings.resume_offset, &config_block[0x16], 4);
|
|
|
|
|
2002-08-26 13:21:14 +00:00
|
|
|
if (config_block[0x1a] != 0xFF)
|
|
|
|
global_settings.disk_spindown = config_block[0x1a];
|
|
|
|
|
2002-08-16 14:41:47 +00:00
|
|
|
memcpy(&global_settings.resume_seed, &config_block[0xF8], 4);
|
|
|
|
|
|
|
|
if (config_block[0x24] != 0xFF)
|
|
|
|
memcpy(&global_settings.total_uptime, &config_block[0x24], 4);
|
2002-08-07 10:35:26 +00:00
|
|
|
|
2002-08-16 14:41:47 +00:00
|
|
|
strncpy(global_settings.resume_file, &config_block[0xFC], MAX_PATH);
|
|
|
|
global_settings.resume_file[MAX_PATH]=0;
|
2002-07-15 11:02:12 +00:00
|
|
|
}
|
2002-08-13 11:10:11 +00:00
|
|
|
lcd_set_contrast(global_settings.contrast);
|
2002-07-30 07:56:16 +00:00
|
|
|
lcd_scroll_speed(global_settings.scroll_speed);
|
|
|
|
backlight_time(global_settings.backlight);
|
2002-08-26 13:21:14 +00:00
|
|
|
ata_spindown(global_settings.disk_spindown);
|
2002-08-06 10:52:51 +00:00
|
|
|
#ifdef HAVE_CHARGE_CTRL
|
|
|
|
charge_restart_level = global_settings.discharge ? CHARGE_RESTART_LO : CHARGE_RESTART_HI;
|
|
|
|
#endif
|
2002-06-27 00:20:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* reset all settings to their default value
|
|
|
|
*/
|
2002-07-15 11:02:12 +00:00
|
|
|
void settings_reset(void) {
|
2002-06-27 00:20:00 +00:00
|
|
|
|
2002-07-15 11:02:12 +00:00
|
|
|
DEBUGF( "settings_reset()\n" );
|
|
|
|
|
|
|
|
global_settings.volume = mpeg_sound_default(SOUND_VOLUME);
|
2002-08-14 21:30:06 +00:00
|
|
|
global_settings.balance = mpeg_sound_default(SOUND_BALANCE);
|
2002-07-15 11:02:12 +00:00
|
|
|
global_settings.bass = mpeg_sound_default(SOUND_BASS);
|
|
|
|
global_settings.treble = mpeg_sound_default(SOUND_TREBLE);
|
2002-08-14 21:30:06 +00:00
|
|
|
global_settings.loudness = mpeg_sound_default(SOUND_LOUDNESS);
|
|
|
|
global_settings.bass_boost = mpeg_sound_default(SOUND_SUPERBASS);
|
|
|
|
global_settings.avc = mpeg_sound_default(SOUND_AVC);
|
2002-08-19 10:57:55 +00:00
|
|
|
global_settings.resume = RESUME_ASK;
|
2002-07-15 11:02:12 +00:00
|
|
|
global_settings.contrast = DEFAULT_CONTRAST_SETTING;
|
|
|
|
global_settings.poweroff = DEFAULT_POWEROFF_SETTING;
|
|
|
|
global_settings.backlight = DEFAULT_BACKLIGHT_SETTING;
|
|
|
|
global_settings.wps_display = DEFAULT_WPS_DISPLAY;
|
|
|
|
global_settings.mp3filter = true;
|
2002-07-22 16:39:17 +00:00
|
|
|
global_settings.sort_case = false;
|
2002-08-07 10:35:26 +00:00
|
|
|
global_settings.statusbar = true;
|
2002-08-30 13:49:32 +00:00
|
|
|
global_settings.scrollbar = true;
|
2002-08-07 12:44:41 +00:00
|
|
|
global_settings.loop_playlist = true;
|
2002-07-15 11:02:12 +00:00
|
|
|
global_settings.playlist_shuffle = false;
|
2002-08-06 10:52:51 +00:00
|
|
|
global_settings.discharge = 0;
|
2002-07-15 11:02:12 +00:00
|
|
|
global_settings.total_uptime = 0;
|
|
|
|
global_settings.scroll_speed = 8;
|
2002-08-22 15:47:30 +00:00
|
|
|
global_settings.show_hidden_files = false;
|
2002-08-28 19:34:07 +00:00
|
|
|
global_settings.ff_rewind_accel = DEFAULT_FF_REWIND_ACCEL_SETTING;
|
2002-08-16 14:41:47 +00:00
|
|
|
global_settings.resume_index = -1;
|
|
|
|
global_settings.resume_offset = -1;
|
2002-08-26 13:21:14 +00:00
|
|
|
global_settings.disk_spindown = 5;
|
2002-06-27 00:20:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* dump the list of current settings
|
|
|
|
*/
|
2002-07-15 11:02:12 +00:00
|
|
|
void settings_display(void)
|
2002-06-27 00:20:00 +00:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2002-07-15 11:02:12 +00:00
|
|
|
DEBUGF( "\nsettings_display()\n" );
|
2002-06-27 00:20:00 +00:00
|
|
|
|
|
|
|
DEBUGF( "\nvolume:\t\t%d\nbalance:\t%d\nbass:\t\t%d\ntreble:\t\t%d\nloudness:\t%d\nbass boost:\t%d\n",
|
2002-07-15 11:02:12 +00:00
|
|
|
global_settings.volume,
|
|
|
|
global_settings.balance,
|
|
|
|
global_settings.bass,
|
|
|
|
global_settings.treble,
|
|
|
|
global_settings.loudness,
|
|
|
|
global_settings.bass_boost );
|
2002-06-27 00:20:00 +00:00
|
|
|
|
|
|
|
DEBUGF( "contrast:\t%d\npoweroff:\t%d\nbacklight:\t%d\n",
|
2002-07-15 11:02:12 +00:00
|
|
|
global_settings.contrast,
|
|
|
|
global_settings.poweroff,
|
|
|
|
global_settings.backlight );
|
2002-06-27 00:20:00 +00:00
|
|
|
#endif
|
|
|
|
}
|
2002-06-27 01:08:11 +00:00
|
|
|
|
|
|
|
void set_bool(char* string, bool* variable )
|
|
|
|
{
|
|
|
|
bool done = false;
|
2002-07-24 11:25:59 +00:00
|
|
|
int button;
|
2002-06-27 01:08:11 +00:00
|
|
|
|
2002-08-20 19:37:00 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
if(global_settings.statusbar)
|
|
|
|
lcd_setmargins(0, STATUSBAR_HEIGHT);
|
|
|
|
else
|
|
|
|
lcd_setmargins(0, 0);
|
|
|
|
#endif
|
2002-06-27 01:08:11 +00:00
|
|
|
lcd_clear_display();
|
2002-08-20 19:37:00 +00:00
|
|
|
lcd_puts_scroll(0, 0, string);
|
2002-06-27 01:08:11 +00:00
|
|
|
|
|
|
|
while ( !done ) {
|
|
|
|
lcd_puts(0, 1, *variable ? "on " : "off");
|
2002-08-20 19:37:00 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
status_draw();
|
|
|
|
#endif
|
2002-06-27 01:08:11 +00:00
|
|
|
lcd_update();
|
|
|
|
|
2002-08-20 19:37:00 +00:00
|
|
|
button = button_get_w_tmo(HZ/2);
|
2002-07-24 11:25:59 +00:00
|
|
|
switch ( button ) {
|
2002-06-27 01:08:11 +00:00
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
|
|
|
case BUTTON_LEFT:
|
|
|
|
#else
|
|
|
|
case BUTTON_STOP:
|
|
|
|
case BUTTON_MENU:
|
|
|
|
#endif
|
|
|
|
done = true;
|
|
|
|
break;
|
|
|
|
|
2002-08-20 19:37:00 +00:00
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
|
|
|
case BUTTON_UP:
|
|
|
|
case BUTTON_DOWN:
|
|
|
|
#else
|
|
|
|
case BUTTON_LEFT:
|
|
|
|
case BUTTON_RIGHT:
|
|
|
|
#endif
|
2002-07-24 11:25:59 +00:00
|
|
|
if(!(button & BUTTON_REL))
|
|
|
|
*variable = !*variable;
|
2002-06-27 01:08:11 +00:00
|
|
|
break;
|
2002-08-20 19:37:00 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
|
|
|
case BUTTON_F3:
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
global_settings.statusbar = !global_settings.statusbar;
|
|
|
|
settings_save();
|
|
|
|
if(global_settings.statusbar)
|
|
|
|
lcd_setmargins(0, STATUSBAR_HEIGHT);
|
|
|
|
else
|
|
|
|
lcd_setmargins(0, 0);
|
|
|
|
lcd_clear_display();
|
|
|
|
lcd_puts_scroll(0, 0, string);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
#endif
|
2002-06-27 01:08:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
lcd_stop_scroll();
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_int(char* string,
|
|
|
|
char* unit,
|
|
|
|
int* variable,
|
|
|
|
void (*function)(int),
|
|
|
|
int step,
|
|
|
|
int min,
|
|
|
|
int max )
|
|
|
|
{
|
|
|
|
bool done = false;
|
|
|
|
|
2002-08-20 19:37:00 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
if(global_settings.statusbar)
|
|
|
|
lcd_setmargins(0, STATUSBAR_HEIGHT);
|
|
|
|
else
|
|
|
|
lcd_setmargins(0, 0);
|
|
|
|
#endif
|
2002-06-27 01:08:11 +00:00
|
|
|
lcd_clear_display();
|
2002-08-20 19:37:00 +00:00
|
|
|
lcd_puts_scroll(0, 0, string);
|
2002-06-27 01:08:11 +00:00
|
|
|
|
|
|
|
while (!done) {
|
|
|
|
char str[32];
|
|
|
|
snprintf(str,sizeof str,"%d %s ", *variable, unit);
|
2002-08-20 19:37:00 +00:00
|
|
|
lcd_puts(0, 1, str);
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
status_draw();
|
|
|
|
#endif
|
2002-06-27 01:08:11 +00:00
|
|
|
lcd_update();
|
|
|
|
|
2002-08-20 19:37:00 +00:00
|
|
|
switch( button_get_w_tmo(HZ/2) ) {
|
2002-06-27 01:08:11 +00:00
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
|
|
|
case BUTTON_UP:
|
2002-07-30 07:50:53 +00:00
|
|
|
case BUTTON_UP | BUTTON_REPEAT:
|
2002-06-27 01:08:11 +00:00
|
|
|
#else
|
|
|
|
case BUTTON_RIGHT:
|
2002-07-30 07:50:53 +00:00
|
|
|
case BUTTON_RIGHT | BUTTON_REPEAT:
|
2002-06-27 01:08:11 +00:00
|
|
|
#endif
|
|
|
|
*variable += step;
|
|
|
|
if(*variable > max )
|
|
|
|
*variable = max;
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
|
|
|
case BUTTON_DOWN:
|
2002-07-30 07:50:53 +00:00
|
|
|
case BUTTON_DOWN | BUTTON_REPEAT:
|
2002-06-27 01:08:11 +00:00
|
|
|
#else
|
|
|
|
case BUTTON_LEFT:
|
2002-07-30 07:50:53 +00:00
|
|
|
case BUTTON_LEFT | BUTTON_REPEAT:
|
2002-06-27 01:08:11 +00:00
|
|
|
#endif
|
|
|
|
*variable -= step;
|
|
|
|
if(*variable < min )
|
|
|
|
*variable = min;
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
|
|
|
case BUTTON_LEFT:
|
|
|
|
#else
|
|
|
|
case BUTTON_STOP:
|
|
|
|
case BUTTON_MENU:
|
|
|
|
#endif
|
|
|
|
done = true;
|
|
|
|
break;
|
2002-08-20 19:37:00 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
|
|
|
case BUTTON_F3:
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
global_settings.statusbar = !global_settings.statusbar;
|
|
|
|
settings_save();
|
|
|
|
if(global_settings.statusbar)
|
|
|
|
lcd_setmargins(0, STATUSBAR_HEIGHT);
|
|
|
|
else
|
|
|
|
lcd_setmargins(0, 0);
|
|
|
|
lcd_clear_display();
|
|
|
|
lcd_puts_scroll(0, 0, string);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
#endif
|
2002-06-27 01:08:11 +00:00
|
|
|
}
|
|
|
|
if ( function )
|
|
|
|
function(*variable);
|
|
|
|
}
|
|
|
|
lcd_stop_scroll();
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_option(char* string, int* variable, char* options[], int numoptions )
|
|
|
|
{
|
|
|
|
bool done = false;
|
|
|
|
|
2002-08-20 19:37:00 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
if(global_settings.statusbar)
|
|
|
|
lcd_setmargins(0, STATUSBAR_HEIGHT);
|
|
|
|
else
|
|
|
|
lcd_setmargins(0, 0);
|
|
|
|
#endif
|
2002-06-27 01:08:11 +00:00
|
|
|
lcd_clear_display();
|
2002-08-20 19:37:00 +00:00
|
|
|
lcd_puts_scroll(0, 0, string);
|
2002-06-27 01:08:11 +00:00
|
|
|
|
|
|
|
while ( !done ) {
|
|
|
|
lcd_puts(0, 1, options[*variable]);
|
2002-08-20 19:37:00 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
status_draw();
|
|
|
|
#endif
|
2002-06-27 01:08:11 +00:00
|
|
|
lcd_update();
|
|
|
|
|
2002-08-20 19:37:00 +00:00
|
|
|
switch ( button_get_w_tmo(HZ/2) ) {
|
2002-06-27 01:08:11 +00:00
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
|
|
|
case BUTTON_UP:
|
2002-07-30 07:50:53 +00:00
|
|
|
case BUTTON_UP | BUTTON_REPEAT:
|
2002-06-27 01:08:11 +00:00
|
|
|
#else
|
|
|
|
case BUTTON_RIGHT:
|
2002-07-30 07:50:53 +00:00
|
|
|
case BUTTON_RIGHT | BUTTON_REPEAT:
|
2002-06-27 01:08:11 +00:00
|
|
|
#endif
|
|
|
|
if ( *variable < (numoptions-1) )
|
|
|
|
(*variable)++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
|
|
|
case BUTTON_DOWN:
|
2002-07-30 07:50:53 +00:00
|
|
|
case BUTTON_DOWN | BUTTON_REPEAT:
|
2002-06-27 01:08:11 +00:00
|
|
|
#else
|
|
|
|
case BUTTON_LEFT:
|
2002-07-30 07:50:53 +00:00
|
|
|
case BUTTON_LEFT | BUTTON_REPEAT:
|
2002-06-27 01:08:11 +00:00
|
|
|
#endif
|
|
|
|
if ( *variable > 0 )
|
|
|
|
(*variable)--;
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
|
|
|
case BUTTON_LEFT:
|
|
|
|
#else
|
|
|
|
case BUTTON_STOP:
|
|
|
|
case BUTTON_MENU:
|
|
|
|
#endif
|
|
|
|
done = true;
|
|
|
|
break;
|
2002-08-20 19:37:00 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
|
|
|
case BUTTON_F3:
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
global_settings.statusbar = !global_settings.statusbar;
|
|
|
|
settings_save();
|
|
|
|
if(global_settings.statusbar)
|
|
|
|
lcd_setmargins(0, STATUSBAR_HEIGHT);
|
|
|
|
else
|
|
|
|
lcd_setmargins(0, 0);
|
|
|
|
lcd_clear_display();
|
|
|
|
lcd_puts_scroll(0, 0, string);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
#endif
|
2002-06-27 01:08:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
lcd_stop_scroll();
|
|
|
|
}
|
2002-08-09 12:38:45 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_RTC
|
|
|
|
#define INDEX_X 0
|
|
|
|
#define INDEX_Y 1
|
2002-08-09 13:50:58 +00:00
|
|
|
#define INDEX_WIDTH 2
|
2002-08-15 06:36:25 +00:00
|
|
|
char *dayname[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
|
|
|
|
char *monthname[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
|
|
|
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
|
|
|
char cursor[][3] = {{ 0, 8, 12}, {18, 8, 12}, {36, 8, 12},
|
|
|
|
{24, 16, 24}, {54, 16, 18}, {78, 16, 12}};
|
|
|
|
char daysinmonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
2002-08-09 12:38:45 +00:00
|
|
|
|
|
|
|
void set_time(char* string, int timedate[])
|
|
|
|
{
|
|
|
|
bool done = false;
|
|
|
|
int button;
|
2002-08-15 06:36:25 +00:00
|
|
|
int min = 0, steps = 0;
|
|
|
|
int cursorpos = 0;
|
|
|
|
int lastcursorpos = !cursorpos;
|
2002-08-09 12:38:45 +00:00
|
|
|
unsigned char buffer[19];
|
|
|
|
int realyear;
|
|
|
|
int julianday;
|
|
|
|
int i;
|
2002-08-15 06:36:25 +00:00
|
|
|
#if defined(LOADABLE_FONTS) || defined(LCD_PROPFONTS)
|
|
|
|
unsigned char reffub[5];
|
|
|
|
unsigned int width, height;
|
|
|
|
unsigned int separator_width, weekday_width;
|
|
|
|
unsigned int line_height, prev_line_height;
|
|
|
|
#if defined(LOADABLE_FONTS)
|
|
|
|
unsigned char *font = lcd_getcurrentldfont();
|
|
|
|
#endif
|
|
|
|
#endif
|
2002-08-09 12:38:45 +00:00
|
|
|
|
2002-08-20 19:37:00 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
if(global_settings.statusbar)
|
|
|
|
lcd_setmargins(0, STATUSBAR_HEIGHT);
|
|
|
|
else
|
|
|
|
lcd_setmargins(0, 0);
|
|
|
|
#endif
|
2002-08-09 12:38:45 +00:00
|
|
|
lcd_clear_display();
|
2002-08-15 06:36:25 +00:00
|
|
|
lcd_puts_scroll(0, 0, string);
|
2002-08-09 12:38:45 +00:00
|
|
|
|
|
|
|
while ( !done ) {
|
|
|
|
/* calculate the number of days in febuary */
|
2002-08-15 06:36:25 +00:00
|
|
|
realyear = timedate[3] + 2000;
|
|
|
|
if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0)
|
|
|
|
daysinmonth[1] = 29;
|
2002-08-09 12:38:45 +00:00
|
|
|
else
|
2002-08-15 06:36:25 +00:00
|
|
|
daysinmonth[1] = 28;
|
2002-08-09 12:38:45 +00:00
|
|
|
|
|
|
|
/* fix day if month or year changed */
|
2002-08-15 06:36:25 +00:00
|
|
|
if (timedate[5] > daysinmonth[timedate[4] - 1])
|
|
|
|
timedate[5] = daysinmonth[timedate[4] - 1];
|
2002-08-09 12:38:45 +00:00
|
|
|
|
|
|
|
/* calculate day of week */
|
2002-08-15 06:36:25 +00:00
|
|
|
julianday = 0;
|
|
|
|
for(i = 0; i < timedate[4] - 1; i++) {
|
|
|
|
julianday += daysinmonth[i];
|
2002-08-09 12:38:45 +00:00
|
|
|
}
|
2002-08-15 06:36:25 +00:00
|
|
|
julianday += timedate[5];
|
|
|
|
timedate[6] = (realyear + julianday + (realyear - 1) / 4 -
|
|
|
|
(realyear - 1) / 100 + (realyear - 1) / 400 + 7 - 1) % 7;
|
2002-08-09 12:38:45 +00:00
|
|
|
|
2002-08-15 06:36:25 +00:00
|
|
|
snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d ",
|
2002-08-09 12:38:45 +00:00
|
|
|
timedate[0],
|
|
|
|
timedate[1],
|
|
|
|
timedate[2]);
|
2002-08-15 06:36:25 +00:00
|
|
|
lcd_puts(0, 1, buffer);
|
|
|
|
#if defined(LCD_PROPFONTS)
|
|
|
|
/* recalculate the positions and offsets */
|
|
|
|
lcd_getstringsize(string, 0, &width, &prev_line_height);
|
|
|
|
lcd_getstringsize(buffer, 0, &width, &line_height);
|
|
|
|
lcd_getstringsize(":", 0, &separator_width, &height);
|
|
|
|
|
|
|
|
strncpy(reffub, buffer, 2);
|
|
|
|
reffub[2] = '\0';
|
|
|
|
lcd_getstringsize(reffub, 0, &width, &height);
|
|
|
|
cursor[0][INDEX_X] = 0;
|
|
|
|
cursor[0][INDEX_Y] = 1 + prev_line_height + 1;
|
2002-08-21 06:23:23 +00:00
|
|
|
cursor[0][INDEX_WIDTH] = width;
|
2002-08-15 06:36:25 +00:00
|
|
|
|
|
|
|
strncpy(reffub, buffer + 3, 2);
|
|
|
|
reffub[2] = '\0';
|
|
|
|
lcd_getstringsize(reffub, 0, &width, &height);
|
2002-08-21 06:23:23 +00:00
|
|
|
cursor[1][INDEX_X] = cursor[0][INDEX_WIDTH] + separator_width;
|
2002-08-15 06:36:25 +00:00
|
|
|
cursor[1][INDEX_Y] = 1 + prev_line_height + 1;
|
2002-08-21 06:23:23 +00:00
|
|
|
cursor[1][INDEX_WIDTH] = width;
|
2002-08-15 06:36:25 +00:00
|
|
|
|
|
|
|
strncpy(reffub, buffer + 6, 2);
|
|
|
|
reffub[2] = '\0';
|
|
|
|
lcd_getstringsize(reffub, 0, &width, &height);
|
2002-08-21 06:23:23 +00:00
|
|
|
cursor[2][INDEX_X] = cursor[0][INDEX_WIDTH] + separator_width +
|
|
|
|
cursor[1][INDEX_WIDTH] + separator_width;
|
2002-08-15 06:36:25 +00:00
|
|
|
cursor[2][INDEX_Y] = 1 + prev_line_height + 1;
|
2002-08-21 06:23:23 +00:00
|
|
|
cursor[2][INDEX_WIDTH] = width;
|
2002-08-15 06:36:25 +00:00
|
|
|
|
|
|
|
lcd_getstringsize(buffer, 0, &width, &prev_line_height);
|
|
|
|
#elif defined(LOADABLE_FONTS)
|
|
|
|
/* recalculate the positions and offsets */
|
|
|
|
lcd_getstringsize(string, font, &width, &prev_line_height);
|
|
|
|
lcd_getstringsize(buffer, font, &width, &line_height);
|
|
|
|
lcd_getstringsize(":", font, &separator_width, &height);
|
|
|
|
|
|
|
|
strncpy(reffub, buffer, 2);
|
|
|
|
reffub[2] = '\0';
|
|
|
|
lcd_getstringsize(reffub, font, &width, &height);
|
|
|
|
cursor[0][INDEX_X] = 0;
|
|
|
|
cursor[0][INDEX_Y] = prev_line_height;
|
|
|
|
cursor[0][INDEX_WIDTH] = width;
|
|
|
|
|
|
|
|
strncpy(reffub, buffer + 3, 2);
|
|
|
|
reffub[2] = '\0';
|
|
|
|
lcd_getstringsize(reffub, font, &width, &height);
|
|
|
|
cursor[1][INDEX_X] = cursor[0][INDEX_WIDTH] + separator_width;
|
|
|
|
cursor[1][INDEX_Y] = prev_line_height;
|
|
|
|
cursor[1][INDEX_WIDTH] = width;
|
|
|
|
|
|
|
|
strncpy(reffub, buffer + 6, 2);
|
|
|
|
reffub[2] = '\0';
|
|
|
|
lcd_getstringsize(reffub, font, &width, &height);
|
|
|
|
cursor[2][INDEX_X] = cursor[0][INDEX_WIDTH] + separator_width +
|
|
|
|
cursor[1][INDEX_WIDTH] + separator_width;
|
|
|
|
cursor[2][INDEX_Y] = prev_line_height;
|
|
|
|
cursor[2][INDEX_WIDTH] = width;
|
|
|
|
|
|
|
|
lcd_getstringsize(buffer, font, &width, &prev_line_height);
|
|
|
|
#endif
|
2002-08-09 12:38:45 +00:00
|
|
|
|
2002-08-15 06:36:25 +00:00
|
|
|
snprintf(buffer, sizeof(buffer), "%s 20%02d %s %02d ",
|
2002-08-09 12:38:45 +00:00
|
|
|
dayname[timedate[6]],
|
|
|
|
timedate[3],
|
2002-08-15 06:36:25 +00:00
|
|
|
monthname[timedate[4] - 1],
|
2002-08-09 12:38:45 +00:00
|
|
|
timedate[5]);
|
2002-08-15 06:36:25 +00:00
|
|
|
lcd_puts(0, 2, buffer);
|
|
|
|
#if defined(LCD_PROPFONTS)
|
|
|
|
/* recalculate the positions and offsets */
|
|
|
|
lcd_getstringsize(buffer, 0, &width, &line_height);
|
|
|
|
strncpy(reffub, buffer, 3);
|
|
|
|
reffub[3] = '\0';
|
|
|
|
lcd_getstringsize(reffub, 0, &weekday_width, &height);
|
|
|
|
lcd_getstringsize(" ", 0, &separator_width, &height);
|
|
|
|
|
|
|
|
strncpy(reffub, buffer + 4, 4);
|
|
|
|
reffub[4] = '\0';
|
|
|
|
lcd_getstringsize(reffub, 0, &width, &height);
|
2002-08-21 06:23:23 +00:00
|
|
|
cursor[3][INDEX_X] = weekday_width + separator_width;
|
2002-08-15 06:36:25 +00:00
|
|
|
cursor[3][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height + 1;
|
2002-08-21 06:23:23 +00:00
|
|
|
cursor[3][INDEX_WIDTH] = width;
|
2002-08-15 06:36:25 +00:00
|
|
|
|
|
|
|
strncpy(reffub, buffer + 9, 3);
|
|
|
|
reffub[3] = '\0';
|
|
|
|
lcd_getstringsize(reffub, 0, &width, &height);
|
2002-08-21 06:23:23 +00:00
|
|
|
cursor[4][INDEX_X] = weekday_width + separator_width +
|
|
|
|
cursor[3][INDEX_WIDTH] + separator_width;
|
2002-08-15 06:36:25 +00:00
|
|
|
cursor[4][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height + 1;
|
2002-08-21 06:23:23 +00:00
|
|
|
cursor[4][INDEX_WIDTH] = width;
|
2002-08-15 06:36:25 +00:00
|
|
|
|
|
|
|
strncpy(reffub, buffer + 13, 2);
|
|
|
|
reffub[2] = '\0';
|
|
|
|
lcd_getstringsize(reffub, 0, &width, &height);
|
2002-08-21 06:23:23 +00:00
|
|
|
cursor[5][INDEX_X] = weekday_width + separator_width +
|
|
|
|
cursor[3][INDEX_WIDTH] + separator_width +
|
|
|
|
cursor[4][INDEX_WIDTH] + separator_width;
|
2002-08-15 06:36:25 +00:00
|
|
|
cursor[5][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height + 1;
|
2002-08-21 06:23:23 +00:00
|
|
|
cursor[5][INDEX_WIDTH] = width;
|
2002-08-15 06:36:25 +00:00
|
|
|
|
|
|
|
lcd_invertrect(cursor[cursorpos][INDEX_X],
|
2002-08-20 19:37:00 +00:00
|
|
|
cursor[cursorpos][INDEX_Y] + lcd_getymargin(),
|
2002-08-15 06:36:25 +00:00
|
|
|
cursor[cursorpos][INDEX_WIDTH],
|
|
|
|
line_height);
|
|
|
|
#elif defined(LOADABLE_FONTS)
|
|
|
|
/* recalculate the positions and offsets */
|
|
|
|
lcd_getstringsize(buffer, font, &width, &line_height);
|
|
|
|
strncpy(reffub, buffer, 3);
|
|
|
|
reffub[3] = '\0';
|
|
|
|
lcd_getstringsize(reffub, font, &weekday_width, &height);
|
|
|
|
lcd_getstringsize(" ", font, &separator_width, &height);
|
|
|
|
|
|
|
|
strncpy(reffub, buffer + 4, 4);
|
|
|
|
reffub[4] = '\0';
|
|
|
|
lcd_getstringsize(reffub, font, &width, &height);
|
|
|
|
cursor[3][INDEX_X] = weekday_width + separator_width;
|
|
|
|
cursor[3][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height;
|
|
|
|
cursor[3][INDEX_WIDTH] = width;
|
|
|
|
|
|
|
|
strncpy(reffub, buffer + 9, 3);
|
|
|
|
reffub[3] = '\0';
|
|
|
|
lcd_getstringsize(reffub, font, &width, &height);
|
|
|
|
cursor[4][INDEX_X] = weekday_width + separator_width +
|
|
|
|
cursor[3][INDEX_WIDTH] + separator_width;
|
|
|
|
cursor[4][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height;
|
|
|
|
cursor[4][INDEX_WIDTH] = width;
|
|
|
|
|
|
|
|
strncpy(reffub, buffer + 13, 2);
|
|
|
|
reffub[2] = '\0';
|
|
|
|
lcd_getstringsize(reffub, font, &width, &height);
|
|
|
|
cursor[5][INDEX_X] = weekday_width + separator_width +
|
|
|
|
cursor[3][INDEX_WIDTH] + separator_width +
|
|
|
|
cursor[4][INDEX_WIDTH] + separator_width;
|
|
|
|
cursor[5][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height;
|
|
|
|
cursor[5][INDEX_WIDTH] = width;
|
|
|
|
|
|
|
|
lcd_invertrect(cursor[cursorpos][INDEX_X],
|
2002-08-20 19:37:00 +00:00
|
|
|
cursor[cursorpos][INDEX_Y] + lcd_getymargin(),
|
2002-08-15 06:36:25 +00:00
|
|
|
cursor[cursorpos][INDEX_WIDTH],
|
|
|
|
line_height);
|
|
|
|
#else
|
|
|
|
lcd_invertrect(cursor[cursorpos][INDEX_X],
|
2002-08-20 19:37:00 +00:00
|
|
|
cursor[cursorpos][INDEX_Y] + lcd_getymargin(),
|
2002-08-15 06:36:25 +00:00
|
|
|
cursor[cursorpos][INDEX_WIDTH],
|
|
|
|
8);
|
|
|
|
#endif
|
2002-08-20 19:37:00 +00:00
|
|
|
lcd_puts(0, 4, "ON to set");
|
|
|
|
lcd_puts(0, 5, "OFF to revert");
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
status_draw();
|
|
|
|
#endif
|
2002-08-09 12:38:45 +00:00
|
|
|
lcd_update();
|
|
|
|
|
|
|
|
/* calculate the minimum and maximum for the number under cursor */
|
|
|
|
if(cursorpos!=lastcursorpos) {
|
|
|
|
lastcursorpos=cursorpos;
|
|
|
|
switch(cursorpos) {
|
|
|
|
case 0: /* hour */
|
2002-08-15 06:36:25 +00:00
|
|
|
min = 0;
|
|
|
|
steps = 24;
|
2002-08-09 12:38:45 +00:00
|
|
|
break;
|
|
|
|
case 1: /* minute */
|
|
|
|
case 2: /* second */
|
2002-08-15 06:36:25 +00:00
|
|
|
min = 0;
|
|
|
|
steps = 60;
|
2002-08-09 12:38:45 +00:00
|
|
|
break;
|
2002-08-09 13:50:58 +00:00
|
|
|
case 3: /* year */
|
2002-08-15 06:36:25 +00:00
|
|
|
min = 0;
|
|
|
|
steps = 100;
|
2002-08-09 12:38:45 +00:00
|
|
|
break;
|
|
|
|
case 4: /* month */
|
2002-08-15 06:36:25 +00:00
|
|
|
min = 1;
|
|
|
|
steps = 12;
|
2002-08-09 12:38:45 +00:00
|
|
|
break;
|
2002-08-09 13:50:58 +00:00
|
|
|
case 5: /* day */
|
2002-08-15 06:36:25 +00:00
|
|
|
min = 1;
|
|
|
|
steps = daysinmonth[timedate[4] - 1];
|
2002-08-09 12:38:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-20 19:37:00 +00:00
|
|
|
button = button_get_w_tmo(HZ/2);
|
2002-08-09 12:38:45 +00:00
|
|
|
switch ( button ) {
|
|
|
|
case BUTTON_LEFT:
|
2002-08-15 06:36:25 +00:00
|
|
|
cursorpos = (cursorpos + 6 - 1) % 6;
|
2002-08-09 12:38:45 +00:00
|
|
|
break;
|
|
|
|
case BUTTON_RIGHT:
|
2002-08-15 06:36:25 +00:00
|
|
|
cursorpos = (cursorpos + 6 + 1) % 6;
|
2002-08-09 12:38:45 +00:00
|
|
|
break;
|
|
|
|
case BUTTON_UP:
|
2002-08-28 06:12:53 +00:00
|
|
|
case BUTTON_UP | BUTTON_REPEAT:
|
2002-08-15 06:36:25 +00:00
|
|
|
timedate[cursorpos] = (timedate[cursorpos] + steps - min + 1) % steps + min;
|
|
|
|
if(timedate[cursorpos] == 0)
|
|
|
|
timedate[cursorpos] += min;
|
2002-08-09 12:38:45 +00:00
|
|
|
break;
|
|
|
|
case BUTTON_DOWN:
|
2002-08-28 06:12:53 +00:00
|
|
|
case BUTTON_DOWN | BUTTON_REPEAT:
|
2002-08-15 06:36:25 +00:00
|
|
|
timedate[cursorpos]=(timedate[cursorpos]+steps - min - 1) % steps + min;
|
|
|
|
if(timedate[cursorpos] == 0)
|
|
|
|
timedate[cursorpos] += min;
|
2002-08-09 12:38:45 +00:00
|
|
|
break;
|
|
|
|
case BUTTON_ON:
|
2002-08-15 06:36:25 +00:00
|
|
|
done = true;
|
|
|
|
if (timedate[6] == 0) /* rtc needs 1 .. 7 */
|
|
|
|
timedate[6] = 7;
|
2002-08-09 12:38:45 +00:00
|
|
|
break;
|
|
|
|
case BUTTON_OFF:
|
2002-08-15 06:36:25 +00:00
|
|
|
done = true;
|
|
|
|
timedate[0] = -1;
|
2002-08-09 12:38:45 +00:00
|
|
|
break;
|
2002-08-20 19:37:00 +00:00
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
|
|
|
case BUTTON_F3:
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
global_settings.statusbar = !global_settings.statusbar;
|
|
|
|
settings_save();
|
|
|
|
if(global_settings.statusbar)
|
|
|
|
lcd_setmargins(0, STATUSBAR_HEIGHT);
|
|
|
|
else
|
|
|
|
lcd_setmargins(0, 0);
|
|
|
|
lcd_clear_display();
|
|
|
|
lcd_puts_scroll(0, 0, string);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
#endif
|
2002-08-09 12:38:45 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|