summaryrefslogtreecommitdiff
path: root/apps/screens.c
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2004-04-21 06:49:12 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2004-04-21 06:49:12 +0000
commit1de3dd570de9a223ef6294159047ce272859e388 (patch)
tree46bb5129a222116ff837fc0c657c15ee386bfdde /apps/screens.c
parenta1273a4f2ea4bbbecb52967a1be42bd3e54bcfb7 (diff)
downloadrockbox-1de3dd570de9a223ef6294159047ce272859e388.tar.gz
rockbox-1de3dd570de9a223ef6294159047ce272859e388.zip
Moved set_time_screen() to screens.c
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4534 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/screens.c')
-rw-r--r--apps/screens.c287
1 files changed, 287 insertions, 0 deletions
diff --git a/apps/screens.c b/apps/screens.c
index c2320a0217..9e24ba9a18 100644
--- a/apps/screens.c
+++ b/apps/screens.c
@@ -38,6 +38,7 @@
38#include "powermgmt.h" 38#include "powermgmt.h"
39#include "adc.h" 39#include "adc.h"
40#include "action.h" 40#include "action.h"
41#include "talk.h"
41 42
42#ifdef HAVE_LCD_BITMAP 43#ifdef HAVE_LCD_BITMAP
43#define BMPHEIGHT_usb_logo 32 44#define BMPHEIGHT_usb_logo 32
@@ -809,3 +810,289 @@ void charging_splash(void)
809 splash(2*HZ, true, str(LANG_BATTERY_CHARGE)); 810 splash(2*HZ, true, str(LANG_BATTERY_CHARGE));
810 while (button_get(false)); 811 while (button_get(false));
811} 812}
813
814
815#ifdef HAVE_LCD_BITMAP
816
817/* little helper function for voice output */
818static void say_time(int cursorpos, struct tm *tm)
819{
820 const int unit[] = { UNIT_HOUR, UNIT_MIN, UNIT_SEC, 0, 0, 0 };
821 int value = 0;
822
823 if (!global_settings.talk_menu)
824 return;
825
826 switch(cursorpos)
827 {
828 case 0:
829 value = tm->tm_hour;
830 break;
831 case 1:
832 value = tm->tm_min;
833 break;
834 case 2:
835 value = tm->tm_sec;
836 break;
837 case 3:
838 value = tm->tm_year + 1900;
839 break;
840 case 5:
841 value = tm->tm_mday;
842 break;
843 }
844
845 if (cursorpos == 4) /* month */
846 talk_id(LANG_MONTH_JANUARY + value - 1, false);
847 else
848 talk_value(value, unit[cursorpos], false);
849}
850
851
852#define INDEX_X 0
853#define INDEX_Y 1
854#define INDEX_WIDTH 2
855bool set_time_screen(char* string, struct tm *tm)
856{
857 bool done = false;
858 int button;
859 int min = 0, steps = 0;
860 int cursorpos = 0;
861 int lastcursorpos = !cursorpos;
862 unsigned char buffer[19];
863 int realyear;
864 int julianday;
865 int i;
866 unsigned char reffub[5];
867 unsigned int width, height;
868 unsigned int separator_width, weekday_width;
869 unsigned int line_height, prev_line_height;
870 const int dayname[] = {LANG_WEEKDAY_SUNDAY,
871 LANG_WEEKDAY_MONDAY,
872 LANG_WEEKDAY_TUESDAY,
873 LANG_WEEKDAY_WEDNESDAY,
874 LANG_WEEKDAY_THURSDAY,
875 LANG_WEEKDAY_FRIDAY,
876 LANG_WEEKDAY_SATURDAY};
877 const int monthname[] = {LANG_MONTH_JANUARY,
878 LANG_MONTH_FEBRUARY,
879 LANG_MONTH_MARCH,
880 LANG_MONTH_APRIL,
881 LANG_MONTH_MAY,
882 LANG_MONTH_JUNE,
883 LANG_MONTH_JULY,
884 LANG_MONTH_AUGUST,
885 LANG_MONTH_SEPTEMBER,
886 LANG_MONTH_OCTOBER,
887 LANG_MONTH_NOVEMBER,
888 LANG_MONTH_DECEMBER};
889 char cursor[][3] = {{ 0, 8, 12}, {18, 8, 12}, {36, 8, 12},
890 {24, 16, 24}, {54, 16, 18}, {78, 16, 12}};
891 char daysinmonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
892
893 int monthname_len = 0, dayname_len = 0;
894
895 int *valptr = NULL;
896
897#ifdef HAVE_LCD_BITMAP
898 if(global_settings.statusbar)
899 lcd_setmargins(0, STATUSBAR_HEIGHT);
900 else
901 lcd_setmargins(0, 0);
902#endif
903 lcd_clear_display();
904 lcd_puts_scroll(0, 0, string);
905
906 while ( !done ) {
907 /* calculate the number of days in febuary */
908 realyear = tm->tm_year + 1900;
909 if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0)
910 daysinmonth[1] = 29;
911 else
912 daysinmonth[1] = 28;
913
914 /* fix day if month or year changed */
915 if (tm->tm_mday > daysinmonth[tm->tm_mon])
916 tm->tm_mday = daysinmonth[tm->tm_mon];
917
918 /* calculate day of week */
919 julianday = 0;
920 for(i = 0; i < tm->tm_mon; i++) {
921 julianday += daysinmonth[i];
922 }
923 julianday += tm->tm_mday;
924 tm->tm_wday = (realyear + julianday + (realyear - 1) / 4 -
925 (realyear - 1) / 100 + (realyear - 1) / 400 + 7 - 1) % 7;
926
927 snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d ",
928 tm->tm_hour, tm->tm_min, tm->tm_sec);
929 lcd_puts(0, 1, buffer);
930
931 /* recalculate the positions and offsets */
932 lcd_getstringsize(string, &width, &prev_line_height);
933 lcd_getstringsize(buffer, &width, &line_height);
934 lcd_getstringsize(":", &separator_width, &height);
935
936 /* hour */
937 strncpy(reffub, buffer, 2);
938 reffub[2] = '\0';
939 lcd_getstringsize(reffub, &width, &height);
940 cursor[0][INDEX_X] = 0;
941 cursor[0][INDEX_Y] = prev_line_height;
942 cursor[0][INDEX_WIDTH] = width;
943
944 /* minute */
945 strncpy(reffub, buffer + 3, 2);
946 reffub[2] = '\0';
947 lcd_getstringsize(reffub, &width, &height);
948 cursor[1][INDEX_X] = cursor[0][INDEX_WIDTH] + separator_width;
949 cursor[1][INDEX_Y] = prev_line_height;
950 cursor[1][INDEX_WIDTH] = width;
951
952 /* second */
953 strncpy(reffub, buffer + 6, 2);
954 reffub[2] = '\0';
955 lcd_getstringsize(reffub, &width, &height);
956 cursor[2][INDEX_X] = cursor[0][INDEX_WIDTH] + separator_width +
957 cursor[1][INDEX_WIDTH] + separator_width;
958 cursor[2][INDEX_Y] = prev_line_height;
959 cursor[2][INDEX_WIDTH] = width;
960
961 lcd_getstringsize(buffer, &width, &prev_line_height);
962
963 snprintf(buffer, sizeof(buffer), "%s %04d %s %02d ",
964 str(dayname[tm->tm_wday]), tm->tm_year+1900,
965 str(monthname[tm->tm_mon]), tm->tm_mday);
966 lcd_puts(0, 2, buffer);
967
968 /* recalculate the positions and offsets */
969 lcd_getstringsize(buffer, &width, &line_height);
970
971 /* store these 2 to prevent _repeated_ strlen calls */
972 monthname_len = strlen(str(monthname[tm->tm_mon]));
973 dayname_len = strlen(str(dayname[tm->tm_wday]));
974
975 /* weekday */
976 strncpy(reffub, buffer, dayname_len);
977 reffub[dayname_len] = '\0';
978 lcd_getstringsize(reffub, &weekday_width, &height);
979 lcd_getstringsize(" ", &separator_width, &height);
980
981 /* year */
982 strncpy(reffub, buffer + dayname_len + 1, 4);
983 reffub[4] = '\0';
984 lcd_getstringsize(reffub, &width, &height);
985 cursor[3][INDEX_X] = weekday_width + separator_width;
986 cursor[3][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height;
987 cursor[3][INDEX_WIDTH] = width;
988
989 /* month */
990 strncpy(reffub, buffer + dayname_len + 6, monthname_len);
991 reffub[monthname_len] = '\0';
992 lcd_getstringsize(reffub, &width, &height);
993 cursor[4][INDEX_X] = weekday_width + separator_width +
994 cursor[3][INDEX_WIDTH] + separator_width;
995 cursor[4][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height;
996 cursor[4][INDEX_WIDTH] = width;
997
998 /* day */
999 strncpy(reffub, buffer + dayname_len + monthname_len + 7, 2);
1000 reffub[2] = '\0';
1001 lcd_getstringsize(reffub, &width, &height);
1002 cursor[5][INDEX_X] = weekday_width + separator_width +
1003 cursor[3][INDEX_WIDTH] + separator_width +
1004 cursor[4][INDEX_WIDTH] + separator_width;
1005 cursor[5][INDEX_Y] = cursor[0][INDEX_Y] + prev_line_height;
1006 cursor[5][INDEX_WIDTH] = width;
1007
1008 lcd_invertrect(cursor[cursorpos][INDEX_X],
1009 cursor[cursorpos][INDEX_Y] + lcd_getymargin(),
1010 cursor[cursorpos][INDEX_WIDTH],
1011 line_height);
1012
1013 lcd_puts(0, 4, str(LANG_TIME_SET));
1014 lcd_puts(0, 5, str(LANG_TIME_REVERT));
1015#ifdef HAVE_LCD_BITMAP
1016 status_draw(true);
1017#endif
1018 lcd_update();
1019
1020 /* calculate the minimum and maximum for the number under cursor */
1021 if(cursorpos!=lastcursorpos) {
1022 lastcursorpos=cursorpos;
1023 switch(cursorpos) {
1024 case 0: /* hour */
1025 min = 0;
1026 steps = 24;
1027 valptr = &tm->tm_hour;
1028 break;
1029 case 1: /* minute */
1030 min = 0;
1031 steps = 60;
1032 valptr = &tm->tm_min;
1033 break;
1034 case 2: /* second */
1035 min = 0;
1036 steps = 60;
1037 valptr = &tm->tm_sec;
1038 break;
1039 case 3: /* year */
1040 min = 1;
1041 steps = 200;
1042 valptr = &tm->tm_year;
1043 break;
1044 case 4: /* month */
1045 min = 0;
1046 steps = 12;
1047 valptr = &tm->tm_mon;
1048 break;
1049 case 5: /* day */
1050 min = 1;
1051 steps = daysinmonth[tm->tm_mon];
1052 valptr = &tm->tm_mday;
1053 break;
1054 }
1055 say_time(cursorpos, tm);
1056 }
1057
1058 button = button_get_w_tmo(HZ/2);
1059 switch ( button ) {
1060 case BUTTON_LEFT:
1061 cursorpos = (cursorpos + 6 - 1) % 6;
1062 break;
1063 case BUTTON_RIGHT:
1064 cursorpos = (cursorpos + 6 + 1) % 6;
1065 break;
1066 case BUTTON_UP:
1067 case BUTTON_UP | BUTTON_REPEAT:
1068 *valptr = (*valptr + steps - min + 1) %
1069 steps + min;
1070 if(*valptr == 0)
1071 *valptr = min;
1072 say_time(cursorpos, tm);
1073 break;
1074 case BUTTON_DOWN:
1075 case BUTTON_DOWN | BUTTON_REPEAT:
1076 *valptr = (*valptr + steps - min - 1) %
1077 steps + min;
1078 if(*valptr == 0)
1079 *valptr = min;
1080 say_time(cursorpos, tm);
1081 break;
1082 case BUTTON_ON:
1083 done = true;
1084 break;
1085 case BUTTON_OFF:
1086 done = true;
1087 tm->tm_year = -1;
1088 break;
1089
1090 case SYS_USB_CONNECTED:
1091 usb_screen();
1092 return true;
1093 }
1094 }
1095
1096 return false;
1097}
1098#endif