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
Task2Keypad.cpp
00001 #include "Task2Keypad.h" 00002 00003 void KeypadTask(void) 00004 {/** 00005 *\brief TASK 2, Keypad management. 00006 It uses just one ADC port. Five keys switch a 5 resistor ladder 00007 obtaining a unique voltage for each key, with a priority that 00008 depends from the position of the resistor in the ladder. 00009 This function makes an average of 50 analog values (50ms) before 00010 confirming the output, to filter out some noise and debounce keys 00011 */ 00012 00013 static float KeypadAcc; // accumulator to compute average 00014 static float KeypadPrev; // previous value to compute variation 00015 static int KeypadCount; // all samples number 00016 static int KeypadRealCount; // valid samples only 00017 float KeypadVal; 00018 static char KeyPrev='-'; 00019 00020 os.SetTimer(KEYPAD_TMR, 1, 1); 00021 while(1) 00022 { 00023 os.WaitEvent(KEYPAD_EVT); 00024 float InValue = KeypadIn.read(); 00025 if ((InValue > 0.3) && (abs(InValue - KeypadPrev) < 0.1)) 00026 {// makes the average only of the values above a threshold 00027 // and within an almost stable range 00028 KeypadAcc+=InValue; 00029 KeypadRealCount++; 00030 } 00031 00032 KeypadCount++; 00033 KeypadPrev=InValue; 00034 00035 if (KeypadCount >=50) 00036 { 00037 if(KeypadRealCount > 25) 00038 { 00039 KeypadVal=KeypadAcc/KeypadRealCount; 00040 } 00041 else 00042 {// not enough values to average 00043 00044 KeypadVal=0; 00045 } 00046 00047 KeypadAcc=0; 00048 KeypadCount=0; 00049 KeypadRealCount=0; 00050 00051 if(KeypadVal <0.15) 00052 { 00053 Key='-'; 00054 } 00055 else if(KeypadVal>=0.3 && KeypadVal<0.35) 00056 { 00057 Key='E'; 00058 } 00059 else if(KeypadVal>=0.42 && KeypadVal<0.50) 00060 { 00061 Key='v'; 00062 } 00063 else if(KeypadVal>=0.60 && KeypadVal<0.65) 00064 { 00065 Key='^'; 00066 } 00067 else if(KeypadVal>=0.74 && KeypadVal<0.78) 00068 { 00069 Key='>'; 00070 } 00071 else if(KeypadVal>=0.85) 00072 { 00073 Key='<'; 00074 } 00075 00076 if (Key!='-' && Key!=KeyPrev) 00077 {// switch on the LCD backlight if key pressed 00078 os.SetEvent(LCD_LIGHT_DIM_ON_EVT, LCD_LIGHT_DIM_TASK); 00079 } 00080 KeyPrev=Key; 00081 switch (Key) 00082 { 00083 case '^': 00084 Menu=0; 00085 break; 00086 00087 case '>': 00088 Menu=1; 00089 break; 00090 00091 case 'v': 00092 Menu=2; 00093 break; 00094 00095 case '<': 00096 Menu=3; 00097 break; 00098 00099 case 'E': 00100 Menu=4; 00101 break; 00102 } 00103 } 00104 } 00105 }
Generated on Thu Jul 14 2022 14:06:47 by 1.7.2