Simon Ford / Mbed 2 deprecated keyboard

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PS2ASCII.cpp Source File

PS2ASCII.cpp

00001 #include "PS2ASCII.h"
00002 
00003 //===================================
00004 //*Constructor*
00005 //===================================
00006 
00007 PS2ASCII::PS2ASCII(PinName data, PinName clk) : kbd(data,clk) ,_caps(false), _shift(false),  _E0flag(false) ,_numlock(false)
00008 {
00009     
00010 }
00011 
00012 //===================================
00013 //Functions
00014 //===================================
00015 
00016 unsigned char PS2ASCII::getChar()
00017 {
00018      while(1)
00019      {
00020          _E0flag = false;
00021          unsigned char keypress = kbd.rd();                //code in
00022         
00023         if(keypress == 0xE0)                            //is it a special E0 key?
00024         {
00025             keypress = kbd.rd();                        //next byte in
00026             if(keypress == NULL)                        //is it a break code?
00027             {
00028                 keypress = kbd.rd();                    //if so chew it up and back to start
00029                 
00030                 continue;
00031             }
00032             
00033             _E0flag = true;                                //tell us that it is an E0 function
00034             return keypress;
00035         }
00036         
00037         if((keypress == 0x12) || (keypress == 0x59))    //SHIFT pressed?
00038         {
00039             _shift = true;
00040             continue;
00041         }
00042         
00043         if(keypress == NULL)                            //gets rid of byte 1 of break code
00044         {
00045             keypress = kbd.rd();                        //byte 2 of break code in
00046                 
00047             if((keypress == 0x12) || (keypress == 0x59))
00048             {
00049                 _shift = false;
00050             }
00051             continue;
00052         }
00053         
00054         switch (keypress) {
00055             case 0x58:
00056                 _caps = !_caps;                            //CAPS LOCK key
00057                 continue;
00058             case 0x80:
00059                 _numlock = !_numlock;
00060                 continue;
00061             default:
00062                 break;
00063         }
00064         
00065         unsigned char initial_keypress = keypress;
00066         
00067         if(_shift == true)                                //if SHIFT is pressed take shifted character
00068         {
00069             keypress = shift_on[keypress];
00070         }
00071             
00072         if((_caps == true)&&(initial_keypress >= 97)&&(initial_keypress <= 127))
00073         {
00074             keypress = shift_on[keypress];                //if caps is on shift the letter up
00075         }
00076             
00077         return(keypress);
00078         
00079     }
00080 }
00081     
00082 bool PS2ASCII::E0flag()
00083 {
00084     return _E0flag;
00085 }
00086 
00087 bool PS2ASCII::numlock()
00088 {
00089     return _numlock;
00090 }
00091      
00092