summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/settings.c108
-rw-r--r--apps/settings.h3
-rw-r--r--apps/settings_menu.c71
3 files changed, 78 insertions, 104 deletions
diff --git a/apps/settings.c b/apps/settings.c
index 8a93617d64..b84ef52205 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -17,7 +17,6 @@
17 * KIND, either express or implied. 17 * KIND, either express or implied.
18 * 18 *
19 ****************************************************************************/ 19 ****************************************************************************/
20
21#include <stdio.h> 20#include <stdio.h>
22#include "config.h" 21#include "config.h"
23#include "kernel.h" 22#include "kernel.h"
@@ -47,6 +46,7 @@
47#include "errno.h" 46#include "errno.h"
48#include "system.h" 47#include "system.h"
49#include "misc.h" 48#include "misc.h"
49#include "timefuncs.h"
50#ifdef HAVE_LCD_BITMAP 50#ifdef HAVE_LCD_BITMAP
51#include "icons.h" 51#include "icons.h"
52#include "font.h" 52#include "font.h"
@@ -1963,17 +1963,33 @@ bool set_option(char* string, void* variable, enum optiontype type,
1963#ifdef HAVE_LCD_BITMAP 1963#ifdef HAVE_LCD_BITMAP
1964 1964
1965/* little helper function for voice output */ 1965/* little helper function for voice output */
1966static void say_time(int cursorpos, int timedate[]) 1966static void say_time(int cursorpos, struct tm *tm)
1967{ 1967{
1968 const int unit[] = { UNIT_HOUR, UNIT_MIN, UNIT_SEC, 0, 0, 0 }; 1968 const int unit[] = { UNIT_HOUR, UNIT_MIN, UNIT_SEC, 0, 0, 0 };
1969 int value = timedate[cursorpos]; 1969 int value = 0;
1970 1970
1971 if (!global_settings.talk_menu) 1971 if (!global_settings.talk_menu)
1972 return; 1972 return;
1973 1973
1974 if (cursorpos == 3) /* year */ 1974 switch(cursorpos)
1975 value += 2000; 1975 {
1976 1976 case 0:
1977 value = tm->tm_hour;
1978 break;
1979 case 1:
1980 value = tm->tm_min;
1981 break;
1982 case 2:
1983 value = tm->tm_sec;
1984 break;
1985 case 3:
1986 value = tm->tm_year + 1900;
1987 break;
1988 case 5:
1989 value = tm->tm_mday;
1990 break;
1991 }
1992
1977 if (cursorpos == 4) /* month */ 1993 if (cursorpos == 4) /* month */
1978 talk_id(LANG_MONTH_JANUARY + value - 1, false); 1994 talk_id(LANG_MONTH_JANUARY + value - 1, false);
1979 else 1995 else
@@ -1984,7 +2000,7 @@ static void say_time(int cursorpos, int timedate[])
1984#define INDEX_X 0 2000#define INDEX_X 0
1985#define INDEX_Y 1 2001#define INDEX_Y 1
1986#define INDEX_WIDTH 2 2002#define INDEX_WIDTH 2
1987bool set_time(char* string, int timedate[]) 2003bool set_time_screen(char* string, struct tm *tm)
1988{ 2004{
1989 bool done = false; 2005 bool done = false;
1990 int button; 2006 int button;
@@ -2024,6 +2040,7 @@ bool set_time(char* string, int timedate[])
2024 2040
2025 int monthname_len = 0, dayname_len = 0; 2041 int monthname_len = 0, dayname_len = 0;
2026 2042
2043 int *valptr = NULL;
2027 2044
2028#ifdef HAVE_LCD_BITMAP 2045#ifdef HAVE_LCD_BITMAP
2029 if(global_settings.statusbar) 2046 if(global_settings.statusbar)
@@ -2036,27 +2053,27 @@ bool set_time(char* string, int timedate[])
2036 2053
2037 while ( !done ) { 2054 while ( !done ) {
2038 /* calculate the number of days in febuary */ 2055 /* calculate the number of days in febuary */
2039 realyear = timedate[3] + 2000; 2056 realyear = tm->tm_year + 1900;
2040 if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0) 2057 if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0)
2041 daysinmonth[1] = 29; 2058 daysinmonth[1] = 29;
2042 else 2059 else
2043 daysinmonth[1] = 28; 2060 daysinmonth[1] = 28;
2044 2061
2045 /* fix day if month or year changed */ 2062 /* fix day if month or year changed */
2046 if (timedate[5] > daysinmonth[timedate[4] - 1]) 2063 if (tm->tm_mday > daysinmonth[tm->tm_mon])
2047 timedate[5] = daysinmonth[timedate[4] - 1]; 2064 tm->tm_mday = daysinmonth[tm->tm_mon];
2048 2065
2049 /* calculate day of week */ 2066 /* calculate day of week */
2050 julianday = 0; 2067 julianday = 0;
2051 for(i = 0; i < timedate[4] - 1; i++) { 2068 for(i = 0; i < tm->tm_mon; i++) {
2052 julianday += daysinmonth[i]; 2069 julianday += daysinmonth[i];
2053 } 2070 }
2054 julianday += timedate[5]; 2071 julianday += tm->tm_mday;
2055 timedate[6] = (realyear + julianday + (realyear - 1) / 4 - 2072 tm->tm_wday = (realyear + julianday + (realyear - 1) / 4 -
2056 (realyear - 1) / 100 + (realyear - 1) / 400 + 7 - 1) % 7; 2073 (realyear - 1) / 100 + (realyear - 1) / 400 + 7 - 1) % 7;
2057 2074
2058 snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d ", 2075 snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d ",
2059 timedate[0], timedate[1], timedate[2]); 2076 tm->tm_hour, tm->tm_min, tm->tm_sec);
2060 lcd_puts(0, 1, buffer); 2077 lcd_puts(0, 1, buffer);
2061 2078
2062 /* recalculate the positions and offsets */ 2079 /* recalculate the positions and offsets */
@@ -2091,17 +2108,17 @@ bool set_time(char* string, int timedate[])
2091 2108
2092 lcd_getstringsize(buffer, &width, &prev_line_height); 2109 lcd_getstringsize(buffer, &width, &prev_line_height);
2093 2110
2094 snprintf(buffer, sizeof(buffer), "%s 20%02d %s %02d ", 2111 snprintf(buffer, sizeof(buffer), "%s %04d %s %02d ",
2095 str(dayname[timedate[6]]), timedate[3], 2112 str(dayname[tm->tm_wday]), tm->tm_year+1900,
2096 str(monthname[timedate[4] - 1]), timedate[5]); 2113 str(monthname[tm->tm_mon]), tm->tm_mday);
2097 lcd_puts(0, 2, buffer); 2114 lcd_puts(0, 2, buffer);
2098 2115
2099 /* recalculate the positions and offsets */ 2116 /* recalculate the positions and offsets */
2100 lcd_getstringsize(buffer, &width, &line_height); 2117 lcd_getstringsize(buffer, &width, &line_height);
2101 2118
2102 /* store these 2 to prevent _repeated_ strlen calls */ 2119 /* store these 2 to prevent _repeated_ strlen calls */
2103 monthname_len = strlen(str(monthname[timedate[4] - 1])); 2120 monthname_len = strlen(str(monthname[tm->tm_mon]));
2104 dayname_len = strlen(str(dayname[timedate[6]])); 2121 dayname_len = strlen(str(dayname[tm->tm_wday]));
2105 2122
2106 /* weekday */ 2123 /* weekday */
2107 strncpy(reffub, buffer, dayname_len); 2124 strncpy(reffub, buffer, dayname_len);
@@ -2155,26 +2172,35 @@ bool set_time(char* string, int timedate[])
2155 case 0: /* hour */ 2172 case 0: /* hour */
2156 min = 0; 2173 min = 0;
2157 steps = 24; 2174 steps = 24;
2175 valptr = &tm->tm_hour;
2158 break; 2176 break;
2159 case 1: /* minute */ 2177 case 1: /* minute */
2178 min = 0;
2179 steps = 60;
2180 valptr = &tm->tm_min;
2181 break;
2160 case 2: /* second */ 2182 case 2: /* second */
2161 min = 0; 2183 min = 0;
2162 steps = 60; 2184 steps = 60;
2185 valptr = &tm->tm_sec;
2163 break; 2186 break;
2164 case 3: /* year */ 2187 case 3: /* year */
2165 min = 0; 2188 min = 1;
2166 steps = 100; 2189 steps = 200;
2190 valptr = &tm->tm_year;
2167 break; 2191 break;
2168 case 4: /* month */ 2192 case 4: /* month */
2169 min = 1; 2193 min = 0;
2170 steps = 12; 2194 steps = 12;
2195 valptr = &tm->tm_mon;
2171 break; 2196 break;
2172 case 5: /* day */ 2197 case 5: /* day */
2173 min = 1; 2198 min = 1;
2174 steps = daysinmonth[timedate[4] - 1]; 2199 steps = daysinmonth[tm->tm_mon];
2200 valptr = &tm->tm_mday;
2175 break; 2201 break;
2176 } 2202 }
2177 say_time(cursorpos, timedate); 2203 say_time(cursorpos, tm);
2178 } 2204 }
2179 2205
2180 button = button_get_w_tmo(HZ/2); 2206 button = button_get_w_tmo(HZ/2);
@@ -2187,43 +2213,27 @@ bool set_time(char* string, int timedate[])
2187 break; 2213 break;
2188 case BUTTON_UP: 2214 case BUTTON_UP:
2189 case BUTTON_UP | BUTTON_REPEAT: 2215 case BUTTON_UP | BUTTON_REPEAT:
2190 timedate[cursorpos] = (timedate[cursorpos] + steps - min + 1) % 2216 *valptr = (*valptr + steps - min + 1) %
2191 steps + min; 2217 steps + min;
2192 if(timedate[cursorpos] == 0) 2218 if(*valptr == 0)
2193 timedate[cursorpos] += min; 2219 *valptr = min;
2194 say_time(cursorpos, timedate); 2220 say_time(cursorpos, tm);
2195 break; 2221 break;
2196 case BUTTON_DOWN: 2222 case BUTTON_DOWN:
2197 case BUTTON_DOWN | BUTTON_REPEAT: 2223 case BUTTON_DOWN | BUTTON_REPEAT:
2198 timedate[cursorpos]=(timedate[cursorpos]+steps - min - 1) % 2224 *valptr = (*valptr + steps - min - 1) %
2199 steps + min; 2225 steps + min;
2200 if(timedate[cursorpos] == 0) 2226 if(*valptr == 0)
2201 timedate[cursorpos] += min; 2227 *valptr = min;
2202 say_time(cursorpos, timedate); 2228 say_time(cursorpos, tm);
2203 break; 2229 break;
2204 case BUTTON_ON: 2230 case BUTTON_ON:
2205 done = true; 2231 done = true;
2206 if (timedate[6] == 0) /* rtc needs 1 .. 7 */
2207 timedate[6] = 7;
2208 break; 2232 break;
2209 case BUTTON_OFF: 2233 case BUTTON_OFF:
2210 done = true; 2234 done = true;
2211 timedate[0] = -1; 2235 tm->tm_year = -1;
2212 break; 2236 break;
2213#ifdef HAVE_RECORDER_KEYPAD
2214 case BUTTON_F3:
2215#ifdef HAVE_LCD_BITMAP
2216 global_settings.statusbar = !global_settings.statusbar;
2217 settings_save();
2218 if(global_settings.statusbar)
2219 lcd_setmargins(0, STATUSBAR_HEIGHT);
2220 else
2221 lcd_setmargins(0, 0);
2222 lcd_clear_display();
2223 lcd_puts_scroll(0, 0, string);
2224#endif
2225 break;
2226#endif
2227 2237
2228 case SYS_USB_CONNECTED: 2238 case SYS_USB_CONNECTED:
2229 usb_screen(); 2239 usb_screen();
diff --git a/apps/settings.h b/apps/settings.h
index 0bf67b474b..8d602f17ac 100644
--- a/apps/settings.h
+++ b/apps/settings.h
@@ -23,6 +23,7 @@
23#include <stdbool.h> 23#include <stdbool.h>
24#include "config.h" 24#include "config.h"
25#include "file.h" 25#include "file.h"
26#include "timefuncs.h"
26 27
27#define ROCKBOX_DIR "/.rockbox" 28#define ROCKBOX_DIR "/.rockbox"
28#define FONT_DIR "/fonts" 29#define FONT_DIR "/fonts"
@@ -237,7 +238,7 @@ bool set_option(char* string, void* variable, enum optiontype type,
237 struct opt_items* options, int numoptions, void (*function)(int)); 238 struct opt_items* options, int numoptions, void (*function)(int));
238bool set_int(char* string, char* unit, int voice_unit, int* variable, 239bool set_int(char* string, char* unit, int voice_unit, int* variable,
239 void (*function)(int), int step, int min, int max ); 240 void (*function)(int), int step, int min, int max );
240bool set_time(char* string, int timedate[]); 241bool set_time_screen(char* string, struct tm *tm);
241int read_line(int fd, char* buffer, int buffer_size); 242int read_line(int fd, char* buffer, int buffer_size);
242void set_file(char* filename, char* setting, int maxlen); 243void set_file(char* filename, char* setting, int maxlen);
243 244
diff --git a/apps/settings_menu.c b/apps/settings_menu.c
index 10d3665b97..7150dd239d 100644
--- a/apps/settings_menu.c
+++ b/apps/settings_menu.c
@@ -21,6 +21,7 @@
21 21
22#include <stdio.h> 22#include <stdio.h>
23#include <stdbool.h> 23#include <stdbool.h>
24#include <string.h>
24 25
25#include "lcd.h" 26#include "lcd.h"
26#include "menu.h" 27#include "menu.h"
@@ -41,6 +42,7 @@
41#include "tree.h" 42#include "tree.h"
42#include "screens.h" 43#include "screens.h"
43#include "talk.h" 44#include "talk.h"
45#include "timefuncs.h"
44#ifdef HAVE_LCD_BITMAP 46#ifdef HAVE_LCD_BITMAP
45#include "peakmeter.h" 47#include "peakmeter.h"
46#endif 48#endif
@@ -685,7 +687,8 @@ static bool trickle_charge(void)
685#ifdef HAVE_RTC 687#ifdef HAVE_RTC
686static bool timedate_set(void) 688static bool timedate_set(void)
687{ 689{
688 int timedate[7]; /* hour,minute,second,year,month,day,dayofweek */ 690 struct tm tm;
691 int timedate[8];
689 bool result; 692 bool result;
690 693
691 timedate[0] = rtc_read(0x03); /* hour */ 694 timedate[0] = rtc_read(0x03); /* hour */
@@ -695,67 +698,27 @@ static bool timedate_set(void)
695 timedate[4] = rtc_read(0x06); /* month */ 698 timedate[4] = rtc_read(0x06); /* month */
696 timedate[5] = rtc_read(0x05); /* day */ 699 timedate[5] = rtc_read(0x05); /* day */
697 700
698 /* day of week not read, calculated in set_time() */ 701 /* Make a local copy of the time struct */
699 /* hour */ 702 memcpy(&tm, get_time(), sizeof(struct tm));
700 timedate[0] = ((timedate[0] & 0x30) >> 4) * 10 + (timedate[0] & 0x0f);
701 /* minute */
702 timedate[1] = ((timedate[1] & 0x70) >> 4) * 10 + (timedate[1] & 0x0f);
703 /* second */
704 timedate[2] = ((timedate[2] & 0x70) >> 4) * 10 + (timedate[2] & 0x0f);
705 /* year */
706 timedate[3] = ((timedate[3] & 0xf0) >> 4) * 10 + (timedate[3] & 0x0f);
707 /* month */
708 timedate[4] = ((timedate[4] & 0x10) >> 4) * 10 + (timedate[4] & 0x0f);
709 /* day */
710 timedate[5] = ((timedate[5] & 0x30) >> 4) * 10 + (timedate[5] & 0x0f);
711 703
712 /* do some range checks */ 704 /* do some range checks */
713 /* This prevents problems with time/date setting after a power loss */ 705 /* This prevents problems with time/date setting after a power loss */
714 if (timedate[0] < 0 || timedate[0] > 23 || 706 if (!valid_time(&tm))
715 timedate[1] < 0 || timedate[1] > 59 ||
716 timedate[2] < 0 || timedate[2] > 59 ||
717 timedate[3] < 0 || timedate[3] > 99 ||
718 timedate[4] < 1 || timedate[4] > 12 ||
719 timedate[5] < 1 || timedate[5] > 31)
720 { 707 {
721 /* hour */ 708 /* hour */
722 timedate[0] = 0; 709 tm.tm_hour = 0;
723 /* minute */ 710 tm.tm_min = 0;
724 timedate[1] = 0; 711 tm.tm_sec = 0;
725 /* second */ 712 tm.tm_mday = 1;
726 timedate[2] = 0; 713 tm.tm_mon = 0;
727 /* year */ 714 tm.tm_wday = 1;
728 timedate[3] = 3; 715 tm.tm_year = 100;
729 /* month */
730 timedate[4] = 1;
731 /* day */
732 timedate[5] = 1;
733 } 716 }
734 717
735 result = set_time(str(LANG_TIME),timedate); 718 result = set_time_screen(str(LANG_TIME), &tm);
736 719
737 if(timedate[0] != -1) { 720 if(tm.tm_year != -1) {
738 /* hour */ 721 set_time(&tm);
739 timedate[0] = ((timedate[0]/10) << 4 | timedate[0]%10) & 0x3f;
740 /* minute */
741 timedate[1] = ((timedate[1]/10) << 4 | timedate[1]%10) & 0x7f;
742 /* second */
743 timedate[2] = ((timedate[2]/10) << 4 | timedate[2]%10) & 0x7f;
744 /* year */
745 timedate[3] = ((timedate[3]/10) << 4 | timedate[3]%10) & 0xff;
746 /* month */
747 timedate[4] = ((timedate[4]/10) << 4 | timedate[4]%10) & 0x1f;
748 /* day */
749 timedate[5] = ((timedate[5]/10) << 4 | timedate[5]%10) & 0x3f;
750
751 rtc_write(0x03, timedate[0] | (rtc_read(0x03) & 0xc0)); /* hour */
752 rtc_write(0x02, timedate[1] | (rtc_read(0x02) & 0x80)); /* minute */
753 rtc_write(0x01, timedate[2] | (rtc_read(0x01) & 0x80)); /* second */
754 rtc_write(0x07, timedate[3]); /* year */
755 rtc_write(0x06, timedate[4] | (rtc_read(0x06) & 0xe0)); /* month */
756 rtc_write(0x05, timedate[5] | (rtc_read(0x05) & 0xc0)); /* day */
757 rtc_write(0x04, timedate[6] | (rtc_read(0x04) & 0xf8)); /* dayofweek */
758 rtc_write(0x00, 0x00); /* 0.1 + 0.01 seconds */
759 } 722 }
760 return result; 723 return result;
761} 724}