Project

General

Profile

Revision 270

Added by Kevin Woo almost 14 years ago

Code cleanup on the cardreader stuff

View differences:

cardreader.c
50 50
}
51 51

  
52 52
ISR(PCINT2_vect) {    
53
    //static uint8_t byte_idx = 0;        // Which bit to store in byte 
54
    //static uint8_t byte = 0;            // The current character being read
55
    //static uint8_t parity = 0;          // Current calculated parity
56
    //static uint8_t parity_error = 0;    // If we saw a parity error this read
57
    //static uint8_t start_sentinal = 0;  // Saw a start sentinal
58
    //static uint8_t stop_sentinal = 0;   // Saw a stop sentinal
59 53
    static uint8_t reading = 0;         // Currently reading
60 54

  
61
    //uint8_t rval;   // Current bit read in
62

  
63

  
64 55
    // Only read card if we are expecting it
65 56
    if (!read_card) {
66 57
        return;
......
68 59

  
69 60
    // Check if the card is inserted or not
70 61
    if (!(PIND & CR_CL) && (reading == 0)) {
71
        //byte_idx = 0;
72
        //byte = 0;
73
        //parity_error = 0;
74

  
75 62
        cr_flag = CR_NONE;
76 63
        cr_buf_idx = 0;
77

  
78
        //start_sentinal = 0;
79
        //stop_sentinal = 0;
80 64
        reading = 1;
65
    // check if the card has finished swiping
81 66
    } else if (PIND & CR_CL) {
82 67
        toggle_led(LED_RED, ON);
83 68
        reading = 0;
84

  
85
        //if ((stop_sentinal == 1) && (parity_error == 0)) {
86
            cr_flag = CR_GOOD;
87
        //} else {
88
        //    cr_flag = CR_BAD;
89
        //}
69
        cr_flag = CR_GOOD;
90 70
        return;
91 71
    }
92 72

  
93 73
    // Read data in on the downtick of the clock
94 74
    if (!(PIND & (CR_CLK))) {
95 75
        // Read data from card reader and flip since ours inverts
96
        //rval = (PIND & CR_DATA) ? 0 : 0x40;
97
        //cr_buf[cr_buf_idx] = (rval == 0) ? '0' : '1';
98 76
        cr_buf[cr_buf_idx] = (PIND & CR_DATA) ? 0 : 0x20;
99 77
        cr_buf_idx++;
100 78
    }
......
102 80
void parse_card(void) {
103 81
    int32_t i = cr_buf_idx - 1;
104 82
    uint8_t start_sentinal = 0;
105
    uint8_t stop_sentinal = 0;
106 83
    uint8_t byte_idx = 0;
107 84
    uint8_t byte = 0;
108 85
    uint8_t parity;
......
120 97
            // Skip parity bit
121 98
            i--;
122 99
        }
123
            i--;
124
        
100

  
101
        i--;
125 102
    }
126 103

  
127 104
    byte = 0;
......
151 128
        } else {
152 129
            byte = (((byte >> 1) & 0x1F) | (cr_buf[i]));
153 130
            byte_idx++;
154
            parity += (cr_buf[i] == 0) ? 0 : 1;
131
            parity += (cr_buf[i]) ? 0 : 1;
155 132
        }
156 133

  
157 134
        // Goto next bit in cr_buf

Also available in: Unified diff