Run on TY51822r3 board with ACC sensor (LIS3DH or BMC050)
Dependencies: BLE_API LIS3DH mbed nRF51822 BMC050 nRF51_LowPwr nRF51_Vdd
Fork of BLE_EddystoneBeacon_Service by
Revision 37:ea459e6c6a35, committed 2016-06-11
- Comitter:
- kenjiArai
- Date:
- Sat Jun 11 01:51:59 2016 +0000
- Parent:
- 36:5508506dda71
- Commit message:
- Added low power mode (use nRF51_LowPwr library) for reduce Idle Current
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
nRF51_LowPwr.lib | Show annotated file Show diff for this revision Revisions of this file |
diff -r 5508506dda71 -r ea459e6c6a35 main.cpp --- a/main.cpp Wed Jun 01 12:32:19 2016 +0000 +++ b/main.cpp Sat Jun 11 01:51:59 2016 +0000 @@ -21,7 +21,7 @@ * http://mbed.org/users/kenjiArai/ * * Started: Feburary 1st, 2016 - * Revised: June 1st, 2016 + * Revised: June 8th, 2016 * * Original: * nRF51822_SimpleControls @@ -53,7 +53,7 @@ * */ -#define ACC_DEVIC 1 // 0=LIS3DH, 1=BMC050 +#define ACC_DEVIC 0 // 0=LIS3DH, 1=BMC050 // Include --------------------------------------------------------------------------------------- #include "mbed.h" @@ -68,15 +68,15 @@ #include "nRF51_lowpwr.h" // Definition ------------------------------------------------------------------------------------ -#define USE_ACC 1 // if you equipped ACC sensor, please set 1 -#define CHK_ACC 0 +#define USE_ACC 0 // if you equipped ACC sensor, please set 1 +#define CHK_ACC 0 // Ckeck ACC device itself #define POWER_LEVEL 0 // 0,1,2 // Before using this function, please specify your program are used following functions or not. #define USE_DEVICE_STDIO_MESSAGES 0 // printf #define USE_DEVICE_SERIAL 0 // Serial or DEBUG & etc. -#define USE_DEVICE_I2C 1 // Sensors with I2C, LCD, EEPROM, Driver chips & etc. +#define USE_DEVICE_I2C 0 // Sensors with I2C, LCD, EEPROM, Driver chips & etc. #define USE_DEVICE_SPI 0 // Sensors with SOI, LCD, EEPROM, Driver chips & etc. #define USE_DEVICE_SPISLAVE 0 // Communication with master vis SPI #define USE_DEVICE_PWMOUT 0 // PWM duty output, Serve & etc. @@ -122,44 +122,44 @@ }; #endif -const nRF51_LOWPWR_TypeDef lowpwr_table = - { - #if USE_DEVICE_STDIO_MESSAGES - true, - #else - false, - #endif - #if USE_DEVICE_SERIAL - true, - #else - false, - #endif - #if USE_DEVICE_I2C - true, - #else - false, - #endif - #if USE_DEVICE_SPI - true, - #else - false, - #endif - #if USE_DEVICE_SPISLAVE - true, - #else - false, - #endif - #if USE_DEVICE_PWMOUT - true, - #else - false, - #endif - #if USE_DEVICE_ANALOGIN - true - #else - false - #endif - }; +const nRF51_LOWPWR_TypeDef lowpwr_table = + { + #if USE_DEVICE_STDIO_MESSAGES + true, + #else + false, + #endif + #if USE_DEVICE_SERIAL + true, + #else + false, + #endif + #if USE_DEVICE_I2C + true, + #else + false, + #endif + #if USE_DEVICE_SPI + true, + #else + false, + #endif + #if USE_DEVICE_SPISLAVE + true, + #else + false, + #endif + #if USE_DEVICE_PWMOUT + true, + #else + false, + #endif + #if USE_DEVICE_ANALOGIN + true + #else + false + #endif + }; // Function prototypes --------------------------------------------------------------------------- int8_t check_dice(void); @@ -285,13 +285,14 @@ } } } -#else +#else // (CHK_ACC == 0) #if (USE_ACC == 0) #error "Please set USE_ACC = 1) -#else +#else // (USE_ACC == 0) int main(void){ float fa[3]; +#if (ACC_DEVIC == 1) while (true){ if (acc.read_id_acc() == I_AM_BMC050_ACC){ PRINTF("I'm BMC050\r\n"); @@ -302,13 +303,14 @@ } wait(1.0); } +#endif // (ACC_DEVIC == 1) LowPwr set_lowpwr(&lowpwr_table); while (true) { #if ACC_DEVIC acc.read_data_acc(fa); -#else +#else // ACC_DEVIC acc.read_data(fa); -#endif +#endif // ACC_DEVIC PRINTF("acc:x=%+4.2f,y=%+4.2f,z=%+4.2f\r\n",fa[0],fa[1],fa[2]); wait(0.5); } @@ -322,9 +324,9 @@ #if ACC_DEVIC acc.read_data_acc(fa); -#else +#else // ACC_DEVIC acc.read_data(fa); -#endif +#endif // ACC_DEVIC //PRINTF("acc:%4.3f\r\n", fa[0]); PRINTF("acc:x=%+4.2f,y=%+4.2f,z=%+4.2f\r\n",fa[0],fa[1],fa[2]); if (fa[0] > 6.0f){ return 2;} @@ -335,7 +337,7 @@ if (fa[2] < -6.0f){ return 6;} return 0; } -#else +#else // (USE_ACC == 1) int8_t check_dice(void){ return 1; } @@ -354,7 +356,7 @@ v = vdd.read_real_value(); PRINTF("Vdd:%f[V]\r\n", v); return (uint16_t)(v * 1000); -#else +#else //USE_DEVICE_SERIAL return (uint16_t)(vdd.read_real_value() * 1000); #endif // USE_DEVICE_SERIAL } @@ -377,7 +379,7 @@ t = float(p_temp) / 4; // Original = float(p_temp)/4.0f - 16.0f; #if USE_DEVICE_SERIAL PRINTF("Chip temp: %+4.1f[degC]\r\n", t); -#endif +#endif // USE_DEVICE_SERIAL if ( t >= 0){ temp = (uint16_t)(t * 256); } else {
diff -r 5508506dda71 -r ea459e6c6a35 nRF51_LowPwr.lib --- a/nRF51_LowPwr.lib Wed Jun 01 12:32:19 2016 +0000 +++ b/nRF51_LowPwr.lib Sat Jun 11 01:51:59 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/kenjiArai/code/nRF51_LowPwr/#9ddf14df689c +http://mbed.org/users/kenjiArai/code/nRF51_LowPwr/#ffd5168de563