alonso palomino
/
ST
iot
Diff: main.cpp
- Revision:
- 3:3157e61f2bfd
- Parent:
- 2:02175845b24c
diff -r 02175845b24c -r 3157e61f2bfd main.cpp --- a/main.cpp Sun Oct 15 18:24:03 2017 +0000 +++ b/main.cpp Tue Oct 17 20:55:04 2017 +0000 @@ -10,10 +10,9 @@ MPU9250 mpu = MPU9250(p26, p27); // Configuration -bool testMPUConnection = true; -bool doSensorInitialization = false; -bool printAccelerometer = false; -bool printGyroscope = false; +bool doSensorInitialization = true; +bool printAccelerometer = true; +bool printGyroscope = true; DigitalOut led1(LED1); InterruptIn button(BUTTON1); @@ -27,24 +26,8 @@ IDLE }; -static uint8_t buttonState = IDLE; - static ButtonService *buttonServicePtr; -void buttonPressedCallback(void) -{ - /* Note that the buttonPressedCallback() executes in interrupt context, so it is safer to access - * BLE device API from the main thread. */ - buttonState = PRESSED; -} - -void buttonReleasedCallback(void) -{ - /* Note that the buttonReleasedCallback() executes in interrupt context, so it is safer to access - * BLE device API from the main thread. */ - buttonState = RELEASED; -} - void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params) { BLE::Instance().gap().startAdvertising(); @@ -106,9 +89,7 @@ //Attach a function to be called by the Ticker, specifiying the interval in seconds. Ticker ticker; - ticker.attach(periodicFunctionCallback, 1); - button.fall(buttonPressedCallback); - button.rise(buttonReleasedCallback); + ticker.attach(periodicFunctionCallback, 1); BLE &ble = BLE::Instance(); ble.init(bleInitComplete); @@ -119,13 +100,6 @@ /* spin loop */ } - if (testMPUConnection) { - uint8_t whoami = mpu.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250); // Read WHO_AM_I register for MPU-9250 - pc.printf("I AM 0x%x\n\r", whoami); - pc.printf("I SHOULD BE 0x71\n\r"); - wait(1); - } - if (doSensorInitialization) { // Initialise sensor board pc.printf("Initializing sensor\n\r"); @@ -136,53 +110,26 @@ while(1) { - //pc.printf("Starting to stream data"); if(printAccelerometer && printGyroscope) { mpu.readAccelData(accelerometer); float ax = accelerometer[0] * 2.0 / 32768.0; float ay = accelerometer[1] * 2.0 / 32768.0; float az = accelerometer[2] * 2.0 / 32768.0; - //pc.printf("Acelerometer information, AX, AY, AZ \n"); - //pc.printf("(%f, %f, %f)\n", ax,ay,az); - float roll = float(atan2(ay, az) * 180/3.1416f); float pitch = float(atan2(-ax, sqrt(ay*ay + az*az)) * 180/3.1416f); float yaw = atan(ax/-ay); - //pc.printf("Roll/Pitch/Yaw: (%f, %f, %f)\n", roll, pitch, yaw); - mpu.readGyroData(gyroscope); float gx = gyroscope[0] * 250.0 / 32768.0; float gy = gyroscope[1] * 250.0 / 32768.0; float gz = gyroscope[2] * 250.0 / 32768.0; - - - pc.printf("(%f, %f, %f, %f, %f, %f)\n", roll, pitch, yaw, gx, gy, gz); - + + buttonServicePtr->updateButtonState(roll, pitch, yaw, gx, gy, gz); } - if (buttonState != IDLE) { - //buttonServicePtr->updateButtonState(buttonState); - //char myword[] = { 'H', 'e', 'l', 'l', 'o', '\0' }; - uint8_t sensorValues[12] = {0}; - sensorValues[0] = 12; - sensorValues[1] = 12; - sensorValues[2] = 12; - sensorValues[3] = 12; - sensorValues[4] = 12; - sensorValues[5] = 12; - sensorValues[6] = 12; - sensorValues[7] = 12; - sensorValues[8] = 12; - sensorValues[9] = 12; - sensorValues[10] = 12; - sensorValues[11] = 12; - buttonServicePtr->updateButtonState(sensorValues); - buttonState = IDLE; - } ble.waitForEvent(); - //wait(0.3); + wait(0.3); } } \ No newline at end of file