/*
 * Keyboard.c
 *
 *  Created on: Nov 5, 2011
 *      Author: RomanM
 */

#include "hal_Keyboard.h"

/*
 * Initialization of keyboard
 */
void Keyboard_Init(void) {
	hal_Keyboard_Init();
}

/*
 * If key is pressed, return its number
 */
uint8_t Key_Pressed(void) {
	uint8_t n;
	uint8_t read = 0;

	for (n=1; n<=3; n++) {
		hal_Keyboard_Set_Col(n);
		read = hal_Keyboard_Read_Row();
		if (read) {
			read = ((read - 1) * 3) + n;
			break;
		}
	}
	return read;
}

/*
 * Read character from keyboard
 */
char Key_GetC(void) {
	uint8_t c;

	c = Key_Pressed();

	if (c >= 1 && c <= 9) return (c + '0');
	else if (c == 10) return '*';
	else if (c == 11) return '0';
	else if (c == 12) return '#';

	return 0;
}
