summaryrefslogtreecommitdiffstats
path: root/source/Concept/Framework/display.h
blob: df18e62d9a29f21681e16c5b423b4b5c990a56ec (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#ifndef _DISPLAY_H
#define _DISPLAY_H

#include "stdafx.h"

class Display : public IO_Module
{
public:
	Display()
	{
		this->parent = NULL;
		this->moduleId = 0;
		this->cursorVisible = false;
		this->illuminationEnabled = true;
		this->commandClear = 0;
		this->commandReturnCursor = 0;
		this->commandNewLine = 0;
		this->commandSetting = 0;
		this->settingCursorVisible = 0;
		this->settingIllumination = 0;
		this->settingCursorPosition = 0;
	}

	Display(uint32 displayId)
	{
		this->parent = NULL;
		this->moduleId = displayId;
		this->cursorVisible = false;
		this->illuminationEnabled = true;
		
		switch(displayId)
		{
			case IO_DISPLAY_MAIN:
				this->commandClear = 12;
				this->commandReturnCursor = 13;
				this->commandNewLine = 10;
				this->commandSetting = 27;
				this->settingCursorVisible = 67;
				this->settingIllumination = 76;
				this->settingCursorPosition = 79;
				msleep(500);
				uart1_init(103);//9600 BAUD at 16MHz Atmel
				sleep(2);
				break;
			default:
				this->commandClear = 0;
				this->commandReturnCursor = 0;
				this->commandNewLine = 0;
				this->commandSetting = 0;
				this->settingCursorVisible = 0;
				this->settingIllumination = 0;
				this->settingCursorPosition = 0;
				break;
		}
	}

protected:
	bool cursorVisible;
	bool illuminationEnabled;
	//Commands
	uint8 commandClear;
	uint8 commandReturnCursor;
	uint8 commandNewLine;
	uint8 commandSetting;
	//Settings
	uint8 settingCursorVisible;
	uint8 settingIllumination;
	uint8 settingCursorPosition;

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

public:
	void Print(char* newString)
	{
		switch(moduleId)
		{
			case IO_DISPLAY_MAIN:
				uart1_puts(newString);
				break;
			default:
				break;
		}
	}

	void Print(int32 newInteger)
	{
		char buffer[12];
		ltoa(newInteger, buffer, 10);
		Print(buffer);
	}

	void Print(char* newString, uint8 xPos, uint8 yPos)
	{
		SetCursorPosition(xPos, yPos);
		Print(newString);
	}

	void Print(int32 newInteger, uint8 xPos, uint8 yPos)
	{
		SetCursorPosition(xPos, yPos);
		Print(newInteger);
	}

	void Clear()
	{
		SendCommand(commandClear);
	}

	void ReturnCursor()
	{
		SendCommand(commandReturnCursor);
	}

	void NewLine()
	{
		SendCommand(commandNewLine);
	}

	bool GetCursorVisible()
	{
		return cursorVisible;
	}

	void SetCursorVisible(bool newStatus)
	{
		cursorVisible = newStatus;

		SendCommand(commandSetting);
		SendCommand(settingCursorVisible);

		if(cursorVisible)
		{
			SendCommand(1);
		}
		else
		{
			SendCommand(0);
		}
	}

	bool GetLightingEnabled()
	{
		return illuminationEnabled;
	}

	void SetLightingEnabled(bool newStatus)
	{
		illuminationEnabled = newStatus;

		SendCommand(commandSetting);
		SendCommand(settingIllumination);

		if(illuminationEnabled)
		{
			SendCommand(1);
		}
		else
		{
			SendCommand(0);
		}
	}

	void SetCursorPosition(uint8 newX, uint8 newY)
	{
		if(!newX || newX > 20) return;
		if(!newY || newY > 4) return;

		SendCommand(commandSetting);
		SendCommand(settingCursorPosition);
		SendCommand(newX);
		SendCommand(newY);
	}
};

#endif