skm
Fork of Hello_FXOS8700Q by
Revision 7:4c834e4dad1f, committed 2015-06-18
- Comitter:
- marcus255
- Date:
- Thu Jun 18 16:25:26 2015 +0000
- Parent:
- 6:02bfeec82bc1
- Commit message:
- skm
Changed in this revision
diff -r 02bfeec82bc1 -r 4c834e4dad1f FXOS8700Q.lib --- a/FXOS8700Q.lib Fri Apr 25 16:47:00 2014 +0000 +++ b/FXOS8700Q.lib Thu Jun 18 16:25:26 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/JimCarver/code/FXOS8700Q/#c53dda05b8cf +http://developer.mbed.org/users/marcus255/code/FXOS8700Q/#b924243d454f
diff -r 02bfeec82bc1 -r 4c834e4dad1f cli.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cli.cpp Thu Jun 18 16:25:26 2015 +0000 @@ -0,0 +1,49 @@ +#include "cli.h" + +void commandService (command *commandStruct){ + int space = 0; + char c; + while ((c = getchar()) != char(13)){ // reads chars until you hit enter + putchar(c); // prints received chars to make echo on console + if (c == ' ') { c = getchar(); putchar(c); space++; } + if (space == 0) { commandStruct->commandName += c; } // if no space occured, place chars in commandName field + else if (space == 1){ commandStruct->commandArg += c; } // if one space occured, place chars in commandArg field + else { commandStruct->commandValue += c; } // if two spaces occured, place chars in commandValue field + } +} + +void commandValidate(command *commandStruct){ + int val; + if (commandStruct->commandName == "accel"){ + if (commandStruct->commandArg == "threshold"){ + val = atoi((commandStruct->commandValue).c_str()); + if (val > 0 && val < 8000){ + threshold = val; + pc.printf("\rthreshold set to %s mg",commandStruct->commandValue); + } + else { pc.printf("\rInvalid value \'%s\'. Valid value range: <1-7999>",commandStruct->commandValue); } + } + else if (commandStruct->commandArg == "help") { pc.printf("\rAvailable arguments for %s are: threshold [value]",commandStruct->commandName); } + else { pc.printf("\rUnrecognized argument \'%s\'",commandStruct->commandArg); } + } + else if (commandStruct->commandName == "delay"){ + if (commandStruct->commandArg == "set"){ + val = atoi((commandStruct->commandValue).c_str()); + if (val > 0 && val < 2001){ + msDelay = val; + pc.printf("\rMeasurement delay set to %d ms", val); + } + else { pc.printf("\rInvalid value \'%s\'. Valid values are <1-2000>", commandStruct->commandValue); } + } + else if (commandStruct->commandArg == "help") { pc.printf("\rAvailable arguments for %s are: set [value]",commandStruct->commandName); } + else { pc.printf("\rUnrecognized argument \'%s\'",commandStruct->commandArg); } + } + else if (commandStruct->commandName == "help"){ pc.printf("\rAvailable commands: accel, delay"); } + else { pc.printf("\rUnrecognized command \'%s\'",commandStruct->commandName); } +} + +void clearConsole(void){ + printf("\r"); + for (int i = 0; i < 64; i++) { printf(" "); } + printf("\r"); +} \ No newline at end of file
diff -r 02bfeec82bc1 -r 4c834e4dad1f cli.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cli.h Thu Jun 18 16:25:26 2015 +0000 @@ -0,0 +1,21 @@ +#ifndef CLI_H +#define CLI_H + +#include <string> +#include "mbed.h" + +extern int msDelay; +extern int threshold; +extern Serial pc; + +struct command { + string commandName; + string commandArg; + string commandValue; +}; + +void commandService (command *commandStruct); // gets text line from user and places strings in 'command' structure +void commandValidate(command *commandStruct); // validates if keywords are correct and performs proper actions +void clearConsole(void); // clears line using spaces and carriage return character + +#endif \ No newline at end of file
diff -r 02bfeec82bc1 -r 4c834e4dad1f main.cpp --- a/main.cpp Fri Apr 25 16:47:00 2014 +0000 +++ b/main.cpp Thu Jun 18 16:25:26 2015 +0000 @@ -1,53 +1,53 @@ #include "mbed.h" #include "FXOS8700Q.h" - - -//FXOS8700Q acc( A4, A5, FXOS8700CQ_SLAVE_ADDR0); // Proper Ports and I2C address for Freescale Multi Axis shield -//FXOS8700Q mag( A4, A5, FXOS8700CQ_SLAVE_ADDR0); // Proper Ports and I2C address for Freescale Multi Axis shield -FXOS8700Q_acc acc( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // Proper Ports and I2C Address for K64F Freedom board -FXOS8700Q_mag mag( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // Proper Ports and I2C Address for K64F Freedom board +#include "cli.h" -Serial pc(USBTX, USBRX); - -MotionSensorDataUnits mag_data; +FXOS8700Q_acc acc(PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // Proper ports and I2C Address for FXOS8700Q accelometer +Serial pc(USBTX, USBRX); // Proper ports for USART MotionSensorDataUnits acc_data; - -MotionSensorDataCounts mag_raw; MotionSensorDataCounts acc_raw; +int msDelay = 300; // default measurement delay in ms +int threshold = 2000; // default acceleration threshold in mg +DigitalOut redLed(LED_RED); +DigitalOut greenLed(LED_GREEN); +DigitalOut blueLed(LED_BLUE); int main() { -float faX, faY, faZ; -float fmX, fmY, fmZ; -int16_t raX, raY, raZ; -int16_t rmX, rmY, rmZ; -acc.enable(); -printf("\r\n\nFXOS8700Q Who Am I= %X\r\n", acc.whoAmI()); + pc.baud(115200); + acc.enable(); + //printf("\n\rFXOS8700Q Device Address = %X\r\n", acc.whoAmI()); + //uint8_t scopeValues[6]; // unmodified data frame from accelometer device + float a, b, c; + while (true) { + command commandStruct; acc.getAxis(acc_data); - mag.getAxis(mag_data); - printf("FXOS8700Q ACC: X=%1.4f Y=%1.4f Z=%1.4f ", acc_data.x, acc_data.y, acc_data.z); - printf(" MAG: X=%4.1f Y=%4.1f Z=%4.1f\r\n", mag_data.x, mag_data.y, mag_data.z); - acc.getX(&faX); - acc.getY(&faY); - acc.getZ(&faZ); - mag.getX(&fmX); - mag.getY(&fmY); - mag.getZ(&fmZ); - printf("FXOS8700Q ACC: X=%1.4f Y=%1.4f Z=%1.4f ", faX, faY, faZ); - printf(" MAG: X=%4.1f Y=%4.1f Z=%4.1f\r\n", fmX, fmY, fmZ); - acc.getAxis(acc_raw); - mag.getAxis(mag_raw); - printf("FXOS8700Q ACC: X=%d Y=%d Z=%d ", acc_raw.x, acc_raw.y, acc_raw.z); - printf(" MAG: X=%d Y=%d Z=%d\r\n", mag_raw.x, mag_raw.y, mag_raw.z); - acc.getX(&raX); - acc.getY(&raY); - acc.getZ(&raZ); - mag.getX(&rmX); - mag.getY(&rmY); - mag.getZ(&rmZ); - printf("FXOS8700Q ACC: X=%d Y=%d Z=%d ", raX, raY, raZ); - printf(" MAG: X=%d Y=%d Z=%d\r\n\n", rmX, rmY, rmZ); - wait(1.0); - } -} \ No newline at end of file + //acc.getAxis(acc_raw, scopeValues); + //printf("Dane z odebranej ramki: "); + //for (uint8_t i = 0; i < 6; i++) + //printf("%04x ",scopeValues[i]); + + printf("\r"); + if ((a=acc_data.x) < 0) printf("X=-%1.3fg ", abs(a)); else printf("X=+%1.3fg ", abs(a)); + if ((b=acc_data.y) < 0) printf("Y=-%1.3fg ", abs(b)); else printf("Y=+%1.3fg ", abs(b)); + if ((c=acc_data.z) < 0) printf("Z=-%1.3fg ", abs(c)); else printf("Z=+%1.3fg ", abs(c)); + + float th = threshold / 1000.0; // to get threshold in g (user defines it in mg) + if (abs(a) > th) redLed = 0; else redLed = 1; // lights the led on if absolute value of acceleration is greater than defined threshold + if (abs(b) > th) greenLed = 0; else greenLed = 1; // otherwise lights the led off + if (abs(c) > th) blueLed = 0; else blueLed = 1; // different colors are assigned with corresponding axis + + wait(msDelay/(1000.0*2.0)); + + if(pc.readable()) { // if USART buffor is not empty (if user enters a command) + clearConsole(); + commandService(&commandStruct); + clearConsole(); + commandValidate(&commandStruct); + wait(3.0); + clearConsole(); + } + } +} +
diff -r 02bfeec82bc1 -r 4c834e4dad1f mbed.bld --- a/mbed.bld Fri Apr 25 16:47:00 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/6473597d706e \ No newline at end of file
diff -r 02bfeec82bc1 -r 4c834e4dad1f mbed.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.lib Thu Jun 18 16:25:26 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/#7cff1c4259d7