-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy patheventproc.c
1650 lines (1496 loc) · 47.2 KB
/
eventproc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* -----------------------------------------------------------------------------
* ----- EVENTPROC.C -----
* ----- EASYPAY -----
* -----------------------------------------------------------------------------
*
* File Description:
* This file contains the event processing functions
*
* Table of Contents:
* (static functions)
* UpdateDisplay - write string to specific row and column
* DisplayMoney - write a number as a monetary value to a row,col
* DisplayTime - write a time in hh:mm:ss to a row,col
* ClearNumber - clear variables associated with recording numbers.
* ClearBalance - clear variables associated with account balance
* ClearParking - clear variables associated with parking status
* AddDigit - add a digit to the local number sequence.
* MobileGet - Get Mobile Top-Up of a spefici amount
* UpdateExitOrUndo - switch between *Exit* and *Undo* on number entry page
* ElapsedTime - get number of elapsed milliseconds since last call
* ConvertTimeToMin - convert integer time of hh:mm format to minutes
*
* (interrupt service routine functions)
* EventTimer - elapsed time counter
*
* (update functions)
* NoUpdate - do nothing
* UpdatePin - flash newest pin digit before hiding it.
* UpdateAccount - write in account balance on Account Page
* UpdatePark - write in parking space and time left
* UpdateParkSpace - write in current space or entered space
* UpdateParkTime - write in entered parking time
*
* (event processing functions)
* NoAction - do nothing
* ResetAction - reset system variables excluding state
* GetUserData - get user info from tapped EasyCard
* AddPinDigit - add a digit to the pin number sequence
* ProcessPin - process pin number
* ExitOrUndoDigit - Exit to welcome page or undo last digit entry
* GetAcctBalance - get user's account balance
* ProcessAcctRecharge - process EasyTopup
* GetParkStatus - get current parking status
* AddParkSpaceDigit - add parking space digit
* ProcessParkSpace - process parking space number
* AddParkTimeDigit - add parking time digit
* ProcessParkTime - process parking time number
* GetUtilityData - get user's utility meter #s
* MobileGetMtn100 - Get MTN VTU Recharge of 100, 200, 400, 750, 1500
* MobileGetMtn200
* MobileGetMtn400
* MobileGetMtn750
* MobileGetMtn1500
* MobileGetGlo100 - Get Glo QuickCharge of 100, 200, 500, 1000, 3000
* MobileGetGlo200
* MobileGetGlo500
* MobileGetGlo1000
* MobileGetGlo3000
* MobileGetAirtel100 - Get Airtel Top-up of 100, 200, 500, 1000
* MobileGetAirtel200
* MobileGetAirtel500
* MobileGetAirtel1000
* MobileGetEtisalat100 -Get Etisalat E-Top up of 100, 200, 500, 1000
* MobileGetEtisalat200
* MobileGetEtisalat500
* MobileGetEtisalat1000
*
*
* Assumptions:
* None
*
* Limitations:
* None
*
* Compiler:
* HI-TECH C Compiler for PIC18 MCUs (http://www.htsoft.com/)
*
* Revision History:
* Apr. 23, 2013 Nnoduka Eruchalu Initial Revision
* May 15, 2013 Nnoduka Eruchalu Changed name ConvertTime to
* ConvertTimeToMin
*/
#include <stdint.h> /* for uint*_t */
#include <stdlib.h> /* for size_t */
#include <htc.h>
#include "general.h"
#include "delay.h" /* for delay_s */
#include "lcd.h"
#include "interface.h"
#include "eventproc.h"
#include "data.h"
#include "smartcard.h"
/* shared variables have to be local to this file */
static uint32_t number; /* entered number sequences are saved here */
static uint8_t num_digits; /* number of entered digits */
static uint8_t updated_number; /* (bool) if the number is updated */
static uint32_t balance; /* account balance (in kobo) */
static uint8_t updated_balance; /* (bool) balance has been updated */
static uint32_t parking_space; /* parking space number */
static int32_t parking_time; /* parking time left */
/* (uints of 1/TIME_SCALE seconds) */
static uint8_t updated_space; /* (bool) parking space has been updated */
static uint32_t elapsed_ms; /* elapsed milliseconds */
static uint8_t uid_easycard[7]; /* UID of EasyCard */
static uint8_t uid_easytopup[7]; /* UID of EasyTopup */
/* static functions local to this file */
static void UpdateDisplay(uint8_t row, uint8_t col, const char *str);
static void DisplayMoney(uint8_t row, uint8_t col, uint32_t n);
static void DisplayTime(uint8_t row, uint8_t col, uint32_t time, uint8_t unit);
static void ClearNumber(void);
static void ClearBalance(void);
static void ClearParking(void);
static void UpdateExitOrUndo(void);
static void AddDigit(eventcode digit, uint8_t num_digits_limit);
static void MobileGet(uint32_t amount);
static uint32_t ElapsedTime(void);
static uint32_t ConvertTimeToMin(uint32_t time, uint8_t num_time_digits);
/*
* UpdateDisplay
* Description: Update the display with the passed in String starting
* from the specified row and column
*
* Arguments: row: 0-indexed LCD display row
* col: 0-indexed LCD display column
* str: string
* Return: None
*
* Input: None
* Output: None
*
* Operation: Set LCD Cursor, and Write the string.
*
* Error Handling: None
*
* Algorithms: None
* Data Strutures: None
*
* Shared Variables: None
*
* Revision History:
* Apr. 23, 2013 Nnoduka Eruchalu Initial Revision
*/
static void UpdateDisplay(uint8_t row, uint8_t col, const char *str)
{
LcdCursor(row, col); /* set LCD Cursor */
LcdWriteStr(str); /* write the string */
}
/*
* DisplayMoney
* Description: At the specified row and column, write a monetary value
* that is supplied in kobos.
* Example: n = 123456 becomes N1,234.56
* n = 0 becomes N0.00
*
* Arguments: row: 0-indexed LCD row
* col: 0-indexed LCD column
* n: monetary amount in kobos
* Return: None
*
* Input: None
* Output: None
*
* Operation: Write exactly 2 digits after a decimal point, and at least
* 1 digit before the decimal point. To ensure you get a
* digit before decimal point, use a do-while loop so that
* even if the number starts out as 0, it is written at least
* once.
*
* Error Handling: None
*
* Algorithms: None
* Data Strutures: None
*
* Shared Variables: None
*
* Revision History:
* Apr. 25, 2013 Nnoduka Eruchalu Initial Revision
*/
static void DisplayMoney(uint8_t row, uint8_t col, uint32_t n)
{
char retbuf[30]; /* allocate space for writing string */
char *p = &retbuf[sizeof(retbuf)-1];/* and prepare to start from end */
int i = 0; /* counter of chars written */
*p = '\0'; /* strings end with a null terminator */
do { /* pre-decimal point loop */
*--p = '0' + (n % 10); /* save next char in ASCII by adding '0'*/
n /= 10; /* and drop the saved char from number */
i++; /* 1 more digit written */
} while(i<2); /* write at least 2 digits b4 decimal pt*/
*--p = '.'; /* write decimal point */
i = 0; /* and reset counter for next loop */
do { /* comma insertion loop */
if ((i%3 == 0) && (i != 0)) { /* if on a 3rd digit */
*--p = ','; /* then next character is a comma */
}
*--p = '0' + (n % 10); /* save next char in ASCII by adding '0'*/
n /= 10; /* and drop the saved char from number */
i++; /* 1 more digit written */
} while (n != 0); /* keep going till number is exhausted */
*--p = NAIRA_CHAR; /* throw in currency logo */
UpdateDisplay(row, col, p); /* FINALLY, update display */
}
/*
* DisplayTime
* Description: At the specified row and column, write a time with format:
* hh:mm:ss
* Example: time = 721*60 becomes 12:01:00 or 12:01
* n = 0 becomes 00:00:00 or 00:00
*
* Arguments: row: 0-indexed LCD row
* col: 0-indexed LCD column
* time: in seconds or minutes
* unit: DISPLAYTIME_SECS or DIPLAYTIME_MINS
* Return: None
*
* Input: None
* Output: None
*
* Operation: time-separator is ':'
*
* Error Handling: None
*
* Algorithms: None
* Data Strutures: None
*
* Shared Variables: None
*
* Revision History:
* Apr. 26, 2013 Nnoduka Eruchalu Initial Revision
*/
static void DisplayTime(uint8_t row, uint8_t col, uint32_t time, uint8_t unit)
{
char retbuf[9]; /* hh:mm:ss is 8 chars and +1 for null-terminator */
char *p = &retbuf[sizeof(retbuf)-1]; /* prepare to start from end */
uint8_t tmp; /* saves hour, minutes, seconds */
int i=0;
*p = '\0'; /* strings end with NULL */
do {
if ((i%2 == 0) && (i != 0)) { /* write a colon after every 2 chars */
*--p = ':';
}
tmp = time%60; /* get a block: hh,mm, or ss */
*--p = '0'+(tmp%10); i++; /* write lower digit */
*--p = '0'+(tmp/10); i++; /* write upper digit */
time /= 60; /* drop the entire block */
} while (i < unit);
UpdateDisplay(row, col, p); /* FINALLY, update display */
}
/*
* ClearNumber
* Description: Clear the variables associated with entered numbers.
*
* Arguments: None
* Return: None
*
* Input: None
* Output: None
*
* Operation: reset number to 0, num_digits to 0, update_number to FALSE
*
* Error Handling: None
*
* Algorithms: None
* Data Strutures: None
*
* Shared Variables: None
*
* Revision History:
* Apr. 23, 2013 Nnoduka Eruchalu Initial Revision
*/
static void ClearNumber(void)
{
number = 0;
num_digits = 0;
updated_number = FALSE;
}
/*
* ClearBalance
* Description: Clear the variables associated with account balance.
*
* Arguments: None
* Return: None
*
* Input: None
* Output: None
*
* Operation: reset balance to 0, and flag indicating it has updated,
* updated_balance
*
* Error Handling: None
*
* Algorithms: None
* Data Strutures: None
*
* Shared Variables: None
*
* Revision History:
* Apr. 23, 2013 Nnoduka Eruchalu Initial Revision
*/
static void ClearBalance(void)
{
balance = 5000000; /* TODO: actually reset to 0 */
updated_balance = FALSE;
}
/*
* ClearParking
* Description: Clear the variables associated with parking status.
*
* Arguments: None
* Return: None
*
* Input: None
* Output: None
*
* Operation: reset parking_space to 0, parking_time to 0, and flags
* indicating space have been updated
* Call ElapsedTime() to reset elapsed_time
*
* Error Handling: None
*
* Algorithms: None
* Data Strutures: None
*
* Shared Variables: None
*
* Revision History:
* Apr. 23, 2013 Nnoduka Eruchalu Initial Revision
*/
static void ClearParking(void)
{
parking_space = 0;
parking_time = 0;
updated_space = FALSE;
ElapsedTime();
}
/*
* UpdateExitOrUndo
* Description: Appropriately select "exit" or "undo" on number entry pages
* and show the right text.
*
* Arguments: None
* Return: None
*
* Input: None
* Output: None
*
* Operation: Move cursor appopriately. If there is no digit on the page
* then can exit, else will be in undo mode.
*
* Error Handling: None
*
* Algorithms: None
* Data Strutures: None
*
* Shared Variables: None
*
* Revision History:
* Apr. 23, 2013 Nnoduka Eruchalu Initial Revision
*/
static void UpdateExitOrUndo(void)
{
LcdCursor(3,0); /* move cursor to row 3, column 0 */
if (num_digits > 0) /* if there are digits then in undo mode */
LcdWriteStr("*Undo*");
else /* else in exit mode */
LcdWriteStr("*Exit*");
}
/*
* EventTimer
* Description: This function keeps count of the number of milliseconds
* passing by. This procedure should be called every 1ms.
*
* Arguments: None
* Return: None
*
* Input: None
* Output: None
*
* Operation: increment elapsed_ms
*
* Error Handling: None
*
* Algorithms: None
* Data Strutures: None
*
* Shared Variables: elapsed_ms - read and modified
*
* Assumptions: Assumes elapsed_ms will be reset to 0 before it overflows
*
* Revision History:
* Apr. 26, 2013 Nnoduka Eruchalu Initial Revision
*/
void EventTimer(void)
{
elapsed_ms++;
}
/*
* NoUpdate
* Description: This function handles when a state has no update routine
* It just returns the current state as the next state.
*
* Arguments: curr_state - the current system state
* Return: nextstate - the next system state
*
* Input: None
* Output: None
*
* Operation: Return the argument.
*
* Error Handling: None
*
* Algorithms: None
* Data Strutures: None
*
* Shared Variables: None
*
* Revision History:
* Apr. 22, 2013 Nnoduka Eruchalu Initial Revision
*/
state NoUpdate(state curr_state)
{
return curr_state;
}
/*
* UpdatePin
* Description: Flash the newest pin digit before changing it to a '*'
*
* Arguments: curr_state - the current system state
* Return: nextstate - the next system state
*
* Input: None
* Output: None
*
* Operation: if there is a new digit, show the preceding digits as '*'
* Show this digit as it is for some time, then change it to
* '*'. Follow this up with updating the exit/undo
* functionality and resetting the updated_number flag, since
* the update has been handled.
*
* Error Handling: None
*
* Algorithms: None
* Data Strutures: None
*
* Shared Variables: None
*
* Revision History:
* Apr. 26, 2013 Nnoduka Eruchalu Initial Revision
*/
state UpdatePin(state curr_state)
{
int i; /* counter for loop through number digits */
if (updated_number) { /* only do update if pin number has changed */
UpdateExitOrUndo();
LcdCursor(1,8); /* center the pin number on row 1 */
for(i=0; i<num_digits-1; i++ ) LcdWrite('*'); /* hide earlier digits */
if (num_digits > 0) LcdWriteInt(number%10); /* show newest digit */
__delay_s(PIN_FLASH_TIME); /* really just a flash */
LcdCursor(1,8); /* prepare to overwrite what was just shown */
for(i=0; i<num_digits; i++ ) LcdWrite('*'); /* now hide all digits */
while(i++<NUM_PIN_DIGITS) LcdWrite(' '); /* blank out earlier writes */
LcdCursor(1,8+num_digits);
updated_number = FALSE;
}
return curr_state; /* current state doesn't change */
}
/*
* UpdateAccount
* Description: Show the updated account balance on the new page
*
* Arguments: curr_state - the current system state
* Return: nextstate - the next system state
*
* Input: None
* Output: None
*
* Operation: if there is an updated balance, show it on the account
* page.
* Then reset the updated_balance flag to FALSE, since
* the update has been handled.
*
* Error Handling: None
*
* Algorithms: None
* Data Strutures: None
*
* Shared Variables: None
*
* Revision History:
* Apr. 26, 2013 Nnoduka Eruchalu Initial Revision
*/
state UpdateAccount(state curr_state)
{
if (updated_balance) { /* only do work if there has been an update */
DisplayMoney(1,9, balance); /* display the new balance as*/
updated_balance = FALSE;
}
return curr_state;
}
/*
* UpdatePark
* Description: write in parking space and time left
*
* Arguments: curr_state - the current system state
* Return: nextstate - the next system state
*
* Input: None
* Output: None
*
* Operation: if there is an updated parking space, show it on the
* parking page.
* Then reset the updated_space flag to FALSE, since
* the update has been handled.
* display new parking time if time has elapsed
*
* Error Handling: None
*
* Algorithms: None
* Data Strutures: None
*
* Shared Variables: None
*
* Revision History:
* Apr. 26, 2013 Nnoduka Eruchalu Initial Revision
*/
state UpdatePark(state curr_state)
{
int32_t old_parking_time = parking_time;
if (updated_space) {
LcdCursor(0,12); LcdWriteInt(parking_space); /* write space number */
updated_space = FALSE;
}
/* always update the displayed time */
parking_time -= ElapsedTime(); /* get elapsed seconds */
if (parking_time < 0) /* but keep time */
parking_time = 0; /* non-negative */
/* if time has changed, update it in seconds */
if (parking_time/TIME_SCALE != old_parking_time/TIME_SCALE)
DisplayTime(1,12,parking_time/TIME_SCALE, DISPLAYTIME_SECS); /* update it (in secs) */
return curr_state;
}
/*
* UpdateParkSpace
* Description: write in current parking space or new space if one is
* entered
*
* Arguments: curr_state - the current system state
* Return: nextstate - the next system state
*
* Input: None
* Output: None
*
* Operation: Only run if there is a changed number digit.
* if there isn't an entered digit, display current space.
* else display currently entered sequence.
* Update Exit/Undo button and clear flag indicating a changed
* digit.
*
* Error Handling: None
*
* Algorithms: None
* Data Strutures: None
*
* Shared Variables: None
*
* Revision History:
* Apr. 27, 2013 Nnoduka Eruchalu Initial Revision
*/
state UpdateParkSpace(state curr_state)
{
if (updated_number) { /* only do update if space number has changed */
UpdateExitOrUndo();
LcdCursor(1,8); /* center the space number on row 1 */
if(num_digits > 0) /* write currently entered sequence if exists */
LcdWriteInt(number);
else /* else write in current space */
LcdWriteInt(parking_space);
updated_number = FALSE;
}
return curr_state; /* current state doesn't change */
}
/*
* UpdateParkTime
* Description: write in entered parking time
*
* Arguments: curr_state - the current system state
* Return: nextstate - the next system state
*
* Input: None
* Output: None
*
* Operation: Only run if there is a changed number digit.
* Display current entered sequence in hh:mm format
* Update Exit/Undo button and clear flag indicating a changed
* digit.
*
* Error Handling: None
*
* Algorithms: None
* Data Strutures: None
*
* Shared Variables: None
*
* Revision History:
* Apr. 27, 2013 Nnoduka Eruchalu Initial Revision
*/
state UpdateParkTime(state curr_state)
{
if (updated_number) { /* only do update if time number has changed */
UpdateExitOrUndo();
/* update it (in mins) */
DisplayTime(1,11,ConvertTimeToMin(number, num_digits), DISPLAYTIME_MINS);
/* place cursor after last written character and skip colon */
LcdCursor(1,11+((num_digits <= 2) ? num_digits : (num_digits+1)));
updated_number = FALSE;
}
return curr_state; /* current state doesn't change */
}
/*
* NoAction
* Description: This function handles an event when there is nothing to be
* done. It just returns next the next state.
*
* Arguments: nextstate- expected next state
* event - current event
* Return: nextstate- actual next state
*
* Input: None
* Output: None
*
* Operation: Return the argument.
*
* Error Handling: None
*
* Algorithms: None
* Data Strutures: None
*
* Shared Variables: None
*
* Revision History:
* Apr. 23, 2013 Nnoduka Eruchalu Initial Revision
*/
state NoAction(state nextstate, eventcode event)
{
return nextstate;
}
/*
* ResetAction
* Description: This function reset system variables excluding state.
*
* Arguments: nextstate- expected next state
* event - current event
* Return: nextstate- actual next state
*
* Input: None
* Output: None
*
* Operation: Clear variables and return the argument.
*
* Error Handling: None
*
* Algorithms: None
* Data Strutures: None
*
* Shared Variables: None
*
* Revision History:
* Apr. 23, 2013 Nnoduka Eruchalu Initial Revision
*/
state ResetAction(state nextstate, eventcode event)
{
ClearNumber();
ClearBalance();
ClearParking();
return nextstate;
}
/*
* GetUserData
* Description: Get user data from last tapped EasyCard
*
* Arguments: nextstate- expected next state
* event - current event
* Return: nextstate- actual next state
*
* Input: None
* Output: None
*
* Operation: Get user data from PICC
* End with a call to ResetAction()
*
* Error Handling: None
*
* Algorithms: None
* Data Strutures: None
*
* Shared Variables: None
*
* Revision History:
* May 16, 2013 Nnoduka Eruchalu Initial Revision
*/
state GetUserData(state nextstate, eventcode event)
{
size_t i;
mifare_tag *tag; /* EasyCard representation */
tag = GetCardTag();
for(i=0; i<7; i++) { /* copy UID from tag */
uid_easycard[i] = tag->uid[i];
}
return ResetAction(nextstate, event); /* perform action reset */
}
/*
* AddDigit
* Description: Add a digit to the pin number sequence
*
* Arguments: digit - digit to be added to number sequence
* num_digits_limit - maximum number of digits in sequence
* Return: None
*
* Input: None.
* Output: None
*
* Operation: If number of digits is less than num_digit_limit:
* Multiply current number by 10 then add the keycode value
* to it, and update number of digits entered.
*
* Error Handling: None.
*
* Algorithms: None
* Data Strutures: None
*
* Shared Variables: number - read and moified
* Assumptions: keycode values go 0 to 9 for corresponding keys <0> to <9>
*
* Revision History:
* Apr. 23, 2013 Nnoduka Eruchalu Initial Revision
*/
static void AddDigit(eventcode digit, uint8_t num_digits_limit)
{
if (num_digits < num_digits_limit) { /* if number not yet complete */
number = number*10 + digit; /* add in new digit and update */
num_digits += 1; /* number of digits thus far */
updated_number = TRUE; /* captured a new digit */
}
}
/*
* MobileGet
* Description: Function for getting mobile topup of a specific amount
*
* Arguments: amount: value of mobile recharge to process (in Naira)
* Return: None.
*
* Input: None
* Output: None
*
* Operation: Flash success message before returning home
*
* Error Handling: None
*
* Algorithms: None
* Data Strutures: None
*
* Shared Variables: None
*
* Revision History:
* Apr. 24, 2013 Nnoduka Eruchalu Initial Revision
* Apr. 25, 2013 Nnoduka Eruchalu Added DisplayMoney
*/
static void MobileGet(uint32_t amount)
{
/* update LCD */
UpdateDisplay(1, 0, " "); /* row 1, col 0 */
UpdateDisplay(2, 0, " Successful Top-Up "); /* row 2, col 0 */
UpdateDisplay(3, 0, "+ "); /* row 3, col 0 */
DisplayMoney(3, 1, amount*100); /* show amount of topup */
balance -= amount*100; /* update balance. */
__delay_s(MSG_FLASH_TIME); /* a msg flash takes time */
}
/*
* ElapsedTime
* Description: Get the number of ms that have elapsed since the last
* time this function was called.
*
* Arguments: None
* Return: elapsed milliseconds
*
* Input: None
* Output: None
*
* Operation: Ideally: set retval to 0, and exchange its value with
* elapsed_ms. This prevents critical code, gets the elapsed
* time and resets the counter.
* However the asm instruction, EXCH, used 16-bit registers
* So will simply turn off interrupts around critical code.
*
* Error Handling: None
*
* Algorithms: None
* Data Strutures: None
*
* Shared Variables: None
* Todo: Fix Critical code: Ideally this code should be:
* retval = 0;
* XCHG retval, elapsed_ms
* return retval
*
* Revision History:
* Apr. 26, 2013 Nnoduka Eruchalu Initial Revision
*/
static uint32_t ElapsedTime(void)
{
uint32_t retval;
retval = elapsed_ms; /* get elapsed time and clear counter */
elapsed_ms = 0;
return retval;
}
/*
* ConvertTimeToMin
* Description: Convert time argument of format hh:mm to minutes
* Example time = 1120 represents 11:20
* this is converted to 11*60 + 20 = 680 seconds
*
* Arguments: time - which represents hh:mm using 4 digits
* time_num_digits - number of digits entered thus far from
* left to right
* Return: actual number of minutes in the time argument
*
* Input: None
* Output: None
*
* Operation: Ideally: set retval to 0, and exchange its value with
* elapsed_ms. This prevents critical code, gets the elapsed
* time and resets the counter.
*
* Error Handling: None
*
* Algorithms: None
* Data Strutures: None
*
* Shared Variables: None
*
* Revision History:
* Apr. 26, 2013 Nnoduka Eruchalu Initial Revision
* May 15, 2013 Nnoduka Eruchalu Changed name ConvertTime to
* ConvertTimeToMin
*/
static uint32_t ConvertTimeToMin(uint32_t time, uint8_t num_time_digits)
{
uint8_t hours, minutes;
switch(num_time_digits) { /* break it into hours and minutes */
case 1: /* entered format is: h*:** */
hours = time*10;
minutes = 0;
break;
case 2: /* entered format is hh:** */
hours = time;
minutes = 0;
break;
case 3: /* entered format is hh:m* */
hours = time/10;
minutes = (time%10) * 10;
break;
case 4: /* entered format is hh:mm */
hours = time/100;
minutes = time%100;
break;
default: /* no time digits is 00:00 */
hours = 0;
minutes = 0;
break;
}
return (hours*60 + minutes); /* return converted time in minutes */
}
/*
* AddPinDigit
* Description: Add a digit to the pin number sequence
*
* Arguments: nextstate- expected next state
* event - entered digit
* Return: nextstate- actual next state
*
* Input: None.
* Output: None
*
* Operation: Add pin digit and stay within max number of pin digits.
*
* Error Handling: None.
*
* Algorithms: None
* Data Strutures: None
*
* Assumptions: None
*
* Revision History:
* Apr. 23, 2013 Nnoduka Eruchalu Initial Revision
* Apr. 24, 2013 Nnoduka Eruchalu Modified to use AddDigit()
*/
state AddPinDigit(state nextstate, eventcode event)
{
/* add pin digit up to number of allowed digits */
AddDigit(event, NUM_PIN_DIGITS);
return nextstate;
}
/*
* ProcessPin
* Description: Process the entered Pin Number.
*
* Arguments: nextstate- expected next state