only report error once
authorJim Morris <morris@wolfman.com>
Tue, 24 Nov 2015 22:42:34 +0000 (14:42 -0800)
committerJim Morris <morris@wolfman.com>
Tue, 24 Nov 2015 22:42:34 +0000 (14:42 -0800)
src/modules/utils/motordrivercontrol/drivers/DRV8711/drv8711.cpp
src/modules/utils/motordrivercontrol/drivers/DRV8711/drv8711.h

index 3240dd8..4b2fbfb 100644 (file)
@@ -9,6 +9,7 @@
 
 DRV8711DRV::DRV8711DRV(std::function<int(uint8_t *b, int cnt, uint8_t *r)> spi) : spi(spi)
 {
+    error_reported.reset();
 }
 
 void DRV8711DRV::init (uint16_t gain)
@@ -321,30 +322,49 @@ bool DRV8711DRV::check_alarm()
     R_STATUS_REG.raw= ReadRegister(G_STATUS_REG.Address);
 
     if(R_STATUS_REG.OTS) {
-        THEKERNEL->streams->printf("ERROR: Overtemperature shutdown\n");
+        if(!error_reported.test(0)) THEKERNEL->streams->printf("ERROR: Overtemperature shutdown\n");
         error= true;
+        error_reported.set(0);
+    }else{
+        error_reported.reset(0);
     }
 
+
     if(R_STATUS_REG.AOCP) {
-        THEKERNEL->streams->printf("ERROR: Channel A over current shutdown\n");
+        if(!error_reported.test(1)) THEKERNEL->streams->printf("ERROR: Channel A over current shutdown\n");
         error= true;
+        error_reported.set(1);
+    }else{
+        error_reported.reset(1);
     }
 
+
     if(R_STATUS_REG.BOCP) {
-        THEKERNEL->streams->printf("ERROR: Channel B over current shutdown\n");
+        if(!error_reported.test(2)) THEKERNEL->streams->printf("ERROR: Channel B over current shutdown\n");
         error= true;
+        error_reported.set(2);
+    }else{
+        error_reported.reset(2);
     }
 
     if(R_STATUS_REG.APDF) {
-        THEKERNEL->streams->printf("ERROR: Channel A predriver fault\n");
+        if(!error_reported.test(3)) THEKERNEL->streams->printf("ERROR: Channel A predriver fault\n");
         error= true;
+        error_reported.set(3);
+    }else{
+        error_reported.reset(3);
     }
 
+
     if(R_STATUS_REG.BPDF) {
-        THEKERNEL->streams->printf("ERROR: Channel B predriver fault\n");
+        if(!error_reported.test(4)) THEKERNEL->streams->printf("ERROR: Channel B predriver fault\n");
         error= true;
+        error_reported.set(4);
+    }else{
+        error_reported.reset(4);
     }
 
+
     return error;
 }
 
index 973f3cc..9d95643 100644 (file)
@@ -1,6 +1,7 @@
 #pragma once
 
 #include <functional>
+#include <bitset>
 
 class StreamOutput;
 
@@ -139,6 +140,7 @@ private:
 
   std::function<int(uint8_t *b, int cnt, uint8_t *r)> spi;
   float resistor{0.05};
+  std::bitset<8> error_reported;
   uint8_t gain{20};