-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventReceiver.cpp
59 lines (48 loc) · 1.19 KB
/
EventReceiver.cpp
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
#include "EventReceiver.h"
EventReceiver::EventReceiver()
{
events = new LinkedList<Event*>();
sCommand = &sCmds;
sCmds.addCommand("Event", ReadSerial);
}
void EventReceiver::getEvent() {
for(int i = 0; i < bufEvents.size(); i++){
events->add(bufEvents.get(i));
DEBUG_PRINTLN("Event Receiver Got Event");
}
bufEvents.clear();
}
void EventReceiver::Receive() {
sCmds.readSerial();
getEvent();
}
LinkedList<Event*>* EventReceiver::Pop()
{
LinkedList<Event*>* listToPop = events;
events = new LinkedList<Event*>();
return listToPop;
}
int EventReceiver::Size(){
return events->size();
}
static void EventReceiver::ReadSerial(){
char *arg;
Event* e;
arg = sCommand->next(); // Get the next argument from the SerialCommand object buffer
if (arg != NULL) // As long as it existed, take it
{
if(strcmp(arg, "Note") == 0){
DEBUG_PRINT(arg);
arg = sCommand->next();
if (arg == NULL) return;
int pitch = atoi(arg);
DEBUG_PRINT(arg);
arg = sCommand->next();
if (arg == NULL) return;
float timeLeft = atof(arg);
DEBUG_PRINTLN(arg);
e = new NoteEvent(pitch, timeLeft);
bufEvents.add(e);
}
}
}