-
Notifications
You must be signed in to change notification settings - Fork 0
/
__framework.h
374 lines (328 loc) · 12.7 KB
/
__framework.h
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
#include "mod_uri.h"
Btn btn_a = Btn(8,"Select",false);
boolean game_flag = false;
int prepareQuiz();
void settingHandler(int option);
void GoodMelody();
void BadMelody();
void ModeTypeScreen(){
boolean screen_flag = true;
Btn btn_a = Btn(9,"A",false);
Btn btn_b = Btn(8,"B",false);
Btn btn_c = Btn(7,"C",false);
Btn btn_d = Btn(6,"D",false);
int index = -1;
while(screen_flag){
display_helper.ModeTypeMenu(index);
if(btn_a.isbuttonClicked() && btn_a.btnClick == true){
index = 1;
}
if(btn_b.isbuttonClicked() && btn_b.btnClick == true){
index = 2;
}
if(btn_c.isbuttonClicked() && btn_c.btnClick == true){
index = 3;
}
if(btn_d.isbuttonClicked() && btn_d.btnClick == true){
MODE_TYPE = index;
screen_flag = false;
break;
}
delay(50);
}
}
void catergoryScreen(){
boolean screen_flag = true;
Btn btn_a = Btn(9,"Select",false);
Btn btn_b = Btn(8,"Back",false);
int knob_level;
int temp = knob.setpot(potPin,"Topics",0,4);
display_helper.categoryMenu(temp);
while(screen_flag){
knob_level = knob.getPotMappedValue();
display_helper.categoryMenu(knob_level);
if(btn_a.isbuttonClicked() && btn_a.btnClick == true){
screen_flag = false;
quiz_helper.settopic(knob_level);
return;
}
if(btn_b.isbuttonClicked() && btn_b.btnClick == true){
screen_flag = false;
return;
}
delay(250);
}
}
void levelScreen(){
boolean screen_flag = true;
Btn btn_a = Btn(9,"Select",false);
Btn btn_b = Btn(8,"Back",false);
int knob_level;
int temp = knob.setpot(potPin,"Level",1,11);
//display_helper.levelMenu(temp);
while(screen_flag){
knob_level = knob.getPotMappedValue();
String new_level = String(knob_level);
String old_level = String(quiz_helper.getLevel());
display_helper.levelMenu(new_level,old_level);
if(btn_a.isbuttonClicked() && btn_a.btnClick == true){
screen_flag = false;
quiz_helper.setLevel(knob_level);
return;
}
if(btn_b.isbuttonClicked() && btn_b.btnClick == true){
screen_flag = false;
return;
}
delay(250);
}
}
void questionSetupScreen(){
boolean screen_flag = true;
Btn btn_a = Btn(9,"Select",false);
Btn btn_b = Btn(8,"Back",false);
int knob_level;
int temp = knob.setpot(potPin,"QuestionSetup",1,51);
while(screen_flag){
knob_level = knob.getPotMappedValue();
String new_total = String(knob_level);
String old_Total = String(quiz_helper.getTotalQuestions());
display_helper.questionSetupMenu(new_total,old_Total);
if(btn_a.isbuttonClicked() && btn_a.btnClick == true){
screen_flag = false;
quiz_helper.setTotalQuestions(knob_level);
return;
}
if(btn_b.isbuttonClicked() && btn_b.btnClick == true){
screen_flag = false;
game_flag = true;
return;
}
delay(20);
}
}
void settingHandler(int option){
switch(option){
case 1:
catergoryScreen();
break;
case 2:
levelScreen();
break;
case 3:
questionSetupScreen();
break;
//case 4:
// preQuizMenu();
// break;
}
}
int preQuizMenu(){
int selected_option;
boolean screen_flag = true;
Btn btn_a = Btn(9,"Start",false);
Btn btn_b = Btn(8,"Change",false);
String topic = quiz_helper.getTopicName(quiz_helper.gettopic());
int level = quiz_helper.getLevel();
int total = quiz_helper.getTotalQuestions();
int knob_duration = knob.setpot(potPin,"Duration",1,TIME_LIMIT);
while(screen_flag){
knob_duration = knob.getPotMappedValue();
display_helper.preQuizSetupMenu(topic,level,total,knob_duration);
if(btn_a.isbuttonClicked() && btn_a.btnClick == true){
//set duration in quiz class TODO
screen_flag = false;
game_flag = true;
selected_option = 1;
quiz_helper.setDuration(knob_duration);
}
if(btn_b.isbuttonClicked() && btn_b.btnClick == true){
screen_flag = false;
game_flag = false;
selected_option = 0;
}
delay(50);
}
return selected_option;
}
int prepareQuiz(){
boolean screen_flag = true;
int knob_level;
Btn btn_a = Btn(9,"A",false);
Btn btn_b = Btn(8,"Back",false);
int temp = knob.setpot(potPin,"Settings",1,4);
display_helper.SettingMenu(temp);
while(screen_flag){
knob_level = knob.getPotMappedValue();
display_helper.SettingMenu(knob_level);
if(btn_a.isbuttonClicked() && btn_a.btnClick == true){
screen_flag = false;
return knob_level;
}
if(btn_b.isbuttonClicked() && btn_b.btnClick == true){
return 4;
}
delay(10);
}
}
String getUserAnswer(String topic,String TotalQuestions,String q_number,String qa,String qb,String symbol,String answer,
String a , String b ,String c ,String d){
Btn btn_a = Btn(9,a,false);
Btn btn_b = Btn(8,b,false);
Btn btn_c = Btn(7,c,false);
Btn btn_d = Btn(6,d,false);
String keyname = "-1";
boolean wait_key = true;
int Current_Duration = quiz_helper.getDuration();
createTimer();
while(wait_key){
controll.run();
String s = String(seconds);
String m = String(minutes);
String h = String(hours);
int remTime = Current_Duration - seconds;
// Serial.println(Current_Duration);
if(seconds >= Current_Duration){
stopTimer();
wait_key = false;
return "XX";
}
display_helper.questionWindow(topic,TotalQuestions,q_number,qa,qb,symbol,answer,a,b,c,d,String(remTime));
if(btn_a.isbuttonClicked() && btn_a.btnClick == true){
wait_key = false;
keyname = btn_a.btnname;
}
if(btn_b.isbuttonClicked() && btn_b.btnClick == true){
wait_key = false;
keyname = btn_b.btnname;
}
if(btn_c.isbuttonClicked() && btn_c.btnClick == true){
wait_key = false;
keyname = btn_c.btnname;
}
if(btn_d.isbuttonClicked() && btn_d.btnClick == true){
wait_key = false;
keyname = btn_d.btnname;
}
delay(10);
}
return keyname;
}
String processFeedback(String feedback,int qanswer){
int fnumber = feedback.toInt();
if(fnumber == qanswer){
int updatedScore = quiz_helper.getScore()+1;
quiz_helper.setScore(updatedScore);
led_green.on();
return String("Correct: "+feedback );
}
else{
led_red.on();
String qstr = String(qanswer);
return String("Correction: "+qstr);
}
}
void showFinalResults(){
Btn btn_a = Btn(9,"A",false);
Btn btn_b = Btn(8,"B",false);
Btn btn_c = Btn(7,"C",false);
Btn btn_d = Btn(6,"D",false);
boolean wait_key = true;
int total = quiz_helper.getScore();
int grandTotal = quiz_helper.getTotalQuestions();
String topic = quiz_helper.getTopicName(quiz_helper.gettopic());
int percentage = (total * 100) / grandTotal;
display_helper.quizFeedback(total,grandTotal,percentage,topic);
if(percentage >= 50){
led_green.on();
GoodMelody();
}else{
led_red.on();
BadMelody();
}
while(wait_key){
if((btn_a.isbuttonClicked() && btn_a.btnClick == true) || (btn_b.isbuttonClicked() && btn_b.btnClick == true)
|| (btn_c.isbuttonClicked() && btn_c.btnClick == true) || (btn_d.isbuttonClicked() && btn_d.btnClick == true)){
wait_key = false;
}
}
led_green.off();
led_red.off();
}
void examSessionHandler(){
int current_topic = quiz_helper.gettopic();
String topic = quiz_helper.getTopicName(current_topic);
int TotalQuestions = quiz_helper.getTotalQuestions();
int myquestions = TotalQuestions;
int q_number = 1;
quiz_helper.setScore(0);
while(myquestions > 0){
struct qTemplate question;
question.a = 0;
question.b = 0;
question.answer = 0;
while((question.a <= question.b) ){
quiz_helper.genNumbers();
question.a = quiz_helper.getfnumber();
question.b = quiz_helper.getlnumber();
}
if(current_topic == 3){
int numberfactor = quiz_helper.findNumberFactors(question.a);
question.b = numberfactor;
quiz_helper.setlnumber(numberfactor);
//Serial<<"Elements size:"<<numberfactor<<endl;
}
question.answer = quiz_helper.operationHandler(current_topic, question.a,question.b);
question.remainder = (quiz_helper.remainder > 0) ? quiz_helper.remainder: 0;
shuffler.createShuffleOrder();
int *array_order = shuffler.getOrder();
int *array_options = quiz_helper.genOptions();
int qanswer = question.answer;
int a = array_order[0] - 1;
question.optionA = array_options[a];
int b = array_order[1] - 1;
question.optionB = array_options[b];
int c = array_order[2] - 1;
question.optionC = array_options[c];
int d = array_order[3] - 1;
question.optionD = array_options[d];
display_helper.questionWindow(topic,String(TotalQuestions),String(q_number),String(question.a),String(question.b),quiz_helper.getTopicSymbol(),String(question.answer),
String(question.optionA),String(question.optionB),String(question.optionC),String(question.optionD),"0");
String feedback = getUserAnswer(topic,String(TotalQuestions),String(q_number),String(question.a),String(question.b),quiz_helper.getTopicSymbol(),String(question.answer),
String(question.optionA),String(question.optionB),String(question.optionC),String(question.optionD));
String user_msg = processFeedback(feedback,qanswer);
display_helper.questionWindowFeedback(topic,String(TotalQuestions),String(q_number),String(question.a),String(question.b),
quiz_helper.getTopicSymbol(),String(question.answer),feedback,user_msg);
myquestions = myquestions - 1;
q_number = q_number + 1;
delay(4000);
led_green.off();
led_red.off();
}
showFinalResults();
game_flag = false;
}
void GoodMelody(){
int melody[] = {NOTE_E6, NOTE_D6, NOTE_FS6, NOTE_GS6, NOTE_C6, NOTE_B5, NOTE_D5, NOTE_E5, NOTE_B5, NOTE_A5, NOTE_AS5, NOTE_E5, NOTE_A5};
int noteDurations[] = {16,16,8,8,16,16,8,8,16,16,8,8,2};
int SIZE_ARRAY = (sizeof(melody)/sizeof(melody[0]));
for(int thisNote = 0; thisNote < SIZE_ARRAY; thisNote++) {
int noteDuration = 1000 / noteDurations[thisNote];
tone(TONE_PIN, melody[thisNote], noteDuration);
int pauseBetweenNotes = noteDuration * 2.00;
delay(pauseBetweenNotes);
noTone(TONE_PIN);
}
}
void BadMelody(){
int melody[] = {NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4};
int noteDurations[] = {4, 8, 8, 4, 4, 4, 4, 4};
int SIZE_ARRAY = (sizeof(melody)/sizeof(melody[0]));
for(int thisNote = 0; thisNote < SIZE_ARRAY; thisNote++) {
int noteDuration = 1000 / noteDurations[thisNote];
tone(TONE_PIN, melody[thisNote], noteDuration);
int pauseBetweenNotes = noteDuration * 2.00;
delay(pauseBetweenNotes);
noTone(TONE_PIN);
}
}