-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdevice.cpp
50 lines (37 loc) · 881 Bytes
/
device.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
#include "device.h"
#include <iostream>
#include <cstring>
using namespace Chaos;
void Device::init(const char* filename, int bytesPerFrame) {
file = fopen( filename, "r" );
if( file == NULL ) {
std::cerr << "Couldn't open " << filename << std::endl;
}
this->bytesPerFrame = bytesPerFrame;
this->buffer = new char[bytesPerFrame];
}
Device::~Device() {
stop();
WaitForInternalThreadToExit();
fclose( file );
if( buffer != NULL) {
delete [] buffer;
}
}
void Device::addObserver(DeviceObserver* observer) {
this->observer = observer;
}
void Device::doAction() {
// printf("Read: " );
for (int i = 0; i < bytesPerFrame; i++) {
buffer[i] = fgetc( file );
// printf("%d ", (int)buffer[i]);
}
// printf("\n");
DeviceEvent event;
interpret( buffer, &event );
if (observer != NULL &&
event.time != -1) {
observer->newDeviceEvent( &event );
}
}