?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{BLAME START}

library

?curdirlinks? -

Blame information for rev 6

Line No. Rev Author Line
1 6 kaklik /*! \file input.c \brief User-Input Functions. */
2 //*****************************************************************************
3 //
4 // File Name : 'input.c'
5 // Title : User-Input Functions
6 // Author : Pascal Stang - Copyright (C) 2003
7 // Created : 2003.09.11
8 // Revised : 2003.09.11
9 // Version : 0.1
10 // Target MCU : Atmel AVR series
11 // Editor Tabs : 4
12 //
13 // This code is distributed under the GNU Public License
14 // which can be found at http://www.gnu.org/licenses/gpl.txt
15 //
16 //*****************************************************************************
17  
18 //----- Include Files ---------------------------------------------------------
19 #include "global.h" // include our global settings
20 #ifdef __AVR_ATmega128__
21 #include "uart2.h"
22 #else
23 #include "uart.h"
24 #endif
25 #include "rprintf.h" // include printf function library
26  
27 #include "input.h"
28  
29 // defines and typedefs
30 #ifndef INPUT_UART
31 #define INPUT_UART 1
32 #endif
33  
34 // globals
35  
36 // functions
37 u08 inputString(u08 termChar, u08 termLen, u08* data)
38 {
39 u08 s=0;
40 u08 length=0;
41  
42 while(length < termLen)
43 {
44 // get input
45 #ifdef __AVR_ATmega128__
46 while(!uartReceiveByte(INPUT_UART,&s));
47 #else
48 while(!uartReceiveByte(&s));
49 #endif
50  
51 // handle special characters
52 if(s == 0x08) // backspace
53 {
54 if(length > 0)
55 {
56 // echo backspace-space-backspace
57 rprintfChar(0x08);
58 rprintfChar(' ');
59 rprintfChar(0x08);
60 length--;
61 }
62 }
63 else if(s == termChar) // termination character
64 {
65 // save null-termination
66 data[length] = 0;
67 break;
68 }
69 else
70 {
71 // echo character
72 rprintfChar(s);
73 // save character
74 data[length++] = s;
75 }
76 }
77 return length;
78 }
79  
80 u08 asciiHexToByte(u08* string)
81 {
82 // convert 2-byte hex string to byte
83 return (asciiHexToNibble(string[0])<<4) + asciiHexToNibble(string[1]);
84 }
85  
86 u08 asciiHexToNibble(u08 character)
87 {
88 // convert 1-byte hex ascii character to nibble
89 if((character >= 0x30) && (character <= 0x39))
90 return character-0x30;
91 else if((character >= 'A') && (character <= 'F'))
92 return character-'A'+10;
93 else if((character >= 'a') && (character <= 'f'))
94 return character-'a'+10;
95 else return 0;
96 }
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3