yoshinari kou
/
WW_SD_send_IRVer2
Send IR data from SD card. I changed Chip Select signal timing.
main.cpp@1:372b09a39fa4, 2011-09-01 (annotated)
- Committer:
- halfpitch
- Date:
- Thu Sep 01 09:45:40 2011 +0000
- Revision:
- 1:372b09a39fa4
- Parent:
- 0:da2f4475a464
Rev.B
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
halfpitch | 0:da2f4475a464 | 1 | ////////////////////////////////////// |
halfpitch | 0:da2f4475a464 | 2 | // White Wizard Board (PAT.PEND) // |
halfpitch | 0:da2f4475a464 | 3 | // Send IR data from microSD card. // |
halfpitch | 0:da2f4475a464 | 4 | // // |
halfpitch | 0:da2f4475a464 | 5 | // Nest Egg Inc. 2011/7/9 // |
halfpitch | 0:da2f4475a464 | 6 | // // |
halfpitch | 0:da2f4475a464 | 7 | ////////////////////////////////////// |
halfpitch | 0:da2f4475a464 | 8 | #include "mbed.h" |
halfpitch | 0:da2f4475a464 | 9 | #include "SDFileSystem.h" |
halfpitch | 0:da2f4475a464 | 10 | |
halfpitch | 0:da2f4475a464 | 11 | #define SDch 0x05 |
halfpitch | 1:372b09a39fa4 | 12 | #define MAXdatanum 1000 |
halfpitch | 0:da2f4475a464 | 13 | #define TimeLimit 3000 |
halfpitch | 0:da2f4475a464 | 14 | #define pul38khz 26 |
halfpitch | 0:da2f4475a464 | 15 | #define pul38k_ON 13 |
halfpitch | 0:da2f4475a464 | 16 | #define pul38k_OFF 26 |
halfpitch | 0:da2f4475a464 | 17 | |
halfpitch | 0:da2f4475a464 | 18 | //for ifdef |
halfpitch | 0:da2f4475a464 | 19 | //#define TEST 1 |
halfpitch | 0:da2f4475a464 | 20 | //#define SEND 1 |
halfpitch | 0:da2f4475a464 | 21 | //#define SAVE 1 |
halfpitch | 0:da2f4475a464 | 22 | |
halfpitch | 0:da2f4475a464 | 23 | //prototype |
halfpitch | 0:da2f4475a464 | 24 | void send_pulse(int, int); |
halfpitch | 0:da2f4475a464 | 25 | |
halfpitch | 0:da2f4475a464 | 26 | SDFileSystem sd(p5, p6, p7, p8, "sd"); |
halfpitch | 0:da2f4475a464 | 27 | |
halfpitch | 0:da2f4475a464 | 28 | DigitalOut myled1(LED1); |
halfpitch | 0:da2f4475a464 | 29 | DigitalOut myled2(LED2); |
halfpitch | 0:da2f4475a464 | 30 | DigitalOut myled3(LED3); |
halfpitch | 0:da2f4475a464 | 31 | DigitalOut myled4(LED4); |
halfpitch | 0:da2f4475a464 | 32 | |
halfpitch | 0:da2f4475a464 | 33 | PwmOut Pulse_pin(p25); |
halfpitch | 0:da2f4475a464 | 34 | |
halfpitch | 0:da2f4475a464 | 35 | int trigger = 0; |
halfpitch | 0:da2f4475a464 | 36 | int saved = 0; |
halfpitch | 0:da2f4475a464 | 37 | |
halfpitch | 0:da2f4475a464 | 38 | int main(){ |
halfpitch | 0:da2f4475a464 | 39 | int IRdata[MAXdatanum]; |
halfpitch | 0:da2f4475a464 | 40 | int pulsetime[MAXdatanum]; |
halfpitch | 0:da2f4475a464 | 41 | int j = 0; |
halfpitch | 0:da2f4475a464 | 42 | int datanum = 0; |
halfpitch | 0:da2f4475a464 | 43 | |
halfpitch | 0:da2f4475a464 | 44 | myled1 = 0; |
halfpitch | 0:da2f4475a464 | 45 | myled2 = 0; |
halfpitch | 0:da2f4475a464 | 46 | myled3 = 0; |
halfpitch | 0:da2f4475a464 | 47 | myled4 = 0; |
halfpitch | 0:da2f4475a464 | 48 | |
halfpitch | 0:da2f4475a464 | 49 | myled1 = 1; |
halfpitch | 0:da2f4475a464 | 50 | |
halfpitch | 0:da2f4475a464 | 51 | sd.SetCh(SDch); //channel No 0101(=0x05), depend on your SPI module setting. (1:High 0:Low) |
halfpitch | 0:da2f4475a464 | 52 | printf("again\n"); |
halfpitch | 0:da2f4475a464 | 53 | int pHL = 0; |
halfpitch | 0:da2f4475a464 | 54 | int t = 0; |
halfpitch | 1:372b09a39fa4 | 55 | FILE *fp1 = fopen("/sd/IRDATA.csv", "r"); |
halfpitch | 1:372b09a39fa4 | 56 | //FILE *fp1 = fopen("/sd/off.csv", "r"); |
halfpitch | 0:da2f4475a464 | 57 | |
halfpitch | 0:da2f4475a464 | 58 | datanum = 0; |
halfpitch | 0:da2f4475a464 | 59 | |
halfpitch | 0:da2f4475a464 | 60 | fscanf(fp1, "%d\n",&datanum); //read from SD |
halfpitch | 0:da2f4475a464 | 61 | printf("datanum, %d\n",datanum); |
halfpitch | 0:da2f4475a464 | 62 | myled2 = 1; |
halfpitch | 0:da2f4475a464 | 63 | |
halfpitch | 0:da2f4475a464 | 64 | Pulse_pin.period_us(pul38khz); |
halfpitch | 0:da2f4475a464 | 65 | |
halfpitch | 1:372b09a39fa4 | 66 | j=0; |
halfpitch | 0:da2f4475a464 | 67 | for(j=0;j<datanum;++j){ |
halfpitch | 1:372b09a39fa4 | 68 | fscanf(fp1, "%d,%d,\n",&pHL, &t); |
halfpitch | 1:372b09a39fa4 | 69 | //printf("%d : %d,%d,\n",j,pHL, t); |
halfpitch | 0:da2f4475a464 | 70 | IRdata[j] = pHL; |
halfpitch | 0:da2f4475a464 | 71 | pulsetime[j] = t; |
halfpitch | 0:da2f4475a464 | 72 | } |
halfpitch | 0:da2f4475a464 | 73 | |
halfpitch | 0:da2f4475a464 | 74 | myled3 = 1; |
halfpitch | 0:da2f4475a464 | 75 | |
halfpitch | 0:da2f4475a464 | 76 | for(j=0;j<datanum;++j){ |
halfpitch | 0:da2f4475a464 | 77 | send_pulse(IRdata[j],pulsetime[j]); |
halfpitch | 0:da2f4475a464 | 78 | } |
halfpitch | 0:da2f4475a464 | 79 | |
halfpitch | 0:da2f4475a464 | 80 | Pulse_pin.pulsewidth(pul38k_OFF); |
halfpitch | 0:da2f4475a464 | 81 | fclose(fp1); |
halfpitch | 0:da2f4475a464 | 82 | myled4 = 1; |
halfpitch | 0:da2f4475a464 | 83 | printf("close fp1\n"); |
halfpitch | 0:da2f4475a464 | 84 | } |
halfpitch | 0:da2f4475a464 | 85 | |
halfpitch | 0:da2f4475a464 | 86 | |
halfpitch | 0:da2f4475a464 | 87 | void send_pulse(int pHL, int t){ |
halfpitch | 0:da2f4475a464 | 88 | |
halfpitch | 0:da2f4475a464 | 89 | int k = 0; |
halfpitch | 0:da2f4475a464 | 90 | |
halfpitch | 0:da2f4475a464 | 91 | if(pHL == 0){ |
halfpitch | 0:da2f4475a464 | 92 | //38kHz pulse on |
halfpitch | 0:da2f4475a464 | 93 | Pulse_pin.pulsewidth_us(pul38k_ON); |
halfpitch | 0:da2f4475a464 | 94 | |
halfpitch | 0:da2f4475a464 | 95 | }else if(pHL == 1){ |
halfpitch | 0:da2f4475a464 | 96 | //38kHz pulse off |
halfpitch | 0:da2f4475a464 | 97 | Pulse_pin.pulsewidth(pul38k_OFF); |
halfpitch | 0:da2f4475a464 | 98 | |
halfpitch | 0:da2f4475a464 | 99 | }else{ |
halfpitch | 0:da2f4475a464 | 100 | Pulse_pin.pulsewidth(pul38k_OFF); |
halfpitch | 0:da2f4475a464 | 101 | printf("\n\n-----Data format is incorrect!!-----\n pHL = %d, t = %d \n", pHL, t); |
halfpitch | 0:da2f4475a464 | 102 | |
halfpitch | 0:da2f4475a464 | 103 | } |
halfpitch | 0:da2f4475a464 | 104 | for(k = 0; k < t; ++k){ |
halfpitch | 0:da2f4475a464 | 105 | wait_us(50); |
halfpitch | 0:da2f4475a464 | 106 | } |
halfpitch | 0:da2f4475a464 | 107 | } |
halfpitch | 0:da2f4475a464 | 108 |