A porting of a GPS decoding and presenting program within the mbos RTOS. It is not a definitive application but a study program to test NMEA full decoding library and a first approach to an RTOS. Many thanks to Andrew Levido for his support and his patience on teaching me the RTOS principles from the other side of the Earth. It uses NMEA library by Tim (xtimor@gmail.com) ported by Ken Todotani (http://mbed.org/users/todotani/) on public mbed library (http://mbed.org/users/todotani/programs/GPS_nmeaLib/5yo4h) also available, as original universal C library, on http://nmea.sourceforge.net

Dependencies:   mbos Watchdog TextLCD mbed ConfigFile

Committer:
guiott
Date:
Fri Feb 03 16:29:52 2012 +0000
Revision:
3:a2f9eb3b8a16
Parent:
2:8917036cbf69

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
guiott 2:8917036cbf69 1 #include "Task2Keypad.h"
guiott 2:8917036cbf69 2
guiott 2:8917036cbf69 3 void KeypadTask(void)
guiott 2:8917036cbf69 4 {/**
guiott 2:8917036cbf69 5 *\brief TASK 2, Keypad management.
guiott 2:8917036cbf69 6 It uses just one ADC port. Five keys switch a 5 resistor ladder
guiott 2:8917036cbf69 7 obtaining a unique voltage for each key, with a priority that
guiott 2:8917036cbf69 8 depends from the position of the resistor in the ladder.
guiott 2:8917036cbf69 9 This function makes an average of 50 analog values (50ms) before
guiott 2:8917036cbf69 10 confirming the output, to filter out some noise and debounce keys
guiott 2:8917036cbf69 11 */
guiott 2:8917036cbf69 12
guiott 2:8917036cbf69 13 static float KeypadAcc; // accumulator to compute average
guiott 2:8917036cbf69 14 static float KeypadPrev; // previous value to compute variation
guiott 2:8917036cbf69 15 static int KeypadCount; // all samples number
guiott 2:8917036cbf69 16 static int KeypadRealCount; // valid samples only
guiott 2:8917036cbf69 17 float KeypadVal;
guiott 2:8917036cbf69 18 static char KeyPrev='-';
guiott 2:8917036cbf69 19
guiott 2:8917036cbf69 20 os.SetTimer(KEYPAD_TMR, 1, 1);
guiott 2:8917036cbf69 21 while(1)
guiott 2:8917036cbf69 22 {
guiott 2:8917036cbf69 23 os.WaitEvent(KEYPAD_EVT);
guiott 2:8917036cbf69 24 float InValue = KeypadIn.read();
guiott 2:8917036cbf69 25 if ((InValue > 0.3) && (abs(InValue - KeypadPrev) < 0.1))
guiott 2:8917036cbf69 26 {// makes the average only of the values above a threshold
guiott 2:8917036cbf69 27 // and within an almost stable range
guiott 2:8917036cbf69 28 KeypadAcc+=InValue;
guiott 2:8917036cbf69 29 KeypadRealCount++;
guiott 2:8917036cbf69 30 }
guiott 2:8917036cbf69 31
guiott 2:8917036cbf69 32 KeypadCount++;
guiott 2:8917036cbf69 33 KeypadPrev=InValue;
guiott 2:8917036cbf69 34
guiott 2:8917036cbf69 35 if (KeypadCount >=50)
guiott 2:8917036cbf69 36 {
guiott 2:8917036cbf69 37 if(KeypadRealCount > 25)
guiott 2:8917036cbf69 38 {
guiott 2:8917036cbf69 39 KeypadVal=KeypadAcc/KeypadRealCount;
guiott 2:8917036cbf69 40 }
guiott 2:8917036cbf69 41 else
guiott 2:8917036cbf69 42 {// not enough values to average
guiott 2:8917036cbf69 43
guiott 2:8917036cbf69 44 KeypadVal=0;
guiott 2:8917036cbf69 45 }
guiott 2:8917036cbf69 46
guiott 2:8917036cbf69 47 KeypadAcc=0;
guiott 2:8917036cbf69 48 KeypadCount=0;
guiott 2:8917036cbf69 49 KeypadRealCount=0;
guiott 2:8917036cbf69 50
guiott 2:8917036cbf69 51 if(KeypadVal <0.15)
guiott 2:8917036cbf69 52 {
guiott 2:8917036cbf69 53 Key='-';
guiott 2:8917036cbf69 54 }
guiott 2:8917036cbf69 55 else if(KeypadVal>=0.3 && KeypadVal<0.35)
guiott 2:8917036cbf69 56 {
guiott 2:8917036cbf69 57 Key='E';
guiott 2:8917036cbf69 58 }
guiott 2:8917036cbf69 59 else if(KeypadVal>=0.42 && KeypadVal<0.50)
guiott 2:8917036cbf69 60 {
guiott 2:8917036cbf69 61 Key='v';
guiott 2:8917036cbf69 62 }
guiott 2:8917036cbf69 63 else if(KeypadVal>=0.60 && KeypadVal<0.65)
guiott 2:8917036cbf69 64 {
guiott 2:8917036cbf69 65 Key='^';
guiott 2:8917036cbf69 66 }
guiott 2:8917036cbf69 67 else if(KeypadVal>=0.74 && KeypadVal<0.78)
guiott 2:8917036cbf69 68 {
guiott 2:8917036cbf69 69 Key='>';
guiott 2:8917036cbf69 70 }
guiott 2:8917036cbf69 71 else if(KeypadVal>=0.85)
guiott 2:8917036cbf69 72 {
guiott 2:8917036cbf69 73 Key='<';
guiott 2:8917036cbf69 74 }
guiott 2:8917036cbf69 75
guiott 2:8917036cbf69 76 if (Key!='-' && Key!=KeyPrev)
guiott 2:8917036cbf69 77 {// switch on the LCD backlight if key pressed
guiott 2:8917036cbf69 78 os.SetEvent(LCD_LIGHT_DIM_ON_EVT, LCD_LIGHT_DIM_TASK);
guiott 2:8917036cbf69 79 }
guiott 2:8917036cbf69 80 KeyPrev=Key;
guiott 2:8917036cbf69 81 switch (Key)
guiott 2:8917036cbf69 82 {
guiott 2:8917036cbf69 83 case '^':
guiott 2:8917036cbf69 84 Menu=0;
guiott 2:8917036cbf69 85 break;
guiott 2:8917036cbf69 86
guiott 2:8917036cbf69 87 case '>':
guiott 2:8917036cbf69 88 Menu=1;
guiott 2:8917036cbf69 89 break;
guiott 2:8917036cbf69 90
guiott 2:8917036cbf69 91 case 'v':
guiott 2:8917036cbf69 92 Menu=2;
guiott 2:8917036cbf69 93 break;
guiott 2:8917036cbf69 94
guiott 2:8917036cbf69 95 case '<':
guiott 2:8917036cbf69 96 Menu=3;
guiott 2:8917036cbf69 97 break;
guiott 2:8917036cbf69 98
guiott 2:8917036cbf69 99 case 'E':
guiott 2:8917036cbf69 100 Menu=4;
guiott 2:8917036cbf69 101 break;
guiott 2:8917036cbf69 102 }
guiott 2:8917036cbf69 103 }
guiott 2:8917036cbf69 104 }
guiott 2:8917036cbf69 105 }