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: BLE_API mbed nRF51822
Fork of BLE_UARTConsole by
main.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #include <string.h> 00018 #include <stdarg.h> 00019 #include "mbed.h" 00020 00021 00022 #define DEBUG 1 /* Set this if you need debug messages on the console; 00023 * it will have an impact on code-size and power consumption. */ 00024 00025 //Icarus libraries 00026 #include "ADXL362Sensor.h" 00027 #include "MPU9250Sensor.h" 00028 00029 00030 00031 #define BAUD_RATE 115200 00032 Serial s(P0_5, P0_6); 00033 00034 #if DEBUG 00035 #define LOG_BUFFER 100 00036 #define LOG(...) do { if (debug) { debug( __VA_ARGS__); } } while (0) 00037 #else 00038 #define LOG_BUFFER 0 00039 #define LOG(...) /* nothing */ 00040 #endif /* #if DEBUG */ 00041 char debugBuffer[LOG_BUFFER]; 00042 void debug ( const char* format, ...) { 00043 va_list argptr; 00044 va_start(argptr, format); 00045 // vsnprintf(debugBuffer, LOG_BUFFER ,format, argptr); 00046 vprintf(format, argptr); 00047 va_end(argptr); 00048 // if (uart){ 00049 // uart->write(debugBuffer, strlen(debugBuffer)); 00050 // } 00051 } 00052 00053 00054 00055 SPI spi1(P0_28, P0_24, P0_29); // mosi, miso, sclk 00056 DigitalOut adxl_cs(P0_23); 00057 DigitalOut mpu_cs(P0_18); 00058 00059 DigitalOut led(P0_5); 00060 DigitalOut motor(P0_6); 00061 00062 DigitalIn button(P0_16,PullDown); 00063 00064 00065 00066 uint32_t sensorErrors[10]; 00067 00068 00069 ADXL362Sensor adxl362(spi1, adxl_cs, debug); 00070 MPU9250Sensor mpu9250(spi1, mpu_cs, debug); 00071 00072 00073 00074 00075 int testSensors(BaseSensor& sensor) 00076 { 00077 uint32_t errorCount = sensor.verifyIntegrity(sensorErrors); 00078 if (errorCount>0){ 00079 for (int i=0;i<errorCount;i++){ 00080 LOG("ERROR: Sensor %s failed with error code: %d\n\r",sensor.getSimpleName(),sensorErrors[i]); 00081 } 00082 } else { 00083 LOG("Sensor %s validated!\n\r",sensor.getSimpleName()); 00084 } 00085 return errorCount; 00086 } 00087 00088 00089 00090 int main(void) 00091 { 00092 s.baud(BAUD_RATE); 00093 00094 00095 LOG("Initialising the nRF51822\n\r"); 00096 00097 while (true) { 00098 testSensors(adxl362); 00099 // testSensors(mpu9250); 00100 wait(10.0f); 00101 } 00102 }
Generated on Wed Jul 13 2022 08:05:01 by
1.7.2
