Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BufferedSerial FatFileSystemCpp mbed
FIZReader.cpp
- Committer:
- AndyA
- Date:
- 2021-02-16
- Revision:
- 8:961bb15570a1
- Parent:
- 6:61274e214f46
File content as of revision 8:961bb15570a1:
#include "FIZReader.h" #include "LTCApp.h" FIZReader::FIZReader(const PinName Tx, const PinName Rx) : _port(Tx,Rx) { _port.baud(115200); inputPtr = 0; _focus = 0; _iris = 0; _zoom = 0; newData = false; _port.attach(callback(this, &FIZReader::OnRx)); } void FIZReader::requestCurrent(void) { _port.putc(0x02); _port.putc('0'); _port.putc('C'); _port.putc('0'); _port.putc('0'); _port.putc('D'); _port.putc('5'); _port.putc(0x03); } bool FIZReader::getMostRecent(uint32_t *focus, uint16_t *iris, uint16_t *zoom) { *focus = _focus; *iris = _iris*10; *zoom = _zoom; bool wasNew = newData; newData = false; return wasNew; } void FIZReader::OnRx(void) { inputBuffer[inputPtr] = _port.getc(); if (inputPtr==0) { if (inputBuffer[inputPtr] == 0x02) inputPtr++; } else if (inputBuffer[inputPtr] == 0x03) { parsePacket(); inputPtr = 0; } else { inputPtr++; if (inputPtr == InBufferSize) inputPtr = 0; } } void FIZReader::parsePacket() { // expect ASCII string of "0C07ffffffiiiizzzzcs" where ffffff is 6 char hex value for focus // iiii is 4 char hex value for tstop, zzzz is 4 char hex value for zoom and cs is 2 char checksum if (inputPtr != 21) return; if (inputBuffer[1] != '0') return; if (inputBuffer[2] != 'C') return; _focus = 0; _iris = 0; _zoom = 0; for (int count = 0;count<6;count++) { _focus*=16; _focus += hexValue(inputBuffer[5+count]); } for (int count = 0;count<4;count++) { _iris*=16; _iris += hexValue(inputBuffer[11+count]); _zoom*=16; _zoom += hexValue(inputBuffer[15+count]); } newData = true; }