test
RN42.cpp
- Committer:
- trisjph
- Date:
- 2013-12-16
- Revision:
- 0:30f62fde3cf4
File content as of revision 0:30f62fde3cf4:
#include "RN42.h" //#include "C12832_lcd.h" //Serial pc2(USBTX, USBRX); Serial RN42(PTD3,PTD2); DigitalOut RN42_reset_pin(PTC2); Serial pc2(USBTX, USBRX); //C12832_LCD lcd2; short RN42_init(void) { RN42.baud(115200); pc2.baud(115200); //lcd2.printf("starting reset"); return RN42_reset(); } short RN42_reset(void) { char buff[3]; short i=0; RN42_reset_pin = 0; wait_ms(500); RN42_reset_pin = 1; wait(2); //lcd2.printf("checking reset"); RN42.printf("$$$"); for(i=0; i<3; i++) { buff[i] = RN42.getc(); } // pc2.printf("buffer = %s\n",buff); if((buff[0] == 67) && (buff[1] == 77) && (buff[2] == 68)) { RN42.printf("---\n"); while(RN42.getc() != 68); while(RN42.getc() != 10); // lcd2.printf("reset successful"); return 1; } //lcd2.printf("reset failed..."); return 0; } short RN42_SPP(void) { char buff[3]; short i=0; if(RN42_reset()) { wait_ms(500); RN42.printf("$$$"); for(i=0; i<3; i++) { buff[i] = RN42.getc(); } //pc2.printf("buff = %c%c%c",buff[0],buff[1],buff[2]); if((buff[0] == 67) && (buff[1] == 77) && (buff[2] == 68)) { RN42.printf("S~,0\n"); while(RN42.getc() != 75); while(RN42.getc() != 10); RN42.printf("R,1\n"); while(RN42.getc() != 33); while(RN42.getc() != 10); wait_ms(500); return 1; } } return 0; } short RN42_HID(void) { char buff[3]; short i=0; if(RN42_reset()) { wait_ms(500); RN42.printf("$$$"); for(i=0; i<3; i++) { buff[i] = RN42.getc(); } //pc2.printf("buff = %c%c%c",buff[0],buff[1],buff[2]); if((buff[0] == 67) && (buff[1] == 77) && (buff[2] == 68)) { RN42.printf("S~,6\n"); while(RN42.getc() != 75); while(RN42.getc() != 10); RN42.printf("SH,0232\n"); while(RN42.getc() != 75); while(RN42.getc() != 10); RN42.printf("R,1\n"); while(RN42.getc() != 33); while(RN42.getc() != 10); wait_ms(500); /*RN42.printf("$$$"); for(i=0; i<3; i++) { buff[i] = RN42.getc(); } //pc2.printf("buff2 = %c%c%c",buff[0],buff[1],buff[2]); if((buff[0] == 67) && (buff[1] == 77) && (buff[2] == 68)) { RN42.printf("SH,0231\n"); while(RN42.getc() != 75); while(RN42.getc() != 10); RN42.printf("---\n"); while(RN42.getc() != 68); while(RN42.getc() != 10);*/ return 1; // } } } return 0; } short RN42_key(char key) { RN42.putc(key); return 1; } short RN42_mouse(signed char x,signed char y) { RN42.printf("%.2c%.2c%.2c%.2c%.2c%.2c%.2c", 0xFD, 0x5, 0x2, 0x00, x, y, 0x00); return 1; } short RN42_click(char l,char m,char r) { char temp; temp = (r << 2) | (l << 1) | m; //pc2.printf("temp val=%.2x\n",temp); RN42.printf("%.2c%.2c%.2c%.2c%.2c%.2c%.2c", 0xFD, 0x5, 0x2, temp, 0x00, 0x00, 0x00); return 1; } short RN42_specaial_key(char key) { RN42.printf("%.2c%.2c%.2c%.2c", 0xFE, 0x1, 0x0, key); pc2.printf("%.2x %.2x %.2x %.2x", 0xFE, 0x1, 0x0, key); wait_ms(500); RN42.printf("%.2c%.2c", 0xFE, 0x0);//0xfe return 1; } void RN42_connect(void) { char buff[3]; short i=0; pc2.printf("start\n"); RN42.printf("$$$"); for(i=0; i<3; i++) { buff[i] = RN42.getc(); } RN42.printf("C\n"); pc2.printf("searching\n"); wait(4); while(RN42.readable()) RN42.getc(); pc2.printf("initiate connection\n"); ///RN42.printf("CFI\n"); //wait(5); // RN42.printf("---\n"); //while(RN42.getc() != 68); //while(RN42.getc() != 10); //pc2.printf("exited cmd\n"); }