Joystick for SLVM

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
jnagendran3
Date:
Tue Dec 09 01:23:36 2014 +0000
Commit message:
first

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
xbee_lib/xbee.cpp Show annotated file Show diff for this revision Revisions of this file
xbee_lib/xbee.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Dec 09 01:23:36 2014 +0000
@@ -0,0 +1,30 @@
+#include "mbed.h"
+#include "xbee.h"
+
+//Sender code
+
+AnalogIn JS1x(p19);
+AnalogIn JS2x(p20);
+xbee xbee1(p9,p10,p11); //Initalise xbee_lib
+Serial Sender(p9,p10);
+int main()
+{
+    char x1, x2, x3, rr=0x00;
+    while(1) 
+    {             
+
+        if(JS1x<.25) x1= 0x0C;
+        else if(JS1x>.75) x1= 0x03;
+        else x1= 0x00;
+
+        if(JS2x>.75) x2= 0x0C;
+        else if(JS2x<.25) x2= 0x03;
+        else x2= 0x00;
+
+        x3=(x1<<4)|x2;
+        if (x3!=rr)Sender.putc(x3); //just says to only send new commands, can remove if you want
+        rr=x3;
+        
+    }
+}
+    
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Dec 09 01:23:36 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/031413cf7a89
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xbee_lib/xbee.cpp	Tue Dec 09 01:23:36 2014 +0000
@@ -0,0 +1,144 @@
+/* Copyright (c) 2012 Tristan Hughes, MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
+ * and associated documentation files (the "Software"), to deal in the Software without restriction, 
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or 
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+ 
+ #include "xbee.h"
+
+
+xbee::xbee(PinName tx, PinName rx, PinName reset)
+{
+    _tx = tx;
+    _rx = rx;
+    _reset = reset;
+}
+
+xbee::~xbee()
+{
+}
+
+int xbee::ConfigMode()
+{
+    int a;
+    Serial DATA(_tx,_rx);
+    wait(2);
+    DATA.printf("+++");
+    while (a != 75) {
+        if (DATA.readable()) {
+            a = DATA.getc();
+        }
+    }
+    wait(1);
+    printf("config mode\n");
+    return 1;
+}
+
+int xbee::GetSerial(int *serial_no)
+{
+    int sh1,sh2,sh3,sl1,sl2,sl3,sl4;
+    Serial DATA(_tx,_rx);
+    wait_ms(50);
+    DATA.printf("ATSL \r");
+    DATA.scanf ("%2x%2x%2x%2x",&sl1,&sl2,&sl3,&sl4);
+    wait_ms(500);
+    DATA.printf("ATSH \r");
+    DATA.scanf ("%2x%2x%2x",&sh1,&sh2,&sh3);
+
+    serial_no[0] = sh1;
+    serial_no[1] = sh2;
+    serial_no[2] = sh3;
+    serial_no[3] = sl1;
+    serial_no[4] = sl2;
+    serial_no[5] = sl3;
+    serial_no[6] = sl4;
+
+    return 1;
+}
+
+int xbee::SetKey(int* key)
+{
+    Serial DATA(_tx,_rx);
+    DATA.printf("ATEE 1 \r");
+
+    DATA.scanf ("%*s");
+    wait_ms(1);
+    DATA.printf("ATKY %x \r",key);
+    DATA.scanf ("%*s");
+    return 1;
+}
+
+int xbee::WriteSettings()
+{
+    Serial DATA(_tx,_rx);
+    wait_ms(5);
+    DATA.printf("ATWR \r");
+    DATA.scanf ("%*s");
+    return 1;
+}
+
+int xbee::ExitConfigMode()
+{
+    Serial DATA(_tx,_rx);
+    wait_ms(5);
+    DATA.printf("ATCN \r");
+    DATA.scanf ("%*s");
+    return 1;
+}
+
+int xbee::SendData(char *data_buf)
+{
+    Serial DATA(_tx,_rx);
+    DATA.printf("%s",data_buf);
+    return 1;
+}
+
+void xbee::RecieveData(char *data_buf, int numchar)
+{
+    int count=0;
+    if(numchar == 0) {
+        numchar = sizeof(data_buf);
+    }
+    Serial DATA(_tx,_rx);
+    while(numchar!=count) {
+        if(DATA.readable()) {
+            *data_buf = DATA.getc();
+            data_buf+=1;
+            count++;
+        }
+
+    }
+}
+
+int xbee::SetPanId(int pan_id)
+{
+    Serial DATA(_tx,_rx);
+    wait_ms(5);
+    DATA.printf("ATID %i\r",pan_id);
+    DATA.scanf ("%*s");
+    return 1;
+}
+
+void xbee::Reset()
+{
+    DigitalOut rssi(_reset);
+    rssi = 0;
+    wait_ms(10);
+    rssi = 1;
+    wait_ms(1);
+}
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xbee_lib/xbee.h	Tue Dec 09 01:23:36 2014 +0000
@@ -0,0 +1,77 @@
+/* Copyright (c) 2012 Tristan Hughes, MIT License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
+ * and associated documentation files (the "Software"), to deal in the Software without restriction, 
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or 
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#include "mbed.h"
+
+/** Xbee interface class for configuring, sending and recieving data using an Xbee */
+class xbee
+{
+private:
+    PinName _tx;
+    PinName _rx;
+    PinName _reset;
+public:
+    /** Configure serial data pin.
+      * @param tx The serial tx pin the xbee is conected to.
+      * @param rx The serial rx pin the xbee is conected to.
+      * @param reset The pin connected to the Xbee reset pin.
+      */
+    xbee(PinName tx, PinName rx, PinName reset);
+    ~xbee();
+    /** Puts the Xbee into config mode.
+      * @return Returns 1 on success.
+      */
+    int ConfigMode();
+    /** Gets the serial number/mac address of the Xbee and places it into serial_no.
+      * @param serial_no array to store the serial of Xbee (must be 8 long).
+      * @return Returns 1 on success.
+      */
+    int GetSerial(int*);
+    /** Sets the encryption key to the one stored in security_key.
+      * @param key Pointer to the network key to set.
+      * @return Returns 1 on success.
+      */
+    int SetKey(int*);
+    /** Sets the id of the PAN network for the Xbee to use
+      * @param pan_id The id of the PAN for the Xbee to use.
+      * @return Returns 1 on success.
+      */
+    int SetPanId(int);
+    /** Writes the settings to the Non volatile memory on the Xbee
+      * @param key Pointer to the network key to set.
+      * @return Returns 1 on success.
+      */
+    int WriteSettings();
+    /** Exits config mode
+      * @return Returns 1 on success.
+      */
+    int ExitConfigMode();
+    /** Sends data in the send_Data buffer.
+      * @param data_buf Pointer to the buffer of data to send.
+      * @returns 1 on success.
+      */
+    int SendData(char*);
+    /** Recieves data sent to the xbee.
+      * @param data_buf Pointer to the buffer to put recieved data into.
+      * @param numchar Number of characters to read. If 0, will use the size of data_buf.
+      */
+    void RecieveData(char*, int);
+        /** Resets the Xbee.
+      */
+    void Reset();
+
+};