Release 1.01
EditTimeMenu.cpp@3:8395f7ab6d3e, 2019-07-25 (annotated)
- Committer:
- foxbrianr
- Date:
- Thu Jul 25 00:42:49 2019 +0000
- Revision:
- 3:8395f7ab6d3e
- Child:
- 4:7226c43320b5
Baseline for testing
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
foxbrianr | 3:8395f7ab6d3e | 1 | #include "mbed.h" |
foxbrianr | 3:8395f7ab6d3e | 2 | #include "EditTimeMenu.h" |
foxbrianr | 3:8395f7ab6d3e | 3 | #include "TimeUtilities.h" |
foxbrianr | 3:8395f7ab6d3e | 4 | |
foxbrianr | 3:8395f7ab6d3e | 5 | |
foxbrianr | 3:8395f7ab6d3e | 6 | RealTimeClock rtc; |
foxbrianr | 3:8395f7ab6d3e | 7 | |
foxbrianr | 3:8395f7ab6d3e | 8 | |
foxbrianr | 3:8395f7ab6d3e | 9 | EditTimeMenu::EditTimeMenu(string id): Menu(id) |
foxbrianr | 3:8395f7ab6d3e | 10 | { |
foxbrianr | 3:8395f7ab6d3e | 11 | |
foxbrianr | 3:8395f7ab6d3e | 12 | active_selection = 0; |
foxbrianr | 3:8395f7ab6d3e | 13 | row=0; |
foxbrianr | 3:8395f7ab6d3e | 14 | column=0; |
foxbrianr | 3:8395f7ab6d3e | 15 | |
foxbrianr | 3:8395f7ab6d3e | 16 | time_t rawtime; |
foxbrianr | 3:8395f7ab6d3e | 17 | struct tm * timeinfo; |
foxbrianr | 3:8395f7ab6d3e | 18 | |
foxbrianr | 3:8395f7ab6d3e | 19 | time ( &rawtime ); |
foxbrianr | 3:8395f7ab6d3e | 20 | timeinfo = localtime ( &rawtime ); timeinfo = localtime (&rawtime); |
foxbrianr | 3:8395f7ab6d3e | 21 | |
foxbrianr | 3:8395f7ab6d3e | 22 | hours = timeinfo->tm_hour; |
foxbrianr | 3:8395f7ab6d3e | 23 | mins = timeinfo->tm_min; |
foxbrianr | 3:8395f7ab6d3e | 24 | secs = timeinfo->tm_sec; |
foxbrianr | 3:8395f7ab6d3e | 25 | |
foxbrianr | 3:8395f7ab6d3e | 26 | years = timeinfo->tm_year + 1900; |
foxbrianr | 3:8395f7ab6d3e | 27 | months = timeinfo->tm_mon + 1 ; |
foxbrianr | 3:8395f7ab6d3e | 28 | days = timeinfo->tm_mday; |
foxbrianr | 3:8395f7ab6d3e | 29 | |
foxbrianr | 3:8395f7ab6d3e | 30 | |
foxbrianr | 3:8395f7ab6d3e | 31 | } |
foxbrianr | 3:8395f7ab6d3e | 32 | |
foxbrianr | 3:8395f7ab6d3e | 33 | |
foxbrianr | 3:8395f7ab6d3e | 34 | |
foxbrianr | 3:8395f7ab6d3e | 35 | void EditTimeMenu::display(LCD * lcd) |
foxbrianr | 3:8395f7ab6d3e | 36 | { |
foxbrianr | 3:8395f7ab6d3e | 37 | char setTime = 1; |
foxbrianr | 3:8395f7ab6d3e | 38 | char setDate = 1; |
foxbrianr | 3:8395f7ab6d3e | 39 | |
foxbrianr | 3:8395f7ab6d3e | 40 | char current[40]; |
foxbrianr | 3:8395f7ab6d3e | 41 | |
foxbrianr | 3:8395f7ab6d3e | 42 | time_t rawtime; |
foxbrianr | 3:8395f7ab6d3e | 43 | struct tm * timeinfo; |
foxbrianr | 3:8395f7ab6d3e | 44 | |
foxbrianr | 3:8395f7ab6d3e | 45 | time ( &rawtime ); |
foxbrianr | 3:8395f7ab6d3e | 46 | timeinfo = localtime ( &rawtime ); timeinfo = localtime (&rawtime); |
foxbrianr | 3:8395f7ab6d3e | 47 | |
foxbrianr | 3:8395f7ab6d3e | 48 | if (!active_selection){ |
foxbrianr | 3:8395f7ab6d3e | 49 | hours = timeinfo->tm_hour; |
foxbrianr | 3:8395f7ab6d3e | 50 | mins = timeinfo->tm_min; |
foxbrianr | 3:8395f7ab6d3e | 51 | secs = timeinfo->tm_sec; |
foxbrianr | 3:8395f7ab6d3e | 52 | years = timeinfo->tm_year+1900; |
foxbrianr | 3:8395f7ab6d3e | 53 | months = timeinfo->tm_mon + 1; |
foxbrianr | 3:8395f7ab6d3e | 54 | days = timeinfo->tm_mday; |
foxbrianr | 3:8395f7ab6d3e | 55 | lcd->setCursorMode (0) ; |
foxbrianr | 3:8395f7ab6d3e | 56 | } |
foxbrianr | 3:8395f7ab6d3e | 57 | else |
foxbrianr | 3:8395f7ab6d3e | 58 | { |
foxbrianr | 3:8395f7ab6d3e | 59 | // edit mode |
foxbrianr | 3:8395f7ab6d3e | 60 | secs = timeinfo->tm_sec; |
foxbrianr | 3:8395f7ab6d3e | 61 | lcd->setCursorMode (1) ; |
foxbrianr | 3:8395f7ab6d3e | 62 | } |
foxbrianr | 3:8395f7ab6d3e | 63 | |
foxbrianr | 3:8395f7ab6d3e | 64 | switch(active_selection) |
foxbrianr | 3:8395f7ab6d3e | 65 | { |
foxbrianr | 3:8395f7ab6d3e | 66 | case 1: |
foxbrianr | 3:8395f7ab6d3e | 67 | lcd->writeLine(0,"Set Time (hours) :"); |
foxbrianr | 3:8395f7ab6d3e | 68 | break; |
foxbrianr | 3:8395f7ab6d3e | 69 | case 2: |
foxbrianr | 3:8395f7ab6d3e | 70 | lcd->writeLine(0,"Set Time (min) :"); |
foxbrianr | 3:8395f7ab6d3e | 71 | break; |
foxbrianr | 3:8395f7ab6d3e | 72 | case 3: |
foxbrianr | 3:8395f7ab6d3e | 73 | lcd->writeLine(0,"Set Time (sec) :"); |
foxbrianr | 3:8395f7ab6d3e | 74 | break; |
foxbrianr | 3:8395f7ab6d3e | 75 | case 4: |
foxbrianr | 3:8395f7ab6d3e | 76 | lcd->writeLine(0,"Set Date (month) :"); |
foxbrianr | 3:8395f7ab6d3e | 77 | break; |
foxbrianr | 3:8395f7ab6d3e | 78 | case 5: |
foxbrianr | 3:8395f7ab6d3e | 79 | lcd->writeLine(0,"Set Date (day) :"); |
foxbrianr | 3:8395f7ab6d3e | 80 | break; |
foxbrianr | 3:8395f7ab6d3e | 81 | case 6: |
foxbrianr | 3:8395f7ab6d3e | 82 | lcd->writeLine(0,"Set Date (year) :"); |
foxbrianr | 3:8395f7ab6d3e | 83 | break; |
foxbrianr | 3:8395f7ab6d3e | 84 | default: |
foxbrianr | 3:8395f7ab6d3e | 85 | lcd->writeLine(0,"Current Time/Date :"); |
foxbrianr | 3:8395f7ab6d3e | 86 | break; |
foxbrianr | 3:8395f7ab6d3e | 87 | }; |
foxbrianr | 3:8395f7ab6d3e | 88 | //rtc.GetTimeString(buf); |
foxbrianr | 3:8395f7ab6d3e | 89 | //sprintf(current,"%02d:%02d:%02d", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); |
foxbrianr | 3:8395f7ab6d3e | 90 | |
foxbrianr | 3:8395f7ab6d3e | 91 | if (setTime) { |
foxbrianr | 3:8395f7ab6d3e | 92 | sprintf(current,"%02d:%02d", hours,mins); |
foxbrianr | 3:8395f7ab6d3e | 93 | lcd->writeLine(1,current); |
foxbrianr | 3:8395f7ab6d3e | 94 | } |
foxbrianr | 3:8395f7ab6d3e | 95 | |
foxbrianr | 3:8395f7ab6d3e | 96 | if (setDate) { |
foxbrianr | 3:8395f7ab6d3e | 97 | sprintf(current,"%02d/%02d/%02d", months, days, years); |
foxbrianr | 3:8395f7ab6d3e | 98 | lcd->writeLine(2,current); |
foxbrianr | 3:8395f7ab6d3e | 99 | } |
foxbrianr | 3:8395f7ab6d3e | 100 | |
foxbrianr | 3:8395f7ab6d3e | 101 | |
foxbrianr | 3:8395f7ab6d3e | 102 | } |
foxbrianr | 3:8395f7ab6d3e | 103 | |
foxbrianr | 3:8395f7ab6d3e | 104 | void EditTimeMenu::pressMode() |
foxbrianr | 3:8395f7ab6d3e | 105 | { |
foxbrianr | 3:8395f7ab6d3e | 106 | // advance thru |
foxbrianr | 3:8395f7ab6d3e | 107 | if (active_selection++ > 6 ) |
foxbrianr | 3:8395f7ab6d3e | 108 | active_selection = 0; |
foxbrianr | 3:8395f7ab6d3e | 109 | |
foxbrianr | 3:8395f7ab6d3e | 110 | update_needed = 1; |
foxbrianr | 3:8395f7ab6d3e | 111 | } |
foxbrianr | 3:8395f7ab6d3e | 112 | |
foxbrianr | 3:8395f7ab6d3e | 113 | void EditTimeMenu::pressSet() |
foxbrianr | 3:8395f7ab6d3e | 114 | { |
foxbrianr | 3:8395f7ab6d3e | 115 | |
foxbrianr | 3:8395f7ab6d3e | 116 | struct tm t; |
foxbrianr | 3:8395f7ab6d3e | 117 | |
foxbrianr | 3:8395f7ab6d3e | 118 | t.tm_hour = hours; |
foxbrianr | 3:8395f7ab6d3e | 119 | t.tm_min = mins; |
foxbrianr | 3:8395f7ab6d3e | 120 | t.tm_sec = 0; |
foxbrianr | 3:8395f7ab6d3e | 121 | |
foxbrianr | 3:8395f7ab6d3e | 122 | t.tm_year = years - 1900; |
foxbrianr | 3:8395f7ab6d3e | 123 | t.tm_mon = months - 1; |
foxbrianr | 3:8395f7ab6d3e | 124 | t.tm_mday = days; |
foxbrianr | 3:8395f7ab6d3e | 125 | |
foxbrianr | 3:8395f7ab6d3e | 126 | // set the time |
foxbrianr | 3:8395f7ab6d3e | 127 | set_time(mktime(&t)); |
foxbrianr | 3:8395f7ab6d3e | 128 | |
foxbrianr | 3:8395f7ab6d3e | 129 | |
foxbrianr | 3:8395f7ab6d3e | 130 | // go back to normal display |
foxbrianr | 3:8395f7ab6d3e | 131 | // --------------------------------- |
foxbrianr | 3:8395f7ab6d3e | 132 | active_selection = 0; |
foxbrianr | 3:8395f7ab6d3e | 133 | update_needed = 1; |
foxbrianr | 3:8395f7ab6d3e | 134 | } |
foxbrianr | 3:8395f7ab6d3e | 135 | |
foxbrianr | 3:8395f7ab6d3e | 136 | void EditTimeMenu::pressUp() |
foxbrianr | 3:8395f7ab6d3e | 137 | { |
foxbrianr | 3:8395f7ab6d3e | 138 | switch(active_selection) |
foxbrianr | 3:8395f7ab6d3e | 139 | { |
foxbrianr | 3:8395f7ab6d3e | 140 | case 1: hours++;break; |
foxbrianr | 3:8395f7ab6d3e | 141 | case 2: mins++;break; |
foxbrianr | 3:8395f7ab6d3e | 142 | case 3: secs++;break; |
foxbrianr | 3:8395f7ab6d3e | 143 | case 4: months++;break; |
foxbrianr | 3:8395f7ab6d3e | 144 | case 5: days++;break; |
foxbrianr | 3:8395f7ab6d3e | 145 | case 6: years++;break; |
foxbrianr | 3:8395f7ab6d3e | 146 | default:break; |
foxbrianr | 3:8395f7ab6d3e | 147 | |
foxbrianr | 3:8395f7ab6d3e | 148 | } |
foxbrianr | 3:8395f7ab6d3e | 149 | if (hours > 23) hours = 0; |
foxbrianr | 3:8395f7ab6d3e | 150 | if (mins > 60) mins = 0; |
foxbrianr | 3:8395f7ab6d3e | 151 | if (secs > 60) secs = 0; |
foxbrianr | 3:8395f7ab6d3e | 152 | if (months > 12) months = 1; |
foxbrianr | 3:8395f7ab6d3e | 153 | if (days > 31) days = 1; |
foxbrianr | 3:8395f7ab6d3e | 154 | if (years > 2050) years =2011; |
foxbrianr | 3:8395f7ab6d3e | 155 | |
foxbrianr | 3:8395f7ab6d3e | 156 | update_needed = 1; |
foxbrianr | 3:8395f7ab6d3e | 157 | } |
foxbrianr | 3:8395f7ab6d3e | 158 | |
foxbrianr | 3:8395f7ab6d3e | 159 | void EditTimeMenu::pressDown() |
foxbrianr | 3:8395f7ab6d3e | 160 | { |
foxbrianr | 3:8395f7ab6d3e | 161 | switch(active_selection) |
foxbrianr | 3:8395f7ab6d3e | 162 | { |
foxbrianr | 3:8395f7ab6d3e | 163 | case 1: hours--;break; |
foxbrianr | 3:8395f7ab6d3e | 164 | case 2: mins--;break; |
foxbrianr | 3:8395f7ab6d3e | 165 | case 3: secs--;break; |
foxbrianr | 3:8395f7ab6d3e | 166 | case 4: months--;break; |
foxbrianr | 3:8395f7ab6d3e | 167 | case 5: days--;break; |
foxbrianr | 3:8395f7ab6d3e | 168 | case 6: years--;break; |
foxbrianr | 3:8395f7ab6d3e | 169 | default:break; |
foxbrianr | 3:8395f7ab6d3e | 170 | |
foxbrianr | 3:8395f7ab6d3e | 171 | } |
foxbrianr | 3:8395f7ab6d3e | 172 | |
foxbrianr | 3:8395f7ab6d3e | 173 | if (hours < 0) hours += 23; |
foxbrianr | 3:8395f7ab6d3e | 174 | if (mins < 0) mins += 60; |
foxbrianr | 3:8395f7ab6d3e | 175 | if (secs < 0) secs += 60; |
foxbrianr | 3:8395f7ab6d3e | 176 | if (months < 1) months += 12; |
foxbrianr | 3:8395f7ab6d3e | 177 | if (days < 1) days += 31; |
foxbrianr | 3:8395f7ab6d3e | 178 | if (years < 2011) years =2050; |
foxbrianr | 3:8395f7ab6d3e | 179 | |
foxbrianr | 3:8395f7ab6d3e | 180 | update_needed = 1; |
foxbrianr | 3:8395f7ab6d3e | 181 | } |