RaheeNew nonblocking
Dependencies: RaheeNew LinkedList mbed-rpc mbed-rtos mbed
Revision 0:3054baadfda9, committed 2015-11-28
- Comitter:
- jatinsha
- Date:
- Sat Nov 28 10:08:18 2015 +0000
- Commit message:
- js
Changed in this revision
diff -r 000000000000 -r 3054baadfda9 Adafruit9-DOf.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Adafruit9-DOf.lib Sat Nov 28 10:08:18 2015 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/jatinsha/code/RaheeNew/#c3381056a1c6
diff -r 000000000000 -r 3054baadfda9 LinkedList.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LinkedList.lib Sat Nov 28 10:08:18 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/sam_grove/code/LinkedList/#4ed66162aaa8
diff -r 000000000000 -r 3054baadfda9 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Nov 28 10:08:18 2015 +0000 @@ -0,0 +1,144 @@ +#include "mbed.h" +#include "rtos.h" +#include "mbed_rpc.h" +#include "string.h" +#define _MBED_ +#include "Adafruit_9DOF.h" +#include "Serial_base.h" + +Serial pc(USBTX, USBRX); // tx, rx +Serial bluetooth(p9, p10); // tx, rx +Ticker compassTicker; +float compassValue; +float *ax, *ay, *az, *mx, *my, *mz; + +DigitalOut led1(LED1), led2(LED2), led3(LED3); + +//Use the RPC enabled wrapped class - see RpcClasses.h for more info +RpcDigitalOut leftTop(p20,"leftTop"); +RpcDigitalOut leftBottom(p12,"leftBottom"); +RpcDigitalOut rightTop(p22,"rightTop"); +RpcDigitalOut rightBottom(p29,"rightBottom"); + +char buf[256], outbuf[256]; + +bool compassTriggered = false; +bool bluetoothTriggered = false; + + + + +/* Assign a unique ID to the sensors */ + +Adafruit_9DOF dof = Adafruit_9DOF(); +Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(30301); +Adafruit_LSM303_Mag_Unified mag = Adafruit_LSM303_Mag_Unified(30302); +/* Update this with the correct SLP for accurate altitude measurements */ +float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA; +/************************************************************************** + @brief Initialises all the sensors used by this example +**************************************************************************/ + +void initSensors(){ + if(!accel.begin()){ + /* There was a problem detecting the LSM303 ... check your connections */ + s_com->println(("Ooops, no LSM303 detected ... Check your wiring!")); + while(1); + } + + if(!mag.begin()){ + /* There was a problem detecting the LSM303 ... check your connections */ + s_com->println("Ooops, no LSM303 detected ... Check your wiring!"); + while(1); + } +} + +void setup(void){ + s_com->println(("Adafruit 9 DOF Pitch/Roll/Heading Example")); + s_com->println(""); + + /* Initialise the sensors */ + initSensors(); +} + + + + + +void compassTickerCallback() { + compassTriggered = true; +} + +void bluetoothCallback() { + bluetoothTriggered = true; +} + + + +void compassTickerHandler() { + led1 = 1; + + sensors_event_t accel_event; + sensors_event_t mag_event; + sensors_vec_t orientation; + + /* Calculate pitch and roll from the raw accelerometer data */ + accel.getEvent(&accel_event); + if (dof.accelGetOrientation(&accel_event, &orientation)){ + /* 'orientation' should have valid .roll and .pitch fields */ + s_com->print(("Roll: ")); + s_com->print(orientation.roll); + s_com->print(("; ")); + s_com->print(("Pitch: ")); + s_com->print(orientation.pitch); + s_com->print(("; ")); + } + + /* Calculate the heading using the magnetometer */ + mag.getEvent(&mag_event); + if (dof.magGetOrientation(SENSOR_AXIS_Z, &mag_event, &orientation)){ + /* 'orientation' should have valid .heading data now */ + s_com->print(("Heading: ")); + s_com->print(orientation.heading); + s_com->print(("; ")); + } + + s_com->println(("")); + + led1 = 0; + compassTriggered = false; +} + +void bluetoothHandler() { + bluetooth.gets(buf, 256); + //pc.puts(buf); + //Call the static call method on the RPC class + RPC::call(buf, outbuf); + //bluetooth.printf("%s\n", outbuf); + bluetoothTriggered = false; +} + + +int main() { + + pc.baud(115200); + bluetooth.baud(115200); + + setup(); + compassTicker.attach(&compassTickerCallback, 5); // the address of the function to be attached (flip) and the interval (2 seconds) + + while(1) { + if(pc.readable()) { + pc.putc(pc.getc()); + } + if(bluetooth.readable()) { + bluetooth.gets(buf, 256); + RPC::call(buf, outbuf); + } + if(compassTriggered){ + compassTickerHandler(); + } + + + } +} \ No newline at end of file
diff -r 000000000000 -r 3054baadfda9 mbed-rpc.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rpc.lib Sat Nov 28 10:08:18 2015 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/teams/mbed/code/mbed-rpc/#4490a0d9cb2a
diff -r 000000000000 -r 3054baadfda9 mbed-rtos.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Sat Nov 28 10:08:18 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#6d90423c236e
diff -r 000000000000 -r 3054baadfda9 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat Nov 28 10:08:18 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/165afa46840b \ No newline at end of file