Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: eee212projectWithSD
Diff: PS2ASCII.cpp
- Revision:
- 0:ea6fa42df9ec
diff -r 000000000000 -r ea6fa42df9ec PS2ASCII.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/PS2ASCII.cpp Sat Jun 02 09:31:29 2018 +0000
@@ -0,0 +1,132 @@
+#include "PS2ASCII.h"
+
+//===================================
+//*Constructor*
+//===================================
+
+PS2ASCII::PS2ASCII(PinName data, PinName clk) : kbd(data,clk) ,_caps(false), _shift(false), _E0flag(false) ,_numlock(false)
+{
+
+}
+
+//===================================
+//Functions
+//===================================
+
+unsigned char PS2ASCII::getChar()
+{
+ while(1)
+ {
+ _E0flag = false;
+ unsigned char keypress = kbd.rd(); //code in
+
+ if(keypress == 0xE0) //is it a special E0 key?
+ {
+ keypress = kbd.rd(); //next byte in
+ if(keypress == 0xF0) //is it a break code?
+ {
+ keypress = kbd.rd(); //if so chew it up and back to start
+
+ continue;
+ }
+
+ _E0flag = true; //tell us that it is an E0 function
+ return keypress;
+ }
+
+ if((keypress == 0x12) || (keypress == 0x59)) //SHIFT pressed?
+ {
+ _shift = true;
+ continue;
+ }
+
+ if(keypress == 0xF0) //gets rid of byte 1 of break code
+ {
+ keypress = kbd.rd(); //byte 2 of break code in
+
+ if((keypress == 0x12) || (keypress == 0x59))
+ {
+ _shift = false;
+ }
+ continue;
+ }
+
+ switch (keypress) {
+ case 0x58:
+ _caps = !_caps; //CAPS LOCK key
+ kbd.wr(0xED);
+ if (_caps && _numlock)
+ kbd.wr(0x06);
+ else if (_caps && !_numlock)
+ kbd.wr(0x04);
+ else if (!_caps && _numlock)
+ kbd.wr(0x02);
+ else
+ kbd.wr(0x00);
+ continue;
+ case 0x77:
+ _numlock = !_numlock;
+ kbd.wr(0xED);
+ if (_caps && _numlock)
+ kbd.wr(0x06);
+ else if (_caps && !_numlock)
+ kbd.wr(0x04);
+ else if (!_caps && _numlock)
+ kbd.wr(0x02);
+ else
+ kbd.wr(0x00);
+ continue;
+ default:
+ break;
+ }
+
+// We do not need shift and caps lock in our project, since we do not use uppercase letters.
+
+// unsigned char initial_keypress = keypress;
+
+// if(_shift == true) //if SHIFT is pressed take shifted character
+// {
+// keypress = shift_on[keypress];
+// }
+//
+// if((_caps == true)&&(initial_keypress >= 97)&&(initial_keypress <= 127))
+// {
+// keypress = shift_on[keypress]; //if caps is on shift the letter up
+// }
+
+ return(keypress);
+
+ }
+}
+
+unsigned char PS2ASCII::getASCII(unsigned char keypress) {
+ unsigned char character = ps2CharMap[keypress];
+
+ if (!_E0flag && !_numlock) {
+ if (keypress == 0x70 || keypress == 0x69 || keypress == 0x72 || keypress == 0x7A ||
+ keypress == 0x6B || keypress == 0x73 || keypress == 0x74 || keypress == 0x6C ||
+ keypress == 0x75 || keypress == 0x7D)
+ character = ' ';
+
+ }
+
+ return character;
+}
+
+bool PS2ASCII::E0flag()
+{
+ return _E0flag;
+}
+
+bool PS2ASCII::numlock()
+{
+ return _numlock;
+}
+
+bool PS2ASCII::caps() {
+ return _caps;
+}
+
+bool PS2ASCII::shift() {
+ return _shift;
+}
\ No newline at end of file