test

Dependents:   Super_Hans_BT

Committer:
trisjph
Date:
Mon Dec 16 10:26:09 2013 +0000
Revision:
0:30f62fde3cf4
intial;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
trisjph 0:30f62fde3cf4 1 #include "RN42.h"
trisjph 0:30f62fde3cf4 2 //#include "C12832_lcd.h"
trisjph 0:30f62fde3cf4 3
trisjph 0:30f62fde3cf4 4 //Serial pc2(USBTX, USBRX);
trisjph 0:30f62fde3cf4 5 Serial RN42(PTD3,PTD2);
trisjph 0:30f62fde3cf4 6 DigitalOut RN42_reset_pin(PTC2);
trisjph 0:30f62fde3cf4 7 Serial pc2(USBTX, USBRX);
trisjph 0:30f62fde3cf4 8 //C12832_LCD lcd2;
trisjph 0:30f62fde3cf4 9
trisjph 0:30f62fde3cf4 10 short RN42_init(void)
trisjph 0:30f62fde3cf4 11 {
trisjph 0:30f62fde3cf4 12 RN42.baud(115200);
trisjph 0:30f62fde3cf4 13 pc2.baud(115200);
trisjph 0:30f62fde3cf4 14 //lcd2.printf("starting reset");
trisjph 0:30f62fde3cf4 15 return RN42_reset();
trisjph 0:30f62fde3cf4 16
trisjph 0:30f62fde3cf4 17 }
trisjph 0:30f62fde3cf4 18 short RN42_reset(void)
trisjph 0:30f62fde3cf4 19 {
trisjph 0:30f62fde3cf4 20 char buff[3];
trisjph 0:30f62fde3cf4 21 short i=0;
trisjph 0:30f62fde3cf4 22
trisjph 0:30f62fde3cf4 23 RN42_reset_pin = 0;
trisjph 0:30f62fde3cf4 24 wait_ms(500);
trisjph 0:30f62fde3cf4 25 RN42_reset_pin = 1;
trisjph 0:30f62fde3cf4 26 wait(2);
trisjph 0:30f62fde3cf4 27 //lcd2.printf("checking reset");
trisjph 0:30f62fde3cf4 28 RN42.printf("$$$");
trisjph 0:30f62fde3cf4 29 for(i=0; i<3; i++) {
trisjph 0:30f62fde3cf4 30 buff[i] = RN42.getc();
trisjph 0:30f62fde3cf4 31 }
trisjph 0:30f62fde3cf4 32 // pc2.printf("buffer = %s\n",buff);
trisjph 0:30f62fde3cf4 33 if((buff[0] == 67) && (buff[1] == 77) && (buff[2] == 68)) {
trisjph 0:30f62fde3cf4 34 RN42.printf("---\n");
trisjph 0:30f62fde3cf4 35 while(RN42.getc() != 68);
trisjph 0:30f62fde3cf4 36 while(RN42.getc() != 10);
trisjph 0:30f62fde3cf4 37 // lcd2.printf("reset successful");
trisjph 0:30f62fde3cf4 38 return 1;
trisjph 0:30f62fde3cf4 39 }
trisjph 0:30f62fde3cf4 40
trisjph 0:30f62fde3cf4 41 //lcd2.printf("reset failed...");
trisjph 0:30f62fde3cf4 42 return 0;
trisjph 0:30f62fde3cf4 43 }
trisjph 0:30f62fde3cf4 44 short RN42_SPP(void)
trisjph 0:30f62fde3cf4 45 {
trisjph 0:30f62fde3cf4 46 char buff[3];
trisjph 0:30f62fde3cf4 47 short i=0;
trisjph 0:30f62fde3cf4 48
trisjph 0:30f62fde3cf4 49 if(RN42_reset()) {
trisjph 0:30f62fde3cf4 50 wait_ms(500);
trisjph 0:30f62fde3cf4 51 RN42.printf("$$$");
trisjph 0:30f62fde3cf4 52 for(i=0; i<3; i++) {
trisjph 0:30f62fde3cf4 53 buff[i] = RN42.getc();
trisjph 0:30f62fde3cf4 54 }
trisjph 0:30f62fde3cf4 55 //pc2.printf("buff = %c%c%c",buff[0],buff[1],buff[2]);
trisjph 0:30f62fde3cf4 56 if((buff[0] == 67) && (buff[1] == 77) && (buff[2] == 68)) {
trisjph 0:30f62fde3cf4 57 RN42.printf("S~,0\n");
trisjph 0:30f62fde3cf4 58 while(RN42.getc() != 75);
trisjph 0:30f62fde3cf4 59 while(RN42.getc() != 10);
trisjph 0:30f62fde3cf4 60 RN42.printf("R,1\n");
trisjph 0:30f62fde3cf4 61 while(RN42.getc() != 33);
trisjph 0:30f62fde3cf4 62 while(RN42.getc() != 10);
trisjph 0:30f62fde3cf4 63 wait_ms(500);
trisjph 0:30f62fde3cf4 64 return 1;
trisjph 0:30f62fde3cf4 65 }
trisjph 0:30f62fde3cf4 66
trisjph 0:30f62fde3cf4 67 }
trisjph 0:30f62fde3cf4 68 return 0;
trisjph 0:30f62fde3cf4 69 }
trisjph 0:30f62fde3cf4 70 short RN42_HID(void)
trisjph 0:30f62fde3cf4 71 {
trisjph 0:30f62fde3cf4 72 char buff[3];
trisjph 0:30f62fde3cf4 73 short i=0;
trisjph 0:30f62fde3cf4 74
trisjph 0:30f62fde3cf4 75 if(RN42_reset()) {
trisjph 0:30f62fde3cf4 76 wait_ms(500);
trisjph 0:30f62fde3cf4 77 RN42.printf("$$$");
trisjph 0:30f62fde3cf4 78 for(i=0; i<3; i++) {
trisjph 0:30f62fde3cf4 79 buff[i] = RN42.getc();
trisjph 0:30f62fde3cf4 80 }
trisjph 0:30f62fde3cf4 81 //pc2.printf("buff = %c%c%c",buff[0],buff[1],buff[2]);
trisjph 0:30f62fde3cf4 82 if((buff[0] == 67) && (buff[1] == 77) && (buff[2] == 68)) {
trisjph 0:30f62fde3cf4 83 RN42.printf("S~,6\n");
trisjph 0:30f62fde3cf4 84 while(RN42.getc() != 75);
trisjph 0:30f62fde3cf4 85 while(RN42.getc() != 10);
trisjph 0:30f62fde3cf4 86 RN42.printf("SH,0232\n");
trisjph 0:30f62fde3cf4 87 while(RN42.getc() != 75);
trisjph 0:30f62fde3cf4 88 while(RN42.getc() != 10);
trisjph 0:30f62fde3cf4 89 RN42.printf("R,1\n");
trisjph 0:30f62fde3cf4 90 while(RN42.getc() != 33);
trisjph 0:30f62fde3cf4 91 while(RN42.getc() != 10);
trisjph 0:30f62fde3cf4 92 wait_ms(500);
trisjph 0:30f62fde3cf4 93
trisjph 0:30f62fde3cf4 94 /*RN42.printf("$$$");
trisjph 0:30f62fde3cf4 95 for(i=0; i<3; i++) {
trisjph 0:30f62fde3cf4 96 buff[i] = RN42.getc();
trisjph 0:30f62fde3cf4 97 }
trisjph 0:30f62fde3cf4 98 //pc2.printf("buff2 = %c%c%c",buff[0],buff[1],buff[2]);
trisjph 0:30f62fde3cf4 99 if((buff[0] == 67) && (buff[1] == 77) && (buff[2] == 68)) {
trisjph 0:30f62fde3cf4 100 RN42.printf("SH,0231\n");
trisjph 0:30f62fde3cf4 101 while(RN42.getc() != 75);
trisjph 0:30f62fde3cf4 102 while(RN42.getc() != 10);
trisjph 0:30f62fde3cf4 103 RN42.printf("---\n");
trisjph 0:30f62fde3cf4 104 while(RN42.getc() != 68);
trisjph 0:30f62fde3cf4 105 while(RN42.getc() != 10);*/
trisjph 0:30f62fde3cf4 106 return 1;
trisjph 0:30f62fde3cf4 107 // }
trisjph 0:30f62fde3cf4 108 }
trisjph 0:30f62fde3cf4 109
trisjph 0:30f62fde3cf4 110 }
trisjph 0:30f62fde3cf4 111 return 0;
trisjph 0:30f62fde3cf4 112 }
trisjph 0:30f62fde3cf4 113 short RN42_key(char key)
trisjph 0:30f62fde3cf4 114 {
trisjph 0:30f62fde3cf4 115 RN42.putc(key);
trisjph 0:30f62fde3cf4 116 return 1;
trisjph 0:30f62fde3cf4 117 }
trisjph 0:30f62fde3cf4 118 short RN42_mouse(signed char x,signed char y)
trisjph 0:30f62fde3cf4 119 {
trisjph 0:30f62fde3cf4 120
trisjph 0:30f62fde3cf4 121 RN42.printf("%.2c%.2c%.2c%.2c%.2c%.2c%.2c", 0xFD, 0x5, 0x2, 0x00, x, y, 0x00);
trisjph 0:30f62fde3cf4 122 return 1;
trisjph 0:30f62fde3cf4 123 }
trisjph 0:30f62fde3cf4 124 short RN42_click(char l,char m,char r)
trisjph 0:30f62fde3cf4 125 {
trisjph 0:30f62fde3cf4 126 char temp;
trisjph 0:30f62fde3cf4 127
trisjph 0:30f62fde3cf4 128 temp = (r << 2) | (l << 1) | m;
trisjph 0:30f62fde3cf4 129 //pc2.printf("temp val=%.2x\n",temp);
trisjph 0:30f62fde3cf4 130 RN42.printf("%.2c%.2c%.2c%.2c%.2c%.2c%.2c", 0xFD, 0x5, 0x2, temp, 0x00, 0x00, 0x00);
trisjph 0:30f62fde3cf4 131
trisjph 0:30f62fde3cf4 132 return 1;
trisjph 0:30f62fde3cf4 133 }
trisjph 0:30f62fde3cf4 134 short RN42_specaial_key(char key)
trisjph 0:30f62fde3cf4 135 {
trisjph 0:30f62fde3cf4 136 RN42.printf("%.2c%.2c%.2c%.2c", 0xFE, 0x1, 0x0, key);
trisjph 0:30f62fde3cf4 137 pc2.printf("%.2x %.2x %.2x %.2x", 0xFE, 0x1, 0x0, key);
trisjph 0:30f62fde3cf4 138 wait_ms(500);
trisjph 0:30f62fde3cf4 139 RN42.printf("%.2c%.2c", 0xFE, 0x0);//0xfe
trisjph 0:30f62fde3cf4 140 return 1;
trisjph 0:30f62fde3cf4 141 }
trisjph 0:30f62fde3cf4 142
trisjph 0:30f62fde3cf4 143 void RN42_connect(void)
trisjph 0:30f62fde3cf4 144 {
trisjph 0:30f62fde3cf4 145 char buff[3];
trisjph 0:30f62fde3cf4 146 short i=0;
trisjph 0:30f62fde3cf4 147 pc2.printf("start\n");
trisjph 0:30f62fde3cf4 148 RN42.printf("$$$");
trisjph 0:30f62fde3cf4 149 for(i=0; i<3; i++) {
trisjph 0:30f62fde3cf4 150 buff[i] = RN42.getc();
trisjph 0:30f62fde3cf4 151 }
trisjph 0:30f62fde3cf4 152 RN42.printf("C\n");
trisjph 0:30f62fde3cf4 153 pc2.printf("searching\n");
trisjph 0:30f62fde3cf4 154 wait(4);
trisjph 0:30f62fde3cf4 155 while(RN42.readable())
trisjph 0:30f62fde3cf4 156 RN42.getc();
trisjph 0:30f62fde3cf4 157
trisjph 0:30f62fde3cf4 158 pc2.printf("initiate connection\n");
trisjph 0:30f62fde3cf4 159
trisjph 0:30f62fde3cf4 160 ///RN42.printf("CFI\n");
trisjph 0:30f62fde3cf4 161 //wait(5);
trisjph 0:30f62fde3cf4 162 // RN42.printf("---\n");
trisjph 0:30f62fde3cf4 163 //while(RN42.getc() != 68);
trisjph 0:30f62fde3cf4 164 //while(RN42.getc() != 10);
trisjph 0:30f62fde3cf4 165 //pc2.printf("exited cmd\n");
trisjph 0:30f62fde3cf4 166 }