Commit 053265a4d3e1d20c085493b08d18f27987fd09a4

Authored by Calvin Bulla
2 parents e7ebdd58 c8a37283
Exists in master and in 1 other branch dev

Merge branch 'dev' of bizet.dis.ulpgc.es:ediaz/heisenwave into dev

app/src/heisenwave.h
... ... @@ -6,3 +6,4 @@
6 6 #define HW_HELO 1
7 7 #define HW_START_STREAM 2
8 8 #define HW_STOP_STREAM 3
  9 +#define HW_NEW_FRAME 10
9 10 \ No newline at end of file
... ...
app/src/inoChannel.cpp
... ... @@ -6,24 +6,28 @@ 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());
20 18 commands.push(command);
21 19 }
22 20  
23 21 void inoChannel::startStream() {
  22 + string cmd;
  23 + cmd.push_back(HW_START_STREAM);
  24 + commands.push(cmd);
24 25 }
25 26  
26 27 void inoChannel::stopStream() {
  28 + string cmd;
  29 + cmd.push_back(HW_STOP_STREAM);
  30 + commands.push(cmd);
27 31 }
28 32  
29 33 void inoChannel::checkSystem() {
... ... @@ -48,10 +52,26 @@ void inoChannel::threadedFunction() {
48 52 serial.flush();
49 53 checkSystem();
50 54 while(isThreadRunning()) {
51   - // Read from Arduino (frame)
52   - // Check commands / Send
53   - // serial.writeBytes(buffer, length);
54   - // serial.writeBytes(command.c_str(), command.size());
  55 + while(serial.available() < 1);
  56 + switch(serial.read()) {
  57 + case HW_NEW_FRAME:
  58 + {
  59 + while(serial.avilable() < 256);
  60 +
  61 + // serial.readBytes(buffer, 256);
  62 +
  63 + break;
  64 + }
  65 + default:
  66 + // no idea what could go wrong
  67 + break;
  68 + }
  69 + if(commands.size() > 1) {
  70 + string cmd = commands.front();
  71 + if(serial.writeBytes(cmd.c_str(), cmd.size())) {
  72 + commands.pop();
  73 + }
  74 + }
55 75 }
56 76 string status("Closed");
57 77 ofNotifyEvent(statusChange, status, this);
... ...
app/src/inoChannel.h
... ... @@ -19,5 +19,5 @@ public:
19 19 private:
20 20 ofSerial serial;
21 21 string device;
22   - queue<char*> commands;
  22 + queue<string> commands;
23 23 };
... ...
ino/lib/heisenwave/heisenwave.h
... ... @@ -15,6 +15,7 @@
15 15 #define HW_DTIME_GET 7
16 16 #define HW_SLEEP 8
17 17 #define HW_STOP_DATA 9
  18 +#define HW_NEW_FRAME 10
18 19  
19 20 // COMMANDS SIZE
20 21  
... ...
ino/src/sketch.ino
... ... @@ -43,6 +43,8 @@ ISR(ADC_vect) {
43 43  
44 44 void send_data() {
45 45 if (transfer_active && transfer_ready) {
  46 + Serial.write(HW_NEW_FRAME);
  47 +
46 48 for (int i = 0; i < SIZE; i++) {
47 49 Serial.write(pc_buffer[i]);
48 50 }
... ...