#ifndef _KEYBOARD_H
#define _KEYBOARD_H

#include "../../stdafx.h"

class Keyboard : public IO_Module
{
public:
	Keyboard()
	{
		this->parent = NULL;
		this->moduleId = 0;
		this->commandSetting = 0;
		this->settingClearBuffer = 0;
	}

	Keyboard(uint32 keyboardId)
	{
		this->parent = NULL;
		this->moduleId = keyboardId;
		
		switch(keyboardId)
		{
			case IO_KEYBOARD_MAIN:
				this->commandSetting = 27;
				this->settingClearBuffer = 123;
				break;
			default:
				this->commandSetting = 0;
				this->settingClearBuffer = 0;
				break;
		}
	}

protected:
	//Commands
	uint8 commandSetting;
	//Settings
	uint8 settingClearBuffer;

	void SendCommand(uint8 newCommand)
	{
		switch(moduleId)
		{
			case IO_KEYBOARD_MAIN:
				uart1_putc(newCommand);
				break;
			default:
				break;
		}
	}

public:
	uint8 GetInput()
	{
		uint16 input = uart1_getc();

		if(input == 0x100)//no data
		{
			return 0xEE;//empty
		}
		else if(input >= '0' && input <= '9')
		{
			return (uint8)(input - '0');
		}
		else if(input == '*')
		{
			return 10;
		}
		else if(input == '#')
		{
			return 11;
		}
		else
		{
			return 0xFF;//unknown
		}
	}

	void ClearKeyBuffer()
	{
		SendCommand(commandSetting);
		SendCommand(settingClearBuffer);
	}
};

#endif
