Commit 36f1aef1ac99b79ad6b77b0d29cca53510ce55c7
1 parent
d652a093
Exists in
master
and in
1 other branch
queue updated from char* to string (cpp)
-thiisaunfinishedcommitbecauseIdonttrustthiscomputer-
Showing
1 changed file
with
22 additions
and
10 deletions
Show diff stats
app/src/inoChannel.cpp
... | ... | @@ -6,24 +6,31 @@ void inoChannel::setup(string device) { |
6 | 6 | } |
7 | 7 | |
8 | 8 | void inoChannel::exit() { |
9 | - while(!commands.empty()) { | |
10 | - delete[] commands.front(); | |
11 | - commands.pop(); | |
12 | - } | |
9 | + // there is no memory to free (now) | |
13 | 10 | } |
14 | 11 | |
15 | 12 | void inoChannel::identify() { |
16 | - char *command = new char[device.size()+2]; | |
17 | - command[0] = HW_HELO; | |
18 | - command[1] = device.size(); | |
19 | - memcpy(&command[2], device.c_str(), device.size()); | |
13 | + string cmd; | |
14 | + | |
15 | + cmd.append(device); | |
16 | + cmd.push_back(HW_HELO); | |
17 | + cmd.push_back(device.size()); | |
18 | + | |
20 | 19 | commands.push(command); |
21 | 20 | } |
22 | 21 | |
23 | 22 | void inoChannel::startStream() { |
23 | + string cmd; | |
24 | + cmd.push_back(HW_START_STREAM); | |
25 | + | |
26 | + commands.push(cmd); | |
24 | 27 | } |
25 | 28 | |
26 | 29 | void inoChannel::stopStream() { |
30 | + string cmd; | |
31 | + cmd.push_back(HW_STOP_STREAM); | |
32 | + | |
33 | + commands.push(cmd); | |
27 | 34 | } |
28 | 35 | |
29 | 36 | void inoChannel::checkSystem() { |
... | ... | @@ -50,8 +57,13 @@ void inoChannel::threadedFunction() { |
50 | 57 | while(isThreadRunning()) { |
51 | 58 | // Read from Arduino (frame) |
52 | 59 | // Check commands / Send |
53 | - // serial.writeBytes(buffer, length); | |
54 | - // serial.writeBytes(command.c_str(), command.size()); | |
60 | + | |
61 | + if (commands.size() > 1) { | |
62 | + string cmd = commands.front(); | |
63 | + if (serial.writeBytes(cmd.c_str(), cmd.size())) { | |
64 | + commands.pop(); | |
65 | + } | |
66 | + } | |
55 | 67 | } |
56 | 68 | string status("Closed"); |
57 | 69 | ofNotifyEvent(statusChange, status, this); | ... | ... |