summaryrefslogtreecommitdiffstats
path: root/source/Concept/Framework/modules/input/keyboard.h
blob: 243bb6c344272ad2e644e9b1cc3d372a2a37d25f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#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