Tristan Hughes / RN42

Dependents:   Super_Hans_BT

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers RN42.cpp Source File

RN42.cpp

00001 #include "RN42.h"
00002 //#include "C12832_lcd.h"
00003 
00004 //Serial pc2(USBTX, USBRX);
00005 Serial RN42(PTD3,PTD2);
00006 DigitalOut RN42_reset_pin(PTC2);
00007 Serial pc2(USBTX, USBRX);
00008 //C12832_LCD lcd2;
00009 
00010 short RN42_init(void)
00011 {
00012     RN42.baud(115200);
00013     pc2.baud(115200);
00014     //lcd2.printf("starting reset");
00015     return RN42_reset();
00016 
00017 }
00018 short RN42_reset(void)
00019 {
00020     char buff[3];
00021     short i=0;
00022 
00023     RN42_reset_pin = 0;
00024     wait_ms(500);
00025     RN42_reset_pin = 1;
00026     wait(2);
00027     //lcd2.printf("checking reset");
00028     RN42.printf("$$$");
00029     for(i=0; i<3; i++) {
00030         buff[i] = RN42.getc();
00031     }
00032    // pc2.printf("buffer = %s\n",buff);
00033     if((buff[0] == 67) && (buff[1] == 77) && (buff[2] == 68)) {
00034         RN42.printf("---\n");
00035         while(RN42.getc() != 68);
00036         while(RN42.getc() != 10);
00037        // lcd2.printf("reset successful");
00038         return 1;
00039     }
00040 
00041     //lcd2.printf("reset failed...");
00042     return 0;
00043 }
00044 short RN42_SPP(void)
00045 {
00046     char buff[3];
00047     short i=0;
00048 
00049     if(RN42_reset()) {
00050         wait_ms(500);
00051         RN42.printf("$$$");
00052         for(i=0; i<3; i++) {
00053             buff[i] = RN42.getc();
00054         }
00055         //pc2.printf("buff = %c%c%c",buff[0],buff[1],buff[2]);
00056         if((buff[0] == 67) && (buff[1] == 77) && (buff[2] == 68)) {
00057             RN42.printf("S~,0\n");
00058             while(RN42.getc() != 75);
00059             while(RN42.getc() != 10);
00060             RN42.printf("R,1\n");
00061             while(RN42.getc() != 33);
00062             while(RN42.getc() != 10);
00063             wait_ms(500);
00064             return 1;
00065         }
00066 
00067     }
00068     return 0;
00069 }
00070 short RN42_HID(void)
00071 {
00072     char buff[3];
00073     short i=0;
00074 
00075     if(RN42_reset()) {
00076         wait_ms(500);
00077         RN42.printf("$$$");
00078         for(i=0; i<3; i++) {
00079             buff[i] = RN42.getc();
00080         }
00081         //pc2.printf("buff = %c%c%c",buff[0],buff[1],buff[2]);
00082         if((buff[0] == 67) && (buff[1] == 77) && (buff[2] == 68)) {
00083             RN42.printf("S~,6\n");
00084             while(RN42.getc() != 75);
00085             while(RN42.getc() != 10);
00086             RN42.printf("SH,0232\n");
00087             while(RN42.getc() != 75);
00088             while(RN42.getc() != 10);
00089             RN42.printf("R,1\n");
00090             while(RN42.getc() != 33);
00091             while(RN42.getc() != 10);
00092             wait_ms(500);
00093 
00094             /*RN42.printf("$$$");
00095             for(i=0; i<3; i++) {
00096                 buff[i] = RN42.getc();
00097             }
00098             //pc2.printf("buff2 = %c%c%c",buff[0],buff[1],buff[2]);
00099             if((buff[0] == 67) && (buff[1] == 77) && (buff[2] == 68)) {
00100                 RN42.printf("SH,0231\n");
00101                 while(RN42.getc() != 75);
00102                 while(RN42.getc() != 10);
00103                 RN42.printf("---\n");
00104                 while(RN42.getc() != 68);
00105                 while(RN42.getc() != 10);*/
00106             return 1;
00107             // }
00108         }
00109 
00110     }
00111     return 0;
00112 }
00113 short RN42_key(char key)
00114 {
00115     RN42.putc(key);
00116     return 1;
00117 }
00118 short RN42_mouse(signed char x,signed char y)
00119 {
00120 
00121     RN42.printf("%.2c%.2c%.2c%.2c%.2c%.2c%.2c", 0xFD, 0x5, 0x2, 0x00, x, y, 0x00);
00122     return 1;
00123 }
00124 short RN42_click(char l,char m,char r)
00125 {
00126     char temp;
00127 
00128     temp = (r << 2) | (l << 1) | m;
00129     //pc2.printf("temp val=%.2x\n",temp);
00130     RN42.printf("%.2c%.2c%.2c%.2c%.2c%.2c%.2c", 0xFD, 0x5, 0x2, temp, 0x00, 0x00, 0x00);
00131     
00132     return 1;
00133 }
00134 short RN42_specaial_key(char key)
00135 {
00136     RN42.printf("%.2c%.2c%.2c%.2c", 0xFE, 0x1, 0x0, key);
00137     pc2.printf("%.2x %.2x %.2x %.2x", 0xFE, 0x1, 0x0, key);
00138     wait_ms(500);
00139     RN42.printf("%.2c%.2c", 0xFE, 0x0);//0xfe
00140     return 1;
00141 }
00142 
00143 void RN42_connect(void)
00144 {
00145     char buff[3];
00146     short i=0;
00147      pc2.printf("start\n");
00148         RN42.printf("$$$");
00149         for(i=0; i<3; i++) {
00150             buff[i] = RN42.getc();
00151         }
00152         RN42.printf("C\n");
00153          pc2.printf("searching\n");
00154         wait(4);
00155         while(RN42.readable())
00156         RN42.getc();
00157         
00158         pc2.printf("initiate connection\n");
00159         
00160         ///RN42.printf("CFI\n");
00161         //wait(5);
00162        // RN42.printf("---\n");        
00163         //while(RN42.getc() != 68);
00164         //while(RN42.getc() != 10);
00165         //pc2.printf("exited cmd\n");
00166 }