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
Diff: LTCDecode.cpp
- Revision:
- 1:dd1f7e162f91
- Parent:
- 0:97661408d0f9
- Child:
- 9:7214e3c3e5f8
--- a/LTCDecode.cpp Fri Jan 15 11:49:01 2021 +0000
+++ b/LTCDecode.cpp Fri Jan 15 15:44:39 2021 +0000
@@ -1,110 +1,119 @@
#include "LTCDecode.h"
const float FrameRates[] = {0, 23.976, 24, 25, 29.97, 30,
- 47.95, 48, 50, 59.94, 60, 10000000};
+ 47.95, 48, 50, 59.94, 60, 10000000
+ };
const double FramePeriods[] = {1000000, 1000000 / 23.976, 1000000 / 24,
- 1000000 / 25, 1000000 / 29.97, 1000000 / 30,
- 1000000 / 47.95, 1000000 / 48, 1000000 / 50,
- 1000000 / 59.94, 1000000 / 60, 10};
+ 1000000 / 25, 1000000 / 29.97, 1000000 / 30,
+ 1000000 / 47.95, 1000000 / 48, 1000000 / 50,
+ 1000000 / 59.94, 1000000 / 60, 10
+ };
const int numberOfRates = 11;
-LTCDecode::LTCDecode(const PinName pin) : _LTCIn(pin) {
- LTCsynced = false;
- _LTCIn.fall(callback(this, <CDecode::LTCOnEdge));
- _LTCIn.rise(callback(this, <CDecode::LTCOnEdge));
- newBitsWrite = 0;
- bitCounter = 0;
- dwordCounter = 0;
- newBitsRead = 0;
- markCount = 0;
+LTCDecode::LTCDecode(const PinName pin) : _LTCIn(pin)
+{
+ LTCsynced = false;
+ newBitsWrite = 0;
+ bitCounter = 0;
+ dwordCounter = 0;
+ newBitsRead = 0;
+ markCount = 0;
}
-void LTCDecode::setInputTimer(Timer *inputTimer) { _inputTimer = inputTimer; }
-
-void LTCDecode::LTCOnEdge() {
- uint32_t transitionTime = _inputTimer->read_us();
- uint32_t period = (transitionTime - lastTransition);
- lastTransition = transitionTime;
- if (period >
- maxMidSymbolTimeUS) { // time since last transition is > maximum time for
- // a 1, must be a zero and start of the next bit.
- // printf("Z");
- bitTimes[newBitsWrite] = lastBitStart;
- lastBitStart = transitionTime;
- newBitBuffer[newBitsWrite++] = false;
- if (newBitsWrite == _newBitBufferSize_)
- newBitsWrite = 0;
- return;
- }
- // if it's not a 0 it must be a 1 but are we at the end of the bit yet?
- if ((transitionTime - lastBitStart)> minBitPeriodUS) { // end of a bit
- // printf("N");
- bitTimes[newBitsWrite] = lastBitStart;
- lastBitStart = transitionTime;
- newBitBuffer[newBitsWrite++] = true;
- if (newBitsWrite == _newBitBufferSize_)
- newBitsWrite = 0;
- return;
- }
+void LTCDecode::setInputTimer(Timer *inputTimer)
+{
+ _inputTimer = inputTimer;
+ _LTCIn.fall(callback(this, <CDecode::LTCOnEdge));
+ _LTCIn.rise(callback(this, <CDecode::LTCOnEdge));
}
-bool LTCDecode::searchForSync() {
- while (!LTCsynced && (newBitsRead != newBitsWrite)) {
- LTCBuffer[0] = LTCBuffer[0] << 1;
- if (newBitBuffer[newBitsRead++])
- LTCBuffer[0] |= 0x01;
- if (_newBitBufferSize_ == newBitsRead)
- newBitsRead = 0;
- if ((LTCBuffer[0] & 0x0000FFFF) == 0x3FFD) {
- LTCsynced = true;
- memset(LTCBuffer, 0, 3 * sizeof(uint32_t));
+void LTCDecode::LTCOnEdge()
+{
+ uint32_t transitionTime = _inputTimer->read_us();
+ uint32_t period = (transitionTime - lastTransition);
+ lastTransition = transitionTime;
+ if (period >
+ maxMidSymbolTimeUS) { // time since last transition is > maximum time for
+ // a 1, must be a zero and start of the next bit.
+ // printf("Z");
+ bitTimes[newBitsWrite] = lastBitStart;
+ lastBitStart = transitionTime;
+ newBitBuffer[newBitsWrite++] = false;
+ if (newBitsWrite == _newBitBufferSize_)
+ newBitsWrite = 0;
+ return;
}
- }
- return LTCsynced;
+ // if it's not a 0 it must be a 1 but are we at the end of the bit yet?
+ if ((transitionTime - lastBitStart)> minBitPeriodUS) { // end of a bit
+ // printf("N");
+ bitTimes[newBitsWrite] = lastBitStart;
+ lastBitStart = transitionTime;
+ newBitBuffer[newBitsWrite++] = true;
+ if (newBitsWrite == _newBitBufferSize_)
+ newBitsWrite = 0;
+ return;
+ }
}
-bool LTCDecode::readWaitingData() {
- while (newBitsRead != newBitsWrite) {
- timeOfBit = bitTimes[newBitsRead];
-
- if ((bitCounter == 0) && (dwordCounter == 0))
- frameStartTime = timeOfBit;
+bool LTCDecode::searchForSync()
+{
+ while (!LTCsynced && (newBitsRead != newBitsWrite)) {
+ LTCBuffer[0] = LTCBuffer[0] << 1;
+ if (newBitBuffer[newBitsRead++])
+ LTCBuffer[0] |= 0x01;
+ if (_newBitBufferSize_ == newBitsRead)
+ newBitsRead = 0;
+ if ((LTCBuffer[0] & 0x0000FFFF) == 0x3FFD) {
+ LTCsynced = true;
+ memset(LTCBuffer, 0, 3 * sizeof(uint32_t));
+ }
+ }
+ return LTCsynced;
+}
- if (newBitBuffer[newBitsRead++])
- LTCBuffer[dwordCounter] |= (1 << bitCounter);
-
- if (_newBitBufferSize_ == newBitsRead)
- newBitsRead = 0;
+bool LTCDecode::readWaitingData()
+{
+ while (newBitsRead != newBitsWrite) {
+ timeOfBit = bitTimes[newBitsRead];
- bitCounter++;
- if (32 == bitCounter) {
- dwordCounter++;
- bitCounter = 0;
- }
+ if ((bitCounter == 0) && (dwordCounter == 0))
+ frameStartTime = timeOfBit;
+
+ if (newBitBuffer[newBitsRead++])
+ LTCBuffer[dwordCounter] |= (1 << bitCounter);
+
+ if (_newBitBufferSize_ == newBitsRead)
+ newBitsRead = 0;
- if ((2 == dwordCounter) && (16 == bitCounter)) {
- bitCounter = 0;
- dwordCounter = 0;
- if ((LTCBuffer[2] & 0xFFFF) != 0xBFFC) {
- LTCsynced = false;
- return true;
- } else {
- lastFrame.frame = LTCBuffer[0] & 0xf;
- lastFrame.frame += ((LTCBuffer[0] >> 8) & 0x3) * 10;
- lastFrame.seconds = (LTCBuffer[0] >> 16) & 0xf;
- lastFrame.seconds += ((LTCBuffer[0] >> 24) & 0x7) * 10;
- lastFrame.minutes = LTCBuffer[1] & 0xf;
- lastFrame.minutes += ((LTCBuffer[1] >> 8) & 0x7) * 10;
- lastFrame.hours = (LTCBuffer[1] >> 16) & 0xf;
- lastFrame.hours += ((LTCBuffer[1] >> 24) & 0x3) * 10;
- lastFrame.frameDrop = (LTCBuffer[0] & (1 << 10)) == (1 << 10);
- lastFrame.frameStartTime = frameStartTime;
- memset(LTCBuffer, 0, 3 * sizeof(uint32_t));
- return true;
- }
+ bitCounter++;
+ if (32 == bitCounter) {
+ dwordCounter++;
+ bitCounter = 0;
+ }
+
+ if ((2 == dwordCounter) && (16 == bitCounter)) {
+ bitCounter = 0;
+ dwordCounter = 0;
+ if ((LTCBuffer[2] & 0xFFFF) != 0xBFFC) {
+ LTCsynced = false;
+ return true;
+ } else {
+ lastFrame.frame = LTCBuffer[0] & 0xf;
+ lastFrame.frame += ((LTCBuffer[0] >> 8) & 0x3) * 10;
+ lastFrame.seconds = (LTCBuffer[0] >> 16) & 0xf;
+ lastFrame.seconds += ((LTCBuffer[0] >> 24) & 0x7) * 10;
+ lastFrame.minutes = LTCBuffer[1] & 0xf;
+ lastFrame.minutes += ((LTCBuffer[1] >> 8) & 0x7) * 10;
+ lastFrame.hours = (LTCBuffer[1] >> 16) & 0xf;
+ lastFrame.hours += ((LTCBuffer[1] >> 24) & 0x3) * 10;
+ lastFrame.frameDrop = (LTCBuffer[0] & (1 << 10)) == (1 << 10);
+ lastFrame.frameStartTime = frameStartTime;
+ memset(LTCBuffer, 0, 3 * sizeof(uint32_t));
+ return true;
+ }
+ }
}
- }
- return false;
+ return false;
}