- BitBuffer_t* Buffer;\r
- uint8_t ClockMask;\r
- uint8_t DataMask; \r
- } TrackInfo[] = {{&Track1Data, MAG_T1_CLOCK, MAG_T1_DATA},\r
- {&Track2Data, MAG_T2_CLOCK, MAG_T2_DATA},\r
- {&Track3Data, MAG_T3_CLOCK, MAG_T3_DATA}};\r
-\r
- /* Previous magnetic card control line' status, for later comparison */\r
- uint8_t Magstripe_Prev = 0;\r
- \r
- /* Buffered current card reader control line' status */\r
- uint8_t Magstripe_LCL = Magstripe_GetStatus();\r
-\r
- /* Exit the task early if no card is present in the reader */\r
- if (!(Magstripe_LCL & MAG_CARDPRESENT))\r
- return;\r
-\r
- /* Read out card data while a card is present */\r
- while (Magstripe_LCL & MAG_CARDPRESENT)\r
- {\r
- /* Read out the next bit for each track of the card */\r
- for (uint8_t Track = 0; Track < 3; Track++)\r
- {\r
- /* Current data line status for the current card track */\r
- bool DataLevel = ((Magstripe_LCL & TrackInfo[Track].DataMask) != 0);\r
-\r
- /* Current clock line status for the current card track */\r
- bool ClockLevel = ((Magstripe_LCL & TrackInfo[Track].ClockMask) != 0);\r
-\r
- /* Current track clock transition check */\r
- bool ClockChanged = (((Magstripe_LCL ^ Magstripe_Prev) & TrackInfo[Track].ClockMask) != 0);\r
- \r
- /* Sample the next bit on the falling edge of the track's clock line, store key code into the track's buffer */\r
- if (ClockLevel && ClockChanged)\r
- BitBuffer_StoreNextBit(TrackInfo[Track].Buffer, DataLevel);\r
- }\r
-\r
- /* Retain the current card reader control line states for later edge detection */\r
- Magstripe_Prev = Magstripe_LCL;\r
- \r
- /* Retrieve the new card reader control line states */\r
- Magstripe_LCL = Magstripe_GetStatus();\r