-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathEvent.cpp
More file actions
79 lines (53 loc) · 1.84 KB
/
Event.cpp
File metadata and controls
79 lines (53 loc) · 1.84 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
//=============================================================================
// To decouple the low level communication protocol from the higher level view
// of what needs to get done, all commands and response are passed around as
// Events. A lower level class converts protocol messages to/from events.
//
// Note that events have a buffer, and buffers consume the little bit of RAM
// present in an Arduino, so minimize the number of Events allocated or else
// memory might be a problem.
//
// Bob Applegate, K2UT - bob@corshamtech.com
#include "Event.h"
//=============================================================================
// Constructor does very little.
Event::Event(void)
{
type = EVT_NONE;
index = 0; // no data in buffer yet
}
//=============================================================================
// Destructor.
Event::~Event(void)
{
}
//=============================================================================
// Some events have data associated with them, such as file contents, filenames,
// etc. This method is used to add a byte to the message contents of the
// Event.
void Event::addByte(byte data)
{
// Make sure we aren't about to exceed the buffer size
if (index == BUFFER_SIZE)
{
}
else
{
buffer[index++] = data;
}
}
//=============================================================================
// This cleans up an event by removing all old data, clearing the type, etc.
void Event::clean(void)
{
type = EVT_NONE;
index = 0;
}
//=============================================================================
// This assigns a new event type to this event and also clears out any old
// data.
void Event::clean(EVENT_TYPE atype)
{
type = atype;
index = 0;
}