Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

# input.c

Go to the documentation of this file.

    00001 /*! \file input.c \brief User-Input Functions. */
    00002 //*****************************************************************************
    00003 //
    00004 // File Name    : 'input.c'
    00005 // Title        : User-Input Functions
    00006 // Author       : Pascal Stang - Copyright (C) 2003
    00007 // Created      : 2003.09.11
    00008 // Revised      : 2003.09.11
    00009 // Version      : 0.1
    00010 // Target MCU   : any
    00011 // Editor Tabs  : 4
    00012 //
    00013 // This code is distributed under the GNU Public License
    00014 //      which can be found at http://www.gnu.org/licenses/gpl.txt
    00015 //
    00016 //*****************************************************************************
    00017
    00018 //----- Include Files ---------------------------------------------------------
    00019 #include "global.h"     // include our global settings
    00020 #include "uart.h"
    00021 #include "rprintf.h"    // include printf function library
    00022
    00023 #include "input.h"
    00024
    00025 #ifndef INPUT_GETBYTE
    00026 #define INPUT_GETBYTE uart1GetByte
    00027 #endif
    00028
    00029 // globals
    00030
    00031 // functions
    00032 u08 inputString(u08 termChar, u08 termLen, u08* data)
    00033 {
    00034     int s=-1;
    00035     u08 length=0;
    00036
    00037     while(length < termLen)
    00038     {
    00039         // get input
    00040         s = -1;
    00041         while(s == -1)
    00042         {
    00043             s = INPUT_GETBYTE();
    00044         }
    00045
    00046         // handle special characters
    00047         if(s == 0x08)           // backspace
    00048         {
    00049             if(length > 0)
    00050             {
    00051                 // echo backspace-space-backspace
    00052                 rprintfChar(0x08);
    00053                 rprintfChar(' ');
    00054                 rprintfChar(0x08);
    00055                 length--;
    00056             }
    00057         }
    00058         else if(s == termChar)  // termination character
    00059         {
    00060             // save null-termination
    00061             data[length] = 0;
    00062             break;
    00063         }
    00064         else
    00065         {
    00066             // echo character
    00067             rprintfChar(s);
    00068             // save character
    00069             data[length++] = s;
    00070         }
    00071     }
    00072     return length;
    00073 }
    00074
    00075 u08 asciiHexToByte(u08* string)
    00076 {
    00077     // convert 2-byte hex string to byte
    00078     return (asciiHexToNibble(string[0])<<4) + asciiHexToNibble(string[1]);
    00079 }
    00080
    00081 u08 asciiHexToNibble(u08 character)
    00082 {
    00083     // convert 1-byte hex ascii character to nibble
    00084     if((character >= 0x30) && (character <= 0x39))
    00085         return character-0x30;
    00086     else if((character >=  'A') && (character <=  'F'))
    00087         return character-'A'+10;
    00088     else if((character >=  'a') && (character <=  'f'))
    00089         return character-'a'+10;
    00090     else return 0;
    00091 }