-
- int GetT55x7Clock( const int * data, const size_t len, int peak ){
-
- int i,lastpeak,clock;
- clock = 0xFFFF;
- lastpeak = 0;
-
- /* Detect peak if we don't have one */
- if (!peak) {
- for (i = 0; i < len; ++i) {
- if (data[i] > peak) {
- peak = data[i];
- }
- }
- }
-
- for (i = 1; i < len; ++i) {
- /* if this is the beginning of a peak */
- if ( data[i-1] != data[i] && data[i] == peak) {
- /* find lowest difference between peaks */
- if (lastpeak && i - lastpeak < clock)
- clock = i - lastpeak;
- lastpeak = i;
- }
- }
- //return clock;
- //defaults clock to precise values.
- switch(clock){
- case 8:
- case 16:
- case 32:
- case 40:
- case 50:
- case 64:
- case 100:
- case 128:
- return clock;
- break;
- default: break;
- }
-
- //PrintAndLog(" Found Clock : %d - trying to adjust", clock);
-
- // When detected clock is 31 or 33 then then return
- int clockmod = clock%8;
- if ( clockmod == 7 )
- clock += 1;
- else if ( clockmod == 1 )
- clock -= 1;
-
- return clock;
- }