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

FIZReader.h

Committer:
AndyA
Date:
2021-02-09
Revision:
6:61274e214f46
Parent:
5:7994913a15fe

File content as of revision 6:61274e214f46:

#ifndef __FIZReader_H__
#define __FIZReader_H__
#include "BufferedSerial.h"

#define InBufferSize 32

class FIZReader {

public:
  FIZReader(const PinName Tx, const PinName Rx);
    void requestCurrent();

    /// true if the values have been updated since the last update.
    bool getMostRecent(uint32_t *focus, uint16_t *iris, uint16_t *zoom);

private:

  RawSerial _port;
  
  void OnRx(void);
  void parsePacket();
  
  uint8_t inputBuffer[InBufferSize];
  int inputPtr;
  
    uint32_t _focus;
    uint16_t _iris;
    uint16_t _zoom;
    bool newData;
    
    inline int hexValue(char ascii) {
        if (((ascii-'0') >= 0) && ((ascii-'0') <= 9))
            return ascii-'0';
        if (((ascii-'A') >= 0) && ((ascii-'A') <= 5))
            return ascii-'A'+10;
        if (((ascii-'a') >= 0) && ((ascii-'a') <= 5))
            return ascii-'a'+10;
        return 0;
    }    
    
};

#endif