test

Dependents:   Super_Hans_BT

Files at this revision

API Documentation at this revision

Comitter:
trisjph
Date:
Mon Dec 16 10:26:09 2013 +0000
Commit message:
intial;

Changed in this revision

RN42.cpp Show annotated file Show diff for this revision Revisions of this file
RN42.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RN42.cpp	Mon Dec 16 10:26:09 2013 +0000
@@ -0,0 +1,166 @@
+#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");
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RN42.h	Mon Dec 16 10:26:09 2013 +0000
@@ -0,0 +1,53 @@
+#include "mbed.h"
+
+short RN42_init(void);
+short RN42_reset(void);
+short RN42_SPP(void);
+short RN42_HID(void);
+short RN42_key(char key);
+short RN42_mouse(signed char x,signed char y);
+short RN42_click(char l,char r,char m);
+short RN42_specaial_key(char key);
+void RN42_connect(void);
+
+#define INSERT_KEY 0x49
+#define HOME_KEY 0x4A
+#define PAGE_UP_KEY 0x4B
+#define DELETE_KEY 0x4C
+#define END_KEY 0x4D
+#define PAGE_DOWN_KEY 0x4E
+#define RIGHT_ARROW_KEY 0x07
+#define BACKSPACE_KEY 0x2A
+#define TAB_KEY 0x2B
+#define ENTER_KEY 0x28
+#define LEFT_ARROW_KEY 0x0B
+#define DOWN_ARROW_KEY 0x0C
+#define UP_ARROW_KEY 0x0E
+#define F1_KEY 0x3A
+#define F2_KEY 0x3B
+#define F3_KEY 0x3C
+#define F4_KEY 0x3D
+#define F5_KEY 0x3E
+#define F6_KEY 0x3F
+#define F7_KEY 0x40
+#define F8_KEY 0x41
+#define F9_KEY 0x42
+#define F10_KEY 0x43
+#define F11_KEY 0x44
+#define F12_KEY 0x45
+#define ESCAPE_KEY 0x29
+#define CAPS_LOCK_KEY 0x39
+#define SCROLL_LOCK_KEY 0x47
+#define BREAK_PAUSE_KEY 0x48
+#define NUM_LOCK_KEY 0x53
+#define LEFT_CTRL_KEY 0xE0
+#define LEFT_SHIFT_KEY 0xE1
+#define LEFT_ALT_KEY 0xE2
+#define RIGHT_CTRL_KEY 0xE4
+#define RIGHT_SHIFT_KEY 0xE5
+#define RIGHT_ALT_KEY 0xE6
+
+
+
+
+