-
-
-// samy's sniff and repeat routine
-void SamyRun()
-{
- DbpString("Stand-alone mode! No PC necessary.");
-
- // 3 possible options? no just 2 for now
-#define OPTS 2
-
- int high[OPTS], low[OPTS];
-
- // Oooh pretty -- notify user we're in elite samy mode now
- LED(LED_RED, 200);
- LED(LED_ORANGE, 200);
- LED(LED_GREEN, 200);
- LED(LED_ORANGE, 200);
- LED(LED_RED, 200);
- LED(LED_ORANGE, 200);
- LED(LED_GREEN, 200);
- LED(LED_ORANGE, 200);
- LED(LED_RED, 200);
-
- int selected = 0;
- int playing = 0;
-
- // Turn on selected LED
- LED(selected + 1, 0);
-
- for (;;)
- {
- usbattached = UsbPoll(FALSE);
- WDT_HIT();
-
- // Was our button held down or pressed?
- int button_pressed = BUTTON_HELD(1000);
- SpinDelay(300);
-
- // Button was held for a second, begin recording
- if (button_pressed > 0)
- {
- LEDsoff();
- LED(selected + 1, 0);
- LED(LED_RED2, 0);
-
- // record
- DbpString("Starting recording");
-
- // wait for button to be released
- while(BUTTON_PRESS())
- WDT_HIT();
-
- /* need this delay to prevent catching some weird data */
- SpinDelay(500);
-
- CmdHIDdemodFSK(1, &high[selected], &low[selected], 0);
- DbpString("Recorded");
- DbpIntegers(selected, high[selected], low[selected]);
-
- LEDsoff();
- LED(selected + 1, 0);
- // Finished recording
-
- // If we were previously playing, set playing off
- // so next button push begins playing what we recorded
- playing = 0;
- }
-
- // Change where to record (or begin playing)
- else if (button_pressed)
- {
- // Next option if we were previously playing
- if (playing)
- selected = (selected + 1) % OPTS;
- playing = !playing;
-
- LEDsoff();
- LED(selected + 1, 0);
-
- // Begin transmitting
- if (playing)
- {
- LED(LED_GREEN, 0);
- DbpString("Playing");
- // wait for button to be released
- while(BUTTON_PRESS())
- WDT_HIT();
- DbpIntegers(selected, high[selected], low[selected]);
- CmdHIDsimTAG(high[selected], low[selected], 0);
- DbpString("Done playing");
- if (BUTTON_HELD(1000) > 0)
- {
- DbpString("Exiting");
- LEDsoff();
- return;
- }
-
- /* We pressed a button so ignore it here with a delay */
- SpinDelay(300);
-
- // when done, we're done playing, move to next option
- selected = (selected + 1) % OPTS;
- playing = !playing;
- LEDsoff();
- LED(selected + 1, 0);
- }
- else
- while(BUTTON_PRESS())
- WDT_HIT();
- }
- }
-}
-
-
-/* \r
-OBJECTIVE\r
-Listen and detect an external reader. Determine the best location\r
-for the antenna.\r
-\r
-INSTRUCTIONS:\r
-Inside the ListenReaderField() function, there is two mode. \r
-By default, when you call the function, you will enter mode 1.\r
-If you press the PM3 button one time, you will enter mode 2.\r
-If you press the PM3 button a second time, you will exit the function.\r
-\r
-DESCRIPTION OF MODE 1:\r
-This mode just listens for an external reader field and lights up green \r
-for HF and/or red for LF. This is the original mode of the detectreader\r
-function.\r
-\r
-DESCRIPTION OF MODE 2:\r
-This mode will visually represent, using the LEDs, the actual strength of the\r
-current compared to the maximum current detected. Basically, once you know \r
-what kind of external reader is present, it will help you spot the best location to place\r
-your antenna. You will probably not get some good results if there is a LF and a HF reader\r
-at the same place! :-)\r
-\r
-LIGHT SCHEME USED:\r
-\r
-Light scheme | Descriptiong\r
-----------------------------------------------------\r
- ---- | No field detected\r
- X--- | 14% of maximum current detected\r
- -X-- | 29% of maximum current detected\r
- --X- | 43% of maximum current detected\r
- ---X | 57% of maximum current detected\r
- --XX | 71% of maximum current detected\r
- -XXX | 86% of maximum current detected\r
- XXXX | 100% of maximum current detected\r
-\r
-TODO:\r
-Add the LF part for MODE 2\r
-\r
-*/\r
-void ListenReaderField(int limit)\r
-{\r
- int lf_av, lf_av_new, lf_baseline= 0, lf_count= 0;\r
- int hf_av, hf_av_new, hf_baseline= 0, hf_count= 0, hf_max;\r
- int mode=1;\r
-\r
-#define LF_ONLY 1\r
-#define HF_ONLY 2\r
-\r
- LED_A_OFF();\r
- LED_B_OFF();\r
- LED_C_OFF();\r
- LED_D_OFF();\r
-\r
- lf_av= ReadAdc(ADC_CHAN_LF);\r
-\r
- if(limit != HF_ONLY) \r
- {\r
- DbpString("LF 125/134 Baseline:");\r
- DbpIntegers(lf_av,0,0);\r
- lf_baseline= lf_av;\r
- }\r
-\r
- hf_av=hf_max=ReadAdc(ADC_CHAN_HF);\r
-\r
- if (limit != LF_ONLY) \r
- {\r
- DbpString("HF 13.56 Baseline:");\r
- DbpIntegers(hf_av,0,0);\r
- hf_baseline= hf_av;\r
- }\r
-\r
- for(;;) \r
- {\r
- if (BUTTON_PRESS()) {\r
- SpinDelay(500);\r
- switch (mode) {\r
- case 1:\r
- mode=2;\r
- DbpString("Signal Strength Mode");
- break;\r
- case 2:\r
- default:\r
- DbpString("Stopped");\r
- LED_A_OFF();\r
- LED_B_OFF();\r
- LED_C_OFF();\r
- LED_D_OFF();\r
- return;\r
- break;\r
- }\r
- }\r
- WDT_HIT();\r
-\r
- if (limit != HF_ONLY) \r
- {\r
- if (abs(lf_av - lf_baseline) > 10)\r
- LED_D_ON();\r
- else\r
- LED_D_OFF();\r
- ++lf_count;\r
- lf_av_new= ReadAdc(ADC_CHAN_LF);\r
- // see if there's a significant change\r
- if(abs(lf_av - lf_av_new) > 10) \r
- {\r
- DbpString("LF 125/134 Field Change:");\r
- DbpIntegers(lf_av,lf_av_new,lf_count);\r
- lf_av= lf_av_new;\r
- lf_count= 0;\r
- }\r
- }\r
-\r
- if (limit != LF_ONLY) \r
- {\r
- if (abs(hf_av - hf_baseline) > 10) {\r
- if (mode == 1)\r
- LED_B_ON();\r
- if (mode == 2) {\r
- if ( hf_av>(hf_max/7)*6) {\r
- LED_A_ON(); LED_B_ON(); LED_C_ON(); LED_D_ON();\r
- }\r
- if ( (hf_av>(hf_max/7)*5) && (hf_av<=(hf_max/7)*6) ) {\r
- LED_A_ON(); LED_B_ON(); LED_C_OFF(); LED_D_ON();\r
- }\r
- if ( (hf_av>(hf_max/7)*4) && (hf_av<=(hf_max/7)*5) ) {\r
- LED_A_OFF(); LED_B_ON(); LED_C_OFF(); LED_D_ON();\r
- }\r
- if ( (hf_av>(hf_max/7)*3) && (hf_av<=(hf_max/7)*4) ) {\r
- LED_A_OFF(); LED_B_OFF(); LED_C_OFF(); LED_D_ON();\r
- }\r
- if ( (hf_av>(hf_max/7)*2) && (hf_av<=(hf_max/7)*3) ) {\r
- LED_A_OFF(); LED_B_ON(); LED_C_OFF(); LED_D_OFF();\r
- }\r
- if ( (hf_av>(hf_max/7)*1) && (hf_av<=(hf_max/7)*2) ) {\r
- LED_A_ON(); LED_B_OFF(); LED_C_OFF(); LED_D_OFF();\r
- }\r
- if ( (hf_av>(hf_max/7)*0) && (hf_av<=(hf_max/7)*1) ) {\r
- LED_A_OFF(); LED_B_OFF(); LED_C_ON(); LED_D_OFF();\r
- }\r
- } \r
- } else {\r
- if (mode == 1) {\r
- LED_B_OFF();\r
- }\r
- if (mode == 2) {\r
- LED_A_OFF(); LED_B_OFF(); LED_C_OFF(); LED_D_OFF();\r
- }\r
- }\r
-\r
- ++hf_count;\r
- hf_av_new= ReadAdc(ADC_CHAN_HF);\r
- // see if there's a significant change\r
- if(abs(hf_av - hf_av_new) > 10) \r
- {\r
- DbpString("HF 13.56 Field Change:");\r
- DbpIntegers(hf_av,hf_av_new,hf_count);\r
- hf_av= hf_av_new;\r
- if (hf_av > hf_max)\r
- hf_max = hf_av;\r
- hf_count= 0;\r
- }\r
- }\r
- }\r
-}\r
-\r