Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MPU9250_SPI
Fork of WearableDevice_Nucleo by
Diff: main.cpp
- Revision:
- 25:86137c182a17
- Parent:
- 24:eed68c95160c
- Child:
- 26:4bc56ce08d15
--- a/main.cpp Fri Oct 27 09:59:32 2017 +0000
+++ b/main.cpp Fri Oct 27 23:49:44 2017 +0000
@@ -16,10 +16,10 @@
//-----------------------------------------------------------------
// Includes
-#include "mbed.h"
// #include "rtos.h"
// #include "mbed_events.h"
+#include "mbed.h"
#include "configuration.h"
#include "pin.h"
@@ -32,18 +32,29 @@
//-----------------------------------------------------------------
// Declarations
-Timer time_stamp; //Timer µS time-stamp
-EventQueue queue(32 * EVENTS_EVENT_SIZE); //Event
+FILE *fp; // FILE Type for SD-Card
+Timer time_stamp; // Timer µS time-stamp
+
+// Global Variables
const char DeviceNr[6] = "DEV01";
char Data_Buffer[10] = "";
-// uint16_t data_len;
+
+// Events
+EventQueue queue(32 * EVENTS_EVENT_SIZE); // Event Setup
+EventQueue Event1;
+
+// Tickers
+Ticker Ticker1;
+
+// Threads
+Thread Thread1;
// PC Serial (Debug)
Serial PC(USBTX, USBRX);
XBeeLib::XBeeZB XBee = XBeeLib::XBeeZB(RADIO_TX, RADIO_RX, RADIO_RESET, NC, NC, 115200);
int task1_id = queue.call_every(200, CheckInputBuffer);
-int task2_id = queue.call_every(100, ReadIMUData);
+int task2_id = queue.call_every(1, ReadIMUData);
// Create an SDFileSystem object
SDFileSystem sd(SD_MOSI, SD_MISO, SD_CLK, SD_CS, "sd");
@@ -81,35 +92,31 @@
//-----------------------------------------------------------------
void Setup()
{
- PC.baud(9600);
+ // Initialize PC Serial Connection
+ PC.baud(115200);
PC.printf("\r\n------------- Booting! -------------\r\n");
PC.printf("CPU SystemCoreClock is %d Hz", SystemCoreClock);
+ // Initialize XBee Serial Connection
XBee.init();
- XBee.register_receive_cb(&receive_cb); // Register Callbacks
- // time_stamp.start(); // Start Timer
+ XBee.register_receive_cb(&receive_cb); // Register Callbacks
- if(imu.init(1, BITS_DLPF_CFG_188HZ)){ // Initialize the MPU9250
+ // Initialize IMU SPI Connection
+ if(imu.init(1, BITS_DLPF_CFG_188HZ)) // Initialize the MPU9250
PC.printf("\nCouldn't initialize MPU9250 via SPI!");
- }
- PC.printf("\nWHOAMI = 0x%2x", imu.whoami()); // Output I2C address to know if SPI is working, it should be 104
- PC.printf("\nAcc_Scale = %u\n", imu.set_acc_scale(BITS_FS_16G)); // Set Full Range for Acc.
+ PC.printf("\nWHOAMI = 0x%2x", imu.whoami()); // Output I2C Address to check SPI (correct: 104)
+ PC.printf("\nAcc_Scale = %u\n", imu.set_acc_scale(BITS_FS_16G)); // Set Full Range for Acc.
- // Task queue
- // int task1_id = queue.call_every(200, CheckInputBuffer);
- // int task2_id = queue.call_every(50, ReadIMUData);
- // int task3_id = queue.call_every(3000, &print_event, (void *)"called every 3 seconds\n", (int) time_stamp.read());
- // int task4_id = queue.call_every(50, blink_event, led1);
- // int task5_id = queue.call_every(500, println_event);
- // int task6_id = queue.call_every(500, readIMU);
- // int task7_id = queue.call_every(500, gayEvent);
+ // Initialize SD-Card SPI Connection
+
+
}
void SDTest()
{
mkdir("/sd/Log", 0777);
- FILE *fp = fopen("/sd/Log/Data_Log.txt", "w");
+ fp = fopen("/sd/Log/Data_Log.txt", "w");
if(fp == NULL) {
error("File Writing Failed!\n");
}
@@ -142,15 +149,19 @@
Setup(); // Initial Setups
led1 = 1;
- PC.printf("\r\n-------------- Ready! --------------\r\n");
+ PC.printf("\r\n----------- Ready! --------------\r\n");
SDTest();
-
+
+ Thread1.start(callback(&Event1, &EventQueue::dispatch_forever));
+ Ticker1.attach(Event1.event(&ReadIMUData), 0.1);
+
+ fp = fopen("/sd/Log/Data_Log.txt", "w");
time_stamp.reset();
time_stamp.start();
- queue.dispatch();
+ queue.dispatch();
while (true) {
-
-
+
+
}
}
//-----------------------------------------------------------------
\ No newline at end of file
