test header software pre-lora use
Dependencies: mbed SDFileSystem FXOS8700Q
Revision 0:8190023facdb, committed 2019-03-13
- Comitter:
- oliviab
- Date:
- Wed Mar 13 19:26:09 2019 +0000
- Commit message:
- Test for header file (to check ); compiles ok;
Changed in this revision
diff -r 000000000000 -r 8190023facdb FXOS8700Q.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FXOS8700Q.lib Wed Mar 13 19:26:09 2019 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/Freescale/code/FXOS8700Q/#aee7dea904e2
diff -r 000000000000 -r 8190023facdb SDFileSystem.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SDFileSystem.lib Wed Mar 13 19:26:09 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/Manon_rsy/code/SDFileSystem/#4dd9dd045e08
diff -r 000000000000 -r 8190023facdb SensorData.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SensorData.cpp Wed Mar 13 19:26:09 2019 +0000 @@ -0,0 +1,104 @@ +//#include "mbed.h" +//#include <string> +//#include "FXOS8700Q.h" +//#include "SDFileSystem.h" + +#include "SensorData.h" + + +DigitalOut led(LED1); + +#define UART3_tx PTC17 +#define UART3_rx PTC16 +// +//#define UART3_tx D8 +//#define UART3_rx D2 + + +//in header +Serial s_com(UART3_tx, UART3_rx); // tx, rx read gps in +//SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // MOSI, MISO, SCK, CS +//FILE *fp = fopen("/sd/myfile.txt", "w"); +//I2C i2c(PTE25, PTE24); +//FXOS8700QAccelerometer acc(i2c, FXOS8700CQ_SLAVE_ADDR1); //access accelerometer +//FXOS8700QMagnetometer mag(i2c, FXOS8700CQ_SLAVE_ADDR1); + +//void readData(); +//void sensor_data(); +//void log_data(string data); + +//char rca1[128]; +////string rca2; +//string data; + +int main() +{ + + + printf("Hello World !\n"); + acc.enable(); //start accelerometer + mag.enable(); + + + fp = fopen("/sd/sensors.txt", "r"); + if (fp != NULL) { + fclose(fp); + remove("/sd/sensors.txt"); + //pc.printf("Remove an existing file with the same name \n"); + } + + while(1) { + while (s_com.readable()) { +// rca = s_com.getc(); +// printf("%c",rca); + readData(); + sensor_data(); + + } + } +} + +void readData() +{ + s_com.scanf("%s",rca1); + string rca2(rca1); + rca2 += "\n"; + log_data(rca2); + printf(rca2.c_str()); +} + +void sensor_data() +{ + + //get mag+accel data + motion_data_units_t acc_data, mag_data; + + acc.getAxis(acc_data); + mag.getAxis(mag_data); +// pc.printf("\rACC: X=%1.4ff Y=%1.4ff Z=%1.4ff ", acc_data.x, acc_data.y, acc_data.z); +// pc.printf(" MAG: X=%4.1ff Y=%4.1ff Z=%4.1ff \r\n", mag_data.x, mag_data.y, mag_data.z); +// data = ("ACC: "+ acc_data.x + ", "+ acc_data.y + ", " + acc_data.z + "\n" + +// "MAG: " + mag_data.x + ", " + mag_data.y + ", " + mag_data.z + "\n"); + data = "helloworld!\n"; //test + log_data(data); + +// wait(0.5); + +} + + +void log_data(string data) +{ + + // printf("\nWriting data to the sd card \n"); + fp = fopen("/sd/sensors.txt", "w"); + if (fp == NULL) { + //pc.printf("Unable to write the file \n"); + } else { + fprintf(fp, data.c_str()); + fclose(fp); + //pc.printf("File successfully written! \n"); + } + + +} \ No newline at end of file
diff -r 000000000000 -r 8190023facdb SensorData.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SensorData.h Wed Mar 13 19:26:09 2019 +0000 @@ -0,0 +1,20 @@ +#include "mbed.h" +#include <string> +#include "FXOS8700Q.h" +#include "SDFileSystem.h" + +//Serial s_com(UART3_tx, UART3_rx); // tx, rx read gps in +SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // MOSI, MISO, SCK, CS +FILE *fp = fopen("/sd/myfile.txt", "w"); +I2C i2c(PTE25, PTE24); +FXOS8700QAccelerometer acc(i2c, FXOS8700CQ_SLAVE_ADDR1); //access accelerometer +FXOS8700QMagnetometer mag(i2c, FXOS8700CQ_SLAVE_ADDR1); + +char rca1[128]; +//string rca2; +string data; + + +void readData(); +void sensor_data(); +void log_data(string data); \ No newline at end of file
diff -r 000000000000 -r 8190023facdb mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Mar 13 19:26:09 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/3a7713b1edbc \ No newline at end of file