Mateusz Grzywacz / SDI12_device

Files at this revision

API Documentation at this revision

Comitter:
amateusz
Date:
Thu Aug 02 11:16:24 2018 +0000
Parent:
9:a3062b9e4324
Child:
11:e0ccc1072c42
Commit message:
New SDI-12 terminal, yikes!

Changed in this revision

SDI12_device.h Show annotated file Show diff for this revision Revisions of this file
--- a/SDI12_device.h	Wed Aug 01 18:13:52 2018 +0000
+++ b/SDI12_device.h	Thu Aug 02 11:16:24 2018 +0000
@@ -22,15 +22,14 @@
 
     Identification_struct _ident_struct;
 
-    static int detect(SDI12 &sdi12, char indices[], int limit = -1){
+    static int detect(SDI12 &sdi12, char indices[], int stop = -1, int start = -1) {
         char found = 0;
-        for (size_t i = 0; i < (limit==-1?ADDRRICES.size():limit); ++i) {
+        for (size_t i = (start==-1?0:start); i < (stop==-1?ADDRRICES.size():stop+1); ++i) {
 
             string question = "?!";
             question[0] = ADDRRICES[i];
             sdi12.sendCommand(question);
             std::string response;
-//            debug("SEARCHING: %d\r\n", i);
             Timer detectTimer;
             detectTimer.start();
             while (detectTimer.read_ms() < RESPONSE_TIMEOUT) {
@@ -46,20 +45,21 @@
                     }
                 }
             }
+            osDelay(200);
         }
         return found;
     };
 
-    SDI12_device (SDI12 &inst, char address, EventQueue &mainDispatcher) : _sdi12(inst),sensorQueue(4*EVENTS_QUEUE_SIZE){
+    SDI12_device (SDI12 &inst, char address, EventQueue &mainDispatcher) : _sdi12(inst),sensorQueue(4*EVENTS_QUEUE_SIZE) {
         setAddress(address);
         sensorQueue.chain(&mainDispatcher);
         if(getIdentification(_ident_struct));
     };
-    //~SDI12_device () {
-//        // unchain event queue
+    ~SDI12_device () {
+        // unchain event queue
 //        sensorQueue.cancel(_measurementEventId);
-//        sensorQueue.chain(NULL);
-//    }
+        sensorQueue.chain(NULL);
+    }
 
 
 //        // returns after how many seconds a measurement will be ready
@@ -77,7 +77,7 @@
                 return false;
             }
         }
-        
+
         unsigned char bufferSize = sdi12.RxBufferAvailable();
         char buffer[bufferSize+1];
         sdi12.getRxBuffer(buffer);