File view
| 1 | #memmap xmem // Try to put as much code in xmem as possible |
| 2 | // By default, Dynamic C will try to fill up root code first |
| 3 | #class auto // Local variables on the stack |
| 4 | // By default, Dynamic C puts local variables in the heap |
| 5 | #nointerleave // Compile user functions before library functions |
| 6 | // in order to get error messages sooner |
| 7 | |
| 8 | /*** BeginHeader */ |
| 9 | |
| 10 | #ifndef __ISM_DATE_TIME_4711_ |
| 11 | #define __ISM_DATE_TIME_4711_ |
| 12 | |
| 13 | /*** EndHeader */ |
| 14 | |
| 15 | /*** BeginHeader |
| 16 | |
| 17 | InitializeDateTime, |
| 18 | TodStateHandler |
| 19 | */ |
| 20 | |
| 21 | void InitializeDateTime(); |
| 22 | int TodStateHandler(); |
| 23 | |
| 24 | /*** EndHeader */ |
| 25 | |
| 26 | int PreviousTodState; |
| 27 | int TodState; |
| 28 | |
| 29 | int currentYear; |
| 30 | int currentMonth; |
| 31 | int currentDay; |
| 32 | int currentHour; |
| 33 | int currentMinute; |
| 34 | |
| 35 | struct tm snapshotTod; |
| 36 | |
| 37 | // Local Function Prototypes |
| 38 | nodebug void YearSet(int first); |
| 39 | nodebug void MonthSet(int first); |
| 40 | nodebug void DaySet(int first); |
| 41 | nodebug void HourSet(int first); |
| 42 | nodebug void MinuteSet(int first); |
| 43 | |
| 44 | void initializeTodState(); |
| 45 | |
| 46 | enum |
| 47 | { |
| 48 | TODDONE = -2, |
| 49 | TODNOSTATE = -1, |
| 50 | YEARSTATE = 0, |
| 51 | MONTHSTATE, |
| 52 | DAYSTATE, |
| 53 | HOURSTATE, |
| 54 | MINUTESTATE |
| 55 | }; |
| 56 | |
| 57 | // Tod State Machine Table |
| 58 | void (*TodStateTable[5]) (); |
| 59 | |
| 60 | void InitializeDateTime() |
| 61 | { |
| 62 | initializeTodState(); |
| 63 | TodStateTable[0] = YearSet; |
| 64 | TodStateTable[1] = MonthSet; |
| 65 | TodStateTable[2] = DaySet; |
| 66 | TodStateTable[3] = HourSet; |
| 67 | TodStateTable[4] = MinuteSet; |
| 68 | } |
| 69 | |
| 70 | void initializeTodState() |
| 71 | { |
| 72 | TodState = TODDONE; |
| 73 | PreviousTodState = TODNOSTATE; |
| 74 | } |
| 75 | |
| 76 | // Tod State Handler |
| 77 | int exitFlag; |
| 78 | int TodStateHandler() |
| 79 | { |
| 80 | int first; |
| 81 | |
| 82 | exitFlag = 0; |
| 83 | if (TodState == TODDONE) |
| 84 | { |
| 85 | TodState = YEARSTATE; |
| 86 | GetTimeOfDay(&snapshotTod); |
| 87 | currentYear = snapshotTod.tm_year + 1900; |
| 88 | currentMonth = snapshotTod.tm_mon; |
| 89 | currentDay = snapshotTod.tm_mday; |
| 90 | currentHour = snapshotTod.tm_hour; |
| 91 | currentMinute = snapshotTod.tm_min; |
| 92 | } |
| 93 | |
| 94 | if (TodState == PreviousTodState) |
| 95 | first = 0; |
| 96 | else |
| 97 | first = 1; |
| 98 | PreviousTodState = TodState; |
| 99 | TodStateTable[TodState] (first); |
| 100 | |
| 101 | if (TodState == TODDONE) |
| 102 | { |
| 103 | SetTimeOfDay(currentYear, currentMonth, currentDay, |
| 104 | currentHour, currentMinute, 0); |
| 105 | return (exitFlag ? 2 : 1); |
| 106 | } |
| 107 | else |
| 108 | { |
| 109 | return 0; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | void YearSet(int first) |
| 114 | { |
| 115 | int aCode; |
| 116 | char value[6]; |
| 117 | |
| 118 | if (first) |
| 119 | { |
| 120 | sprintf(SetupTopLine, " SET DATE "); |
| 121 | sprintf(SetupBottomLine, " YEAR = %4d ", currentYear); |
| 122 | DisplayMsg(SetupTopLine, SetupBottomLine); |
| 123 | } |
| 124 | else if (GetKeyEdgeFlag()) |
| 125 | { |
| 126 | aCode = GetKeyCode(); |
| 127 | if (aCode == DOWNPB || aCode == UPPB) |
| 128 | { |
| 129 | UpdateDigit(aCode, SetupBottomLine, 9, 13, 1.0, 1900.0, 2099.0, GetFastFlag()); |
| 130 | } |
| 131 | else if (aCode == ENTERPB) |
| 132 | { |
| 133 | strncpy(value, SetupBottomLine+9, 4); |
| 134 | value[4] = '\0'; |
| 135 | currentYear = (int)atof(value); |
| 136 | printf("Year = %d\n", currentYear); |
| 137 | TodState = MONTHSTATE; |
| 138 | } |
| 139 | else if (aCode == SETUPPB) |
| 140 | { |
| 141 | strncpy(value, SetupBottomLine+9, 4); |
| 142 | value[4] = '\0'; |
| 143 | currentYear = (int)atof(value); |
| 144 | TodState = TODDONE; |
| 145 | } |
| 146 | DisplayMsg(SetupTopLine, SetupBottomLine); |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | void MonthSet(int first) |
| 151 | { |
| 152 | int aCode; |
| 153 | char value[6]; |
| 154 | |
| 155 | if (first) |
| 156 | { |
| 157 | sprintf(SetupTopLine, " SET DATE "); |
| 158 | sprintf(SetupBottomLine, " MONTH = %2d ", currentMonth); |
| 159 | DisplayMsg(SetupTopLine, SetupBottomLine); |
| 160 | } |
| 161 | else if (GetKeyEdgeFlag()) |
| 162 | { |
| 163 | aCode = GetKeyCode(); |
| 164 | if (aCode == DOWNPB || aCode == UPPB) |
| 165 | { |
| 166 | UpdateDigit(aCode, SetupBottomLine, 11, 13, 1.0, 1.0, 12.0, GetFastFlag()); |
| 167 | } |
| 168 | else if (aCode == ENTERPB) |
| 169 | { |
| 170 | strncpy(value, SetupBottomLine+11, 2); |
| 171 | value[2] = '\0'; |
| 172 | currentMonth = (int)atof(value); |
| 173 | printf("Month = %d\n",currentMonth); |
| 174 | TodState = DAYSTATE; |
| 175 | } |
| 176 | else if (aCode == SETUPPB) |
| 177 | { |
| 178 | strncpy(value, SetupBottomLine+11, 2); |
| 179 | value[2] = '\0'; |
| 180 | currentMonth = (int)atof(value); |
| 181 | TodState = TODDONE; |
| 182 | } |
| 183 | DisplayMsg(SetupTopLine, SetupBottomLine); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | void DaySet(int first) |
| 188 | { |
| 189 | int aCode; |
| 190 | char value[6]; |
| 191 | |
| 192 | if (first) |
| 193 | { |
| 194 | sprintf(SetupTopLine, " SET DATE "); |
| 195 | sprintf(SetupBottomLine, " DAY = %2d ", currentDay); |
| 196 | DisplayMsg(SetupTopLine, SetupBottomLine); |
| 197 | } |
| 198 | else if (GetKeyEdgeFlag()) |
| 199 | { |
| 200 | aCode = GetKeyCode(); |
| 201 | if (aCode == DOWNPB || aCode == UPPB) |
| 202 | { |
| 203 | UpdateDigit(aCode, SetupBottomLine, 10, 12, 1.0, 1.0, 31.0, GetFastFlag()); |
| 204 | } |
| 205 | else if (aCode == ENTERPB) |
| 206 | { |
| 207 | strncpy(value, SetupBottomLine+10, 2); |
| 208 | value[2] = '\0'; |
| 209 | currentDay = (int)atof(value); |
| 210 | printf("Day = %d\n",currentDay); |
| 211 | TodState = HOURSTATE; |
| 212 | } |
| 213 | else if (aCode == SETUPPB) |
| 214 | { |
| 215 | strncpy(value, SetupBottomLine+10, 2); |
| 216 | value[2] = '\0'; |
| 217 | currentDay = (int)atof(value); |
| 218 | TodState = TODDONE; |
| 219 | } |
| 220 | DisplayMsg(SetupTopLine, SetupBottomLine); |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | void HourSet(int first) |
| 225 | { |
| 226 | int aCode; |
| 227 | char value[6]; |
| 228 | |
| 229 | if (first) |
| 230 | { |
| 231 | sprintf(SetupTopLine, " SET TIME "); |
| 232 | sprintf(SetupBottomLine, " HOUR = %2d ", currentHour); |
| 233 | DisplayMsg(SetupTopLine, SetupBottomLine); |
| 234 | } |
| 235 | else if (GetKeyEdgeFlag()) |
| 236 | { |
| 237 | aCode = GetKeyCode(); |
| 238 | if (aCode == DOWNPB || aCode == UPPB) |
| 239 | { |
| 240 | UpdateDigit(aCode, SetupBottomLine, 10, 12, 1.0, 0.0, 23.0, GetFastFlag()); |
| 241 | } |
| 242 | else if (aCode == ENTERPB) |
| 243 | { |
| 244 | strncpy(value, SetupBottomLine+10, 2); |
| 245 | value[2] = '\0'; |
| 246 | currentHour = (int)atof(value); |
| 247 | printf("Hour = %d\n",currentHour); |
| 248 | TodState = MINUTESTATE; |
| 249 | } |
| 250 | else if (aCode == SETUPPB) |
| 251 | { |
| 252 | strncpy(value, SetupBottomLine+10, 2); |
| 253 | value[2] = '\0'; |
| 254 | currentHour = (int)atof(value); |
| 255 | TodState = TODDONE; |
| 256 | } |
| 257 | DisplayMsg(SetupTopLine, SetupBottomLine); |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | void MinuteSet(int first) |
| 262 | { |
| 263 | int aCode; |
| 264 | char value[6]; |
| 265 | |
| 266 | if (first) |
| 267 | { |
| 268 | sprintf(SetupTopLine, " SET TIME "); |
| 269 | sprintf(SetupBottomLine, " MINUTE = %2d ", currentMinute); |
| 270 | DisplayMsg(SetupTopLine, SetupBottomLine); |
| 271 | } |
| 272 | else if (GetKeyEdgeFlag()) |
| 273 | { |
| 274 | aCode = GetKeyCode(); |
| 275 | if (aCode == DOWNPB || aCode == UPPB) |
| 276 | { |
| 277 | UpdateDigit(aCode, SetupBottomLine, 11, 13, 1.0, 0.0, 59.0, GetFastFlag()); |
| 278 | } |
| 279 | else if (aCode == ENTERPB) |
| 280 | { |
| 281 | strncpy(value, SetupBottomLine+11, 2); |
| 282 | value[2] = '\0'; |
| 283 | currentMinute = (int)atof(value); |
| 284 | printf("Minute = %d\n",currentMinute); |
| 285 | TodState = YEARSTATE; |
| 286 | } |
| 287 | else if (aCode == SETUPPB) |
| 288 | { |
| 289 | strncpy(value, SetupBottomLine+11, 2); |
| 290 | value[2] = '\0'; |
| 291 | currentMinute = (int)atof(value); |
| 292 | TodState = TODDONE; |
| 293 | } |
| 294 | DisplayMsg(SetupTopLine, SetupBottomLine); |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | /*** BeginHeader */ |
| 299 | #endif |
| 300 | /*** EndHeader */ |