CURRENT ISSUE

Contests

bottom corner

Feature Article

Issue #201 April 2007
ATir Keyboard Interface
by Steven Savage

Start | System Overview | Keyboard | IR Remote Operation | ATir Hardware | Operation | Nice Solution | Sources & PDF

Listing 1—How can a keyboard create a user interface? Just “type” it out. This algorithm takes an ASCII character input and converts it into an appropriate key down, key release, and shift key press (if necessary) scan code stream. Anyone for a speed-typing contest?

//This function “types” the character argument via output of 
//keypress scancodes
void kbd_putchar(char ch){
	uint8_t index;
	uint8_t keyCode;
	bool shift = false;	
	switch (ch){
	case (‘\n’):
	keyPress(KEY_ENTER);
	break;
	case (‘\t’):
	keyPress(KEY_TAB);
	break;
	default:

	index=ch-32;   //subtract 32 from ascii value to obtain index
	if (index>63){ //lower case letters and supported	symbols 
                //greater than 63
		index-=32;  // are equiv to value - 32 but with shift inverted
		shift = true;	//after xor, shift is inverted
	}
	keyCode=pgm_read_byte(codeTable + index);
	if bit_test(keyCode,7){
	shift^=true;	//set shift or invert if already 1
	bit_clear(keyCode,7);
	}
	if (shift){ //this section presses the shift key for every character
	keyDown(KEY_SHIFT);
	keyPress(keyCode);
	keyRelease(KEY_SHIFT);
	}
	else
	keyPress(keyCode); //non shift keypress
	
	break;
	}//end switch
} 

 

 


bottom corner