-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathLTTO.cpp
More file actions
226 lines (181 loc) · 5.37 KB
/
LTTO.cpp
File metadata and controls
226 lines (181 loc) · 5.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#include "LTTO.h"
#define LIBCALL_ENABLEINTERRUPT
#include <EnableInterrupt.h>
///---------------------------------------------------------------------------------------------------------
// The LTTO Constructor
LTTO::LTTO()
{
// Move along, nothing to see here !
};
void LTTO::begin(byte txPin, byte rxPin)
{
_txPin = txPin;
_rxPin = rxPin;
pinMode (_txPin, OUTPUT);
pinMode (_rxPin, INPUT_PULLUP);
#ifdef DEBUG
_deBugPin = DE_BUG_TIMING_PIN;
pinMode (DE_BUG_TIMING_PIN, OUTPUT); // This is my DeBug timing pin, fed to the Logic Analyser
digitalWrite(DE_BUG_TIMING_PIN, LOW);
#endif
receiveMilliTimer = 32767;
irPacketLength = 0;
countISR = 0;
_shortPulseLengthError = 0;
_arrayOverLengthError = 0;
_badMessage_CountISRshortPacket = 0;
_badMessage_InvalidPacketType = 0;
_badMessage_non3_6Header = 0;
_fifoPushPointer = 0;
_fifoPopPointer = 0;
for (byte x = 0; x < FIFO_SIZE; x++)
{
_incomingIRmessageFIFO[_fifoPopPointer].type == ' ';
}
_messageOverwrittenCount = 0; //TODO: Did this fix the Overflow on start-up?
////----------------------------------------------------------------------------------------------
// Set Timer0 interrupt
// Timer0 is used for millis(), so this routine piggybacks on that by using a mid-time interupt
OCR0A = 0xAF;
TIMSK0 |= _BV(OCIE0A);
////----------------------------------------------------------------------------------------------
// Add this instance to the Interrupt array
SetUpPinChangeInterupt(_rxPin, this );
}
///---------------------------------------------------------------------------------------------------------
// LTTO Destructor
// TODO: Add a Destructor to remove the Interrupt.
///---------------------------------------------------------------------------------------------------------
// Public: This routine Serial.prints the error counts.
void LTTO::readErrors()
{
Serial.print(F("\n----------------"));
Serial.print(F("\nShortPulse: "));
Serial.print(_shortPulseLengthError);
Serial.print(F("\tArrayOverRun: "));
Serial.print(_arrayOverLengthError);
Serial.print(F("\nShortPacketLength: "));
Serial.print(_badMessage_CountISRshortPacket);
Serial.print(F("\tInvalidPacketType: "));
Serial.print(_badMessage_InvalidPacketType);
Serial.print(F("\tBadMessage_non3_6Header: "));
Serial.print(_badMessage_non3_6Header);
Serial.print(F("\n----------------"));
}
///---------------------------------------------------------------------------------------------------------
// Public : read/writeXXXXX - Returns the decoded variables of the last IR message
void LTTO::clearMessageOverwrittenCount()
{
_messageOverwrittenCount = 0;
}
byte LTTO::readMessageOverwrittenCount()
{
return _messageOverwrittenCount;
}
char LTTO::readMessageType()
{
return decodedIRmessage.type;
}
unsigned int LTTO::readRawDataPacket()
{
return decodedIRmessage.rawDataPacket;
}
byte LTTO::readTeamID()
{
return decodedIRmessage.teamID;
}
byte LTTO::readPlayerID()
{
return decodedIRmessage.playerID;
}
byte LTTO::readShotStrength()
{
return decodedIRmessage.shotStrength;
}
char LTTO::readBeaconType()
{
return decodedIRmessage.beaconType;
}
bool LTTO::readShieldsActiveBeacon()
{
return decodedIRmessage.shieldsActiveBeacon;
}
int LTTO::readTagsRemainingBeacon()
{
return decodedIRmessage.tagsRemainingBeacon;
}
bool LTTO::readTagReceivedBeacon()
{
return decodedIRmessage.tagReceivedBeacon;
}
byte LTTO::readPacketByte()
{
return decodedIRmessage.packetByte;
}
String LTTO::readPacketName()
{
return decodedIRmessage.packetName;
}
String LTTO::readDataType()
{
return decodedIRmessage.dataType;
}
long int LTTO::readDataByte()
{
return decodedIRmessage.dataByte;
//decodedIRmessage.dataByte = 0;
}
byte LTTO::readByteCount()
{
return decodedIRmessage.byteCount;
}
uint8_t LTTO::readCheckSumRxByte()
{
return decodedIRmessage.checkSumRxByte;
}
bool LTTO::readCheckSumOK()
{
return decodedIRmessage.checkSumOK;
}
int LTTO::readCheckSumCalc()
{
return decodedIRmessage.checkSumCalc;
}
void LTTO::clearIRmessage()
{
decodedIRmessage.newMessage = false;
decodedIRmessage.type = NO_MESSAGE;
decodedIRmessage.rawDataPacket = 0;
}
///---------------------------------------------------------------------------------------------------------
// Public : PrintBinary - Prints out any number in Binary, including lead zeros, the size specified.
// Very useful for debugging
void LTTO::printBinary(uint16_t number, byte numberOfDigits)
{
uint16_t _number = number;
byte _numberOfDigits = numberOfDigits;
//#ifdef DEBUG
int _mask = 0;
for (byte _n = 1; _n <= _numberOfDigits; _n++)
{
_mask = (_mask << 1) | 0x0001;
}
_number = _number & _mask; // truncate v to specified number of places
while(_numberOfDigits)
{
if (_number & (0x0001 << (_numberOfDigits - 1) ) )
{
Serial.print(F("1"));
}
else
{
Serial.print(F("0"));
}
--_numberOfDigits;
if( ( (_numberOfDigits % 4) == 0) && (_numberOfDigits != 0) )
{
Serial.print(F("_"));
}
}
//#endif
}