I messed up the merge, so pushing it over to another repo so I don't lose it. Will tidy up and remove later

Dependencies:   BufferedSerial FatFileSystemCpp mbed

Revision:
9:7214e3c3e5f8
Parent:
7:87aea27cc68b
Child:
10:053bac3e326b
--- a/LTCDecode.h	Tue Feb 16 09:53:54 2021 +0000
+++ b/LTCDecode.h	Thu Feb 18 18:15:48 2021 +0000
@@ -3,77 +3,73 @@
 
 #include "mbed.h"
 
-  const uint32_t minBitPeriodUS =
-      (uint32_t)((1000000.0f / 2400) / 1.1f); // allow for 10% time error
-  const uint32_t maxMidSymbolTimeUS = (uint32_t)(
-      ((1000000.0f / (1920 * 2))) * 1.1f); // allow for 10% time error
 
-class LTCDecode {
+class LTCDecode
+{
 
 public:
-  LTCDecode(const PinName pin);
-  void setInputTimer(Timer *inputTimer);
+    LTCDecode(const PinName pin);
 
-  bool synced() { return LTCsynced; };
+    inline bool synced()
+    {
+        return LTCsynced;
+    };
 
-  // reads pending data up to a sync marker, returns true is sync is found.
-  bool searchForSync();
+    void enable(bool enable);
 
-  // reads pending data up to the end of the frame, returns true at the end of a
-  // frame. check sync stats and lastFrameData for results.
-  bool readWaitingData();
+    void attachFrame(void (*callback)(void))
+    {
+        FrameCallback.attach(callback);
+    }
 
-  typedef struct {
-    int hours;
-    int minutes;
-    int seconds;
-    int frame;
-    bool frameDrop;
-    uint32_t frameStartTime;
-  } LTCData_t;
+    inline void getTime(int *hour, int *minute, int *second, int *frame)
+    {
+        *hour = _hours;
+        *minute = _minutes;
+        *second = _seconds;
+        *frame = _frame;
+    }
+    
+    inline bool isFrameDrop() {return _frameDrop;}
 
-  const LTCData_t *getLastFrame() { return &lastFrame; };
+    template<typename T>
+    void attachFrame(T* tptr, void (T::*mptr)(void))
+    {
+        FrameCallback.attach(tptr, mptr);
+    }
 
-  void disable() {
-    _LTCIn.fall(NULL);
-    _LTCIn.rise(NULL);
-    }
-  // buffer holding received LTC bits and their start times.
+    // buffer holding received LTC bits and their start times.
 
 private:
-  void LTCOnEdge(void);
-
-  InterruptIn _LTCIn;
-  Timer *_inputTimer;
-
-  LTCData_t lastFrame;
+    void LTCOnEdge(void);
 
-  static const int _newBitBufferSize_ = 80;
-
-  bool newBitBuffer[_newBitBufferSize_];
-  uint32_t bitTimes[_newBitBufferSize_];
+    InterruptIn _LTCIn;
+    Timer inputTimer;
 
-  bool LTCsynced;
-
-  volatile int newBitsWrite;
-  int newBitsRead;
+    FunctionPointer FrameCallback;
 
-  // max bit period = 520.8 ms (1920 Hz)
-  // min bit period = 416.7 ms (2400 Hz)
-  // max period of a '1' symbol = 260.4ms (1920Hz * 2)
+    // add a bit. Return true if we got the end of frame pattern
+    bool addBitToBuffer(bool bit);
+    void decodeTime();
+    int _hours;
+    int _minutes;
+    int _seconds;
+    int _frame;
+    bool _frameDrop;
 
-  uint32_t lastTransition;
-  uint32_t lastBitStart;
+    bool LTCsynced;
 
-  uint32_t LTCBuffer[3];
-  uint32_t firstMark;
-  int markCount;
-  uint32_t nextSecondStart;
-  uint32_t PPSWidth;
-  int bitCounter ;
-  int dwordCounter ;
+    volatile int newBitsWrite;
+    int newBitsRead;
 
-  uint32_t timeOfBit, frameStartTime;
+    // max bit period = 520.8 ms (1920 Hz)
+    // min bit period = 416.7 ms (2400 Hz)
+    // max period of a '1' symbol = 260.4ms (1920Hz * 2)
+
+    uint32_t lastTransition;
+    uint32_t lastBitStart;
+
+    uint32_t LTCBuffer[3];
 };
 
 #endif