From 608e70d95e78f549bafeb9cb4df2ed8af111511b Mon Sep 17 00:00:00 2001
From: Jochen Vothknecht <jochen3120@gmail.com>
Date: Wed, 16 Aug 2023 15:48:22 +0200
Subject: [PATCH] Fault bit accessors

---
 CLC-qthing/SiliconTorch/Hardware/MAX31856.cpp | 80 +++++++++++++++++++
 CLC-qthing/SiliconTorch/Hardware/MAX31856.hpp | 23 ++++++
 2 files changed, 103 insertions(+)

diff --git a/CLC-qthing/SiliconTorch/Hardware/MAX31856.cpp b/CLC-qthing/SiliconTorch/Hardware/MAX31856.cpp
index 4a5c1b9..d9f8b62 100644
--- a/CLC-qthing/SiliconTorch/Hardware/MAX31856.cpp
+++ b/CLC-qthing/SiliconTorch/Hardware/MAX31856.cpp
@@ -176,6 +176,86 @@ namespace MAX31856 {
     });
   }
 
+  bool MAX31856::isTCOpenCircuit() {
+    return mutex.runReturn<bool> ([&]() {
+
+      SR reg;
+      reg.value = spi->readU8(SR::addr);
+
+      return reg.OPEN;
+    });
+  }
+
+  bool MAX31856::isTCOVUV() {
+    return mutex.runReturn<bool> ([&]() {
+
+      SR reg;
+      reg.value = spi->readU8(SR::addr);
+
+      return reg.OVUV;
+    });
+  }
+
+  bool MAX31856::isTCLOW() {
+    return mutex.runReturn<bool> ([&]() {
+
+      SR reg;
+      reg.value = spi->readU8(SR::addr);
+
+      return reg.TCLOW;
+    });
+  }
+
+  bool MAX31856::isTCHIGH() {
+    return mutex.runReturn<bool> ([&]() {
+
+      SR reg;
+      reg.value = spi->readU8(SR::addr);
+
+      return reg.TCHIGH;
+    });
+  }
+
+  bool MAX31856::isCJLOW() {
+    return mutex.runReturn<bool> ([&]() {
+
+      SR reg;
+      reg.value = spi->readU8(SR::addr);
+
+      return reg.CJLOW;
+    });
+  }
+
+  bool MAX31856::isCJHIGH() {
+    return mutex.runReturn<bool> ([&]() {
+
+      SR reg;
+      reg.value = spi->readU8(SR::addr);
+
+      return reg.CJHIGH;
+    });
+  }
+
+  bool MAX31856::isCJRANGE() {
+    return mutex.runReturn<bool> ([&]() {
+
+      SR reg;
+      reg.value = spi->readU8(SR::addr);
+
+      return reg.CJRANGE;
+    });
+  }
+
+  bool MAX31856::isTCRANGE() {
+    return mutex.runReturn<bool> ([&]() {
+
+      SR reg;
+      reg.value = spi->readU8(SR::addr);
+
+      return reg.TCRANGE;
+    });
+  }
+
 
 
 
diff --git a/CLC-qthing/SiliconTorch/Hardware/MAX31856.hpp b/CLC-qthing/SiliconTorch/Hardware/MAX31856.hpp
index 0c438d7..e18ecaf 100644
--- a/CLC-qthing/SiliconTorch/Hardware/MAX31856.hpp
+++ b/CLC-qthing/SiliconTorch/Hardware/MAX31856.hpp
@@ -79,6 +79,13 @@ namespace MAX31856 {
   union MASK {
 
     struct __attribute__((packed)) {
+      u8 OpenFAULTMask   : 1;
+      u8 OVUVFAULTMask   : 1;
+      u8 TCLowFAULTMask  : 1;
+      u8 TCHighFAULTMask : 1;
+      u8 CJLowFAULTMask  : 1;
+      u8 CJHighFAULTMask : 1;
+      u8 _reserved_      : 2;      
     };
 
     u8 value = 0x00;
@@ -229,6 +236,14 @@ namespace MAX31856 {
     // Info: Read only!
 
     struct __attribute__((packed)) {
+      bool OPEN    : 1;
+      bool OVUV    : 1;
+      bool TCLOW   : 1;
+      bool TCHIGH  : 1;
+      bool CJLOW   : 1;
+      bool CJHIGH  : 1;
+      bool TCRANGE : 1;
+      bool CJRANGE : 1;
     };
 
     u8 value = 0x00;
@@ -290,6 +305,14 @@ namespace MAX31856 {
       void             setThermocoupleType(ThermocoupleType tc);
       ThermocoupleType getThermocoupleType();
 
+      bool isTCOpenCircuit();  // fault bit
+      bool isTCOVUV();  // fault bit
+      bool isTCLOW();  // fault bit
+      bool isTCHIGH();  // fault bit
+      bool isCJLOW();  // fault bit
+      bool isCJHIGH();  // fault bit
+      bool isTCRANGE();  // fault bit
+      bool isCJRANGE();  // fault bit
 
 
       void mainLoop();
-- 
GitLab