m3pi for proj2

Dependencies:   RemoteIR m3pi mbed-rtos mbed

Revision:
9:8c5229dfab82
Parent:
7:1d77c7e0208c
Child:
10:7eaaa891ab81
diff -r aff4290aacff -r 8c5229dfab82 LightCommunication.cpp
--- a/LightCommunication.cpp	Wed May 10 09:33:18 2017 +0200
+++ b/LightCommunication.cpp	Wed May 10 10:01:29 2017 +0200
@@ -4,7 +4,10 @@
 
 #include "LightCommunication.h"
 
-LightCommunication::LightCommunication() : ir_rx(p21), device(p14,p15) {
+LightCommunication::LightCommunication()  {
+    ir_rx = new ReceiverIR(p21);
+    device = new Serial(p14,p15);
+    mut = new Mutex();
     left,right = 0;
 }
 
@@ -13,20 +16,20 @@
 }
 
 void LightCommunication::getSerial(char * test) {
-    if(device.readable()) {
-       device.scanf("%s",test);
+    if(device->readable()) {
+       device->scanf("%s",test);
     }
 }
 
 void LightCommunication::getIRStyle(uint8_t * buf) {
     RemoteIR::Format format;
-    if (ir_rx.getState() == ReceiverIR::Received) {
-        ir_rx.getData(&format, buf, sizeof(buf) * 8);
+    if (ir_rx->getState() == ReceiverIR::Received) {
+        ir_rx->getData(&format, buf, sizeof(buf) * 8);
     }
 }
 
 void LightCommunication::receiveData() {
-    LightCommunication::mut.lock();
+    mut->lock();
     //uint8_t *  data = LightCommunication::getIRStyle();
     char  data[3];
     LightCommunication::getSerial(data);
@@ -38,7 +41,7 @@
         right = LightCommunication::toFloat(data[2]);
     }
 
-    LightCommunication::mut.unlock();
+    mut->unlock();
 }
 
 float LightCommunication::getRight(float cur_right){
@@ -55,7 +58,7 @@
 
 float LightCommunication::getLeft(float cur_left){
 
-    mut.lock();
+    mut->lock();
     float l = left - cur_left;
     if (l>0){
         return (float)(cur_left + 0.005);