summaryrefslogtreecommitdiff
path: root/apps/settings.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/settings.c')
-rw-r--r--apps/settings.c108
1 files changed, 59 insertions, 49 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();