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
FIZ_readers/FIZ_DISNEY.cpp@85:0cc5931bb9ef, 22 months ago (annotated)
- Committer:
- JamieB
- Date:
- Thu Dec 15 06:05:30 2022 +0000
- Revision:
- 85:0cc5931bb9ef
- Parent:
- 17:5ce3fe98e76d
Push to somewhere else due to merge issue
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AndyA | 16:a8d3a0dbe4bf | 1 | #include "FIZ_DISNEY.h" |
AndyA | 16:a8d3a0dbe4bf | 2 | #include "LTCApp.h" |
AndyA | 16:a8d3a0dbe4bf | 3 | FIZDisney::FIZDisney(const PinName Tx, const PinName Rx) : FIZReader(Tx,Rx) |
AndyA | 16:a8d3a0dbe4bf | 4 | { |
AndyA | 16:a8d3a0dbe4bf | 5 | inputPtr = 0; |
AndyA | 16:a8d3a0dbe4bf | 6 | newData = false; |
AndyA | 16:a8d3a0dbe4bf | 7 | _port.baud(115200); |
AndyA | 16:a8d3a0dbe4bf | 8 | _port.attach(callback(this, &FIZDisney::OnRx)); |
AndyA | 16:a8d3a0dbe4bf | 9 | } |
AndyA | 16:a8d3a0dbe4bf | 10 | |
AndyA | 16:a8d3a0dbe4bf | 11 | void FIZDisney::requestCurrent(void) |
AndyA | 16:a8d3a0dbe4bf | 12 | { |
AndyA | 16:a8d3a0dbe4bf | 13 | _port.putc(0x02); |
AndyA | 16:a8d3a0dbe4bf | 14 | _port.putc('0'); |
AndyA | 16:a8d3a0dbe4bf | 15 | _port.putc('C'); |
AndyA | 16:a8d3a0dbe4bf | 16 | _port.putc('0'); |
AndyA | 16:a8d3a0dbe4bf | 17 | _port.putc('0'); |
AndyA | 16:a8d3a0dbe4bf | 18 | _port.putc('D'); |
AndyA | 16:a8d3a0dbe4bf | 19 | _port.putc('5'); |
AndyA | 16:a8d3a0dbe4bf | 20 | _port.putc(0x03); |
AndyA | 16:a8d3a0dbe4bf | 21 | } |
AndyA | 16:a8d3a0dbe4bf | 22 | |
AndyA | 16:a8d3a0dbe4bf | 23 | void FIZDisney::OnRx(void) |
AndyA | 16:a8d3a0dbe4bf | 24 | { |
AndyA | 17:5ce3fe98e76d | 25 | inputBuffer[inputPtr] = _port.getc(); |
AndyA | 17:5ce3fe98e76d | 26 | if (inputPtr==0) { |
AndyA | 17:5ce3fe98e76d | 27 | if (inputBuffer[inputPtr] == 0x02) |
AndyA | 17:5ce3fe98e76d | 28 | inputPtr++; |
AndyA | 17:5ce3fe98e76d | 29 | } else if (inputBuffer[inputPtr] == 0x03) { |
AndyA | 17:5ce3fe98e76d | 30 | parsePacket(); |
AndyA | 17:5ce3fe98e76d | 31 | inputPtr = 0; |
AndyA | 17:5ce3fe98e76d | 32 | } else { |
AndyA | 17:5ce3fe98e76d | 33 | inputPtr++; |
AndyA | 17:5ce3fe98e76d | 34 | if (inputPtr == InBufferSize) |
AndyA | 16:a8d3a0dbe4bf | 35 | inputPtr = 0; |
AndyA | 17:5ce3fe98e76d | 36 | } |
AndyA | 16:a8d3a0dbe4bf | 37 | } |
AndyA | 16:a8d3a0dbe4bf | 38 | |
AndyA | 16:a8d3a0dbe4bf | 39 | void FIZDisney::parsePacket() |
AndyA | 16:a8d3a0dbe4bf | 40 | { |
AndyA | 16:a8d3a0dbe4bf | 41 | // expect ASCII string of "0C07ffffffiiiizzzzcs" where ffffff is 6 char hex value for focus |
AndyA | 16:a8d3a0dbe4bf | 42 | // iiii is 4 char hex value for tstop, zzzz is 4 char hex value for zoom and cs is 2 char checksum |
AndyA | 16:a8d3a0dbe4bf | 43 | if (inputPtr != 21) |
AndyA | 16:a8d3a0dbe4bf | 44 | return; |
AndyA | 16:a8d3a0dbe4bf | 45 | if (inputBuffer[1] != '0') |
AndyA | 16:a8d3a0dbe4bf | 46 | return; |
AndyA | 16:a8d3a0dbe4bf | 47 | if (inputBuffer[2] != 'C') |
AndyA | 16:a8d3a0dbe4bf | 48 | return; |
AndyA | 17:5ce3fe98e76d | 49 | _focus = 0; |
AndyA | 17:5ce3fe98e76d | 50 | _iris = 0; |
AndyA | 17:5ce3fe98e76d | 51 | _zoom = 0; |
AndyA | 17:5ce3fe98e76d | 52 | for (int count = 0; count<6; count++) { |
AndyA | 16:a8d3a0dbe4bf | 53 | _focus*=16; |
AndyA | 16:a8d3a0dbe4bf | 54 | _focus += hexValue(inputBuffer[5+count]); |
AndyA | 16:a8d3a0dbe4bf | 55 | } |
AndyA | 17:5ce3fe98e76d | 56 | for (int count = 0; count<4; count++) { |
AndyA | 16:a8d3a0dbe4bf | 57 | _iris*=16; |
AndyA | 16:a8d3a0dbe4bf | 58 | _iris += hexValue(inputBuffer[11+count]); |
AndyA | 16:a8d3a0dbe4bf | 59 | _zoom*=16; |
AndyA | 16:a8d3a0dbe4bf | 60 | _zoom += hexValue(inputBuffer[15+count]); |
AndyA | 16:a8d3a0dbe4bf | 61 | } |
AndyA | 17:5ce3fe98e76d | 62 | // raw iris data is in 10ths of a stop. We want 100ths |
AndyA | 17:5ce3fe98e76d | 63 | _iris *= 10; |
AndyA | 16:a8d3a0dbe4bf | 64 | newData = true; |
AndyA | 16:a8d3a0dbe4bf | 65 | } |