-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatroom.c
More file actions
191 lines (177 loc) · 5.52 KB
/
chatroom.c
File metadata and controls
191 lines (177 loc) · 5.52 KB
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
186
187
188
189
190
/** Chatroom control codes for Microprocessor Laboratory
2017 Spring Semester. Lee Sang Su 2011314425 SKKU
github.com/sethlee0111
@author sethlee
@version 1.1
*/
#include "chatroom.h"
/**----------------------------------------------
* Initialization for chatroom //
*
* @author sethlee
* @todo add more stuff
*----------------------------------------------*/
void Import_Chatroom(void) {
/* Chatroom Background */
Draw_Vline(0,0,63);
Draw_Vline(1,0,63);
Draw_Vline(126,0,63);
Draw_Vline(127,0,63);
Draw_Hline(0,0,127);
Draw_Hline(1,0,127);
Draw_Hline(62,0,127);
Draw_Hline(63,0,127);
Draw_Hline(49,0,127);
Draw_Hline(50,0,127);
String_GLCD(4, 4, "HELLO, Seth Lee");
String_GLCD(13, 4, "Welcome to");
String_GLCD(21, 4, "The Chatroom");
String_GLCD(30, 4, "Microprocessor");
String_GLCD(39, 4, "--------------------");
Draw_Logo();
//String_GLCD(52, 4, "Say Something!");
}
/**----------------------------------------------
* Initialization Timer for a cursor
*
* @author sethlee
* @todo add more stuff
*----------------------------------------------*/
void Init_Cursor_Timer(void) {
Tim0.tios.byte |= 0x30; // C4I, C5I timer output capture
/* Using C4I */
Tim0.tscr1.byte = 0x80; // timer ON
Tim0.tscr2.byte = 0x07; // 0b0111 Prescale 128
//Tim0.tctl1.byte = 0x03; // OL4, OM4 set
Tim0.tie.byte |= 0x10; // timer 4 interrupt enable, timer 5 is disabled for now
Tim0.tc[4].word = Tim0.tcnt.word + 5; // timer output compare
Tim0.tflg1.byte = 0x30; //Interrupt flag clear
}
/* Interrupt Handler for the timer */
void Timer4_Interrupt(void) {
char i;
if(Tim0.tflg1.byte & 0x10) {
Pim.pieh.byte = 0x07; // disable semaphore for keypadsi
Tim0.tc[4].word += 62500 / 2; //next in 0.5s
if(isCursorOn) {
Erase_GLCD(cursorLeftUpperX, cursorLeftUpperX + 6, cursorLeftUpperY, cursorLeftUpperY + 4);
String_GLCD(cursorLeftUpperX, cursorLeftUpperY, cursorLetter);
isCursorOn = 0;
} else {
for(i = 0; i < 5; i++) {
Draw_Vline(cursorLeftUpperY + i, cursorLeftUpperX, cursorLeftUpperX + 6);
}
isCursorOn = 1;
}
Tim0.tflg1.byte = 0x10; //Interrupt flag clear
}
}
/* timer 5: measuring elasped time after last key input
* if more than 1s has passed, the cursor moves to the next column
*/
void Timer5_Interrupt(void) {
if(Tim0.tflg1.byte & 0x20) { //user started writing to the line,
Tim0.tie.byte &= ~(0x20); //timer 5 is disabled!
Tim0.tflg1.byte = 0x20; // Timer 5 interrupt flag clear
// first, we make sure to put character on current cursor instead of cursor box
Erase_GLCD(cursorLeftUpperX, cursorLeftUpperX + 6, cursorLeftUpperY, cursorLeftUpperY + 4);
String_GLCD(cursorLeftUpperX, cursorLeftUpperY, cursorLetter);
//write to sci
if(cursorLetter[0] == '\0') {
sendMsg[sendMsgIndex++] = '\n';
sendMsg[sendMsgIndex] = '\r';
write_sci0(sendMsg);
cursorLeftUpperY = 4; // initialize cursor
Erase_GLCD(cursorLeftUpperX, cursorLeftUpperX + 6, 4, 125);
sendMsgIndex = 0;
} else {
sendMsg[sendMsgIndex++] = cursorLetter[0];
cursorLetter[0] = 0x20;
cursorLeftUpperY += 6; // we move cursor to the right
Init_Key();
}
}
}
/*
void Init_Message(void) {
msg[4].read = "@ Hello, Welcome to @";
msg[3].read = "< The Chatroom >";
msg[2].read = "* Please Check *";
msg[1].read = "* Your Connection *";
msg[0].read = "_____________________";
}
*/
/**----------------------------------------------
* When a keypad is pushed, this is invoked
*
* @author sethlee
* @todo add more stuff
*----------------------------------------------*/
void Button_Pushed(char key) {
cursorLetter[0] = key;
Erase_GLCD(cursorLeftUpperX, cursorLeftUpperX + 6, cursorLeftUpperY, cursorLeftUpperY + 4);
String_GLCD(cursorLeftUpperX, cursorLeftUpperY, cursorLetter);
Tim0.tflg1.byte = 0x20; // Timer 5 interrupt flag clear
if((key >= 0x30 && key <= 0x39) || key == 0x20) {// if the key is number,
Tim0.tc[5].word = Tim0.tcnt.word + 10000; // immediate cursor change
Tim0.tie.byte |= 0x20;
Tim0.tflg1.byte = 0x20; // Timer 5 interrupt flag clear
} else {
Tim0.tc[5].word = Tim0.tcnt.word + 62500; // we count 1s
Tim0.tie.byte |= 0x20; //timer 5 is enabled!
}
}
/**----------------------------------------------
* put character in a message
*
* @author sethlee
* @todo add more stuff
*----------------------------------------------*/
void Message_Put_Char(char data) {
if(data == 0x0D){
msg[msgIndex].read[readIndex++] = '\0';
displayStartIndex = msgIndex;
initialMsgIndex++;
if(msgIndex == 0)
msgIndex = 4;
else
msgIndex--;
Display_Messages();
readIndex = 0; // initialize index for individual char
} else {
msg[msgIndex].read[readIndex++] = data;
}
}
// Erase_GLCD(39 - (i * 9), 39 - (i * 9) + 8 , 4 , 123);
// String_GLCD(39 - (i * 9), 4, msg[i].read);
/**----------------------------------------------
* Display all 5 rows of Messages
*
* @author sethlee
* @todo add more stuff
*----------------------------------------------*/
void Display_Messages(void) {
char i;
if(initialMsgIndex < 5) {
for(i = 0 ; i < 5; i++) {
Erase_GLCD(39 - (i * 9), 39 - (i * 9) + 8 , 4 , 123);
String_GLCD(39 - (i * 9), 4, msg[i].read);
}
} else {
for(i = 0 ; i < 5; i++) {
Erase_GLCD(39 - (i * 9), 39 - (i * 9) + 8 , 4 , 123);
String_GLCD(39 - (i * 9), 4, msg[nextDisplayIndex()].read);
}
}
}
/*returns current display Index, put next display index*/
unsigned char nextDisplayIndex(void) {
unsigned char temp = displayStartIndex;
if(displayStartIndex == 4) {
displayStartIndex = 0;
return temp;
} else {
displayStartIndex += 1;
return temp;
}
}