Wristband test
Dependencies: BLE_API W25Q16BV WatchdogTimer eMPL_MPU mbed nRF51822-1
Fork of Seeed_Test_Wristband by
Diff: main.cpp
- Revision:
- 5:6d822326219f
- Parent:
- 4:943235e0dd27
- Child:
- 6:762c47a553f6
--- a/main.cpp Sat Mar 26 07:19:02 2016 +0000 +++ b/main.cpp Mon Aug 29 02:11:58 2016 +0000 @@ -20,7 +20,7 @@ static unsigned long curr_time = 0; Timeout timeout; -static const uint8_t player_no = 2; +static const uint8_t player_no = 0; WatchdogTimer watchdogTimer(100); /***************Fault Handle*************/ @@ -61,32 +61,35 @@ ((NRF_UART_Type *)UART_0)->PSELRTS = 0xFFFFFFFF; } -void testFlash() +int testFlash() { flash.chipErase(); int ddd = flash.readByte(0x34); - LOG("%d\r\n", ddd); +// LOG("%d\r\n", ddd); if (ddd != 255) { - LOG("earse flash failed.\r\n"); - NVIC_SystemReset(); +// LOG("earse flash failed.\r\n"); +// NVIC_SystemReset(); + return 0; } - else { - LOG("Flash Erase done\r\n"); - } +// else { +//// LOG("Flash Erase done\r\n"); +// } char string[] = "ABCDEFGHIJK"; flash.writeStream(0x12, string, 11); char str3[11] = {0}; flash.readStream(0x12, str3, 11); - LOG("%s\r\n",str3); +// LOG("%s\r\n",str3); if (str3[0] != 'A') { - LOG("write byte failed.\r\n"); - NVIC_SystemReset(); +// LOG("write byte failed.\r\n"); + return 0; +// NVIC_SystemReset(); } wait(0.1); + return 1; } /***************mpu*************/ @@ -184,8 +187,8 @@ vibr = 0; wait(1); vibr = 1; - wait(1); - vibr = 0; +// wait(1); +// vibr = 0; } void vibrOn() @@ -213,7 +216,13 @@ uint16_t mpuCharUUID = 0xA003; static uint8_t mpuValue[18] = {0}; ReadOnlyArrayGattCharacteristic<uint8_t, sizeof(mpuValue)> mpuChar(mpuCharUUID, mpuValue, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY); -GattCharacteristic *characteristics[] = {&readwriteChar, &flashChar, &mpuChar}; +uint16_t rtcCharUUID = 0xA004; +static uint8_t rtcValue[20] = {0,}; +ReadWriteArrayGattCharacteristic<uint8_t, sizeof(rtcValue)> rtcChar(rtcCharUUID, rtcValue, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY); +uint16_t chargeCharUUID = 0xA005; +static uint8_t chargeValue[2] = {0}; +ReadOnlyArrayGattCharacteristic<uint8_t, sizeof(mpuValue)> chargeChar(chargeCharUUID, chargeValue, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY); +GattCharacteristic *characteristics[] = {&readwriteChar, &flashChar, &mpuChar, &rtcChar, &chargeChar}; GattService testService(testServiceUUID, characteristics, sizeof(characteristics) / sizeof(GattCharacteristic *)); void connectionCallback(const Gap::ConnectionCallbackParams_t *params) @@ -352,14 +361,16 @@ // LOG("charge: %d\r\n", chg); if (chg) { // not charging blue = 1; + AdvData[2] = AdvData[2] & 0x7F; + chargeValue[0] = 0; } else { // charging blue = !blue; - float vcc = readBatteryLevel(); - if (vcc > 4.36) { - blue = 0; - } + AdvData[2] = AdvData[2] | 0x80; + chargeValue[0] = 1; } + chargeValue[1] = AdvData[2] & 0x7F; + ble.updateCharacteristicValue(chargeChar.getValueHandle(), chargeValue, 2); } @@ -414,26 +425,68 @@ #endif release_cts_rts(); - // flash - testFlash(); - flash.enterDeepPowerDown(); +// char str3[8] = {0}; +// flash.readStream(0x13, str3, 8); +// for (int8_t i=0; i<8; i++) { +// LOG("%x", str3[i]); +// } +// LOG("\r\n"); +// uint32_t id0 = 0; +// uint32_t id1 = 0; +// memcpy(&id0, str3, 4); +// memcpy(&id1, &str3[4], 4); +// LOG("%d, %d\r\n", id0, id1); +// uint32_t d0 = NRF_FICR->DEVICEADDR[0]; +// uint32_t d1 = NRF_FICR->DEVICEADDR[1]; +// if (d0 != id0 || d1 != id1) { +// NVIC_SystemReset(); +// } + +// // flash +// testFlash(); +// flash.enterDeepPowerDown(); // release_flash_spi(); - get_ms(&curr_time); - LOG("flash test done @ %d\r\n", curr_time); +// get_ms(&curr_time); +// LOG("flash test done @ %d\r\n", curr_time); // led testLEDs(); - get_ms(&curr_time); - LOG("led test done @ %d\r\n", curr_time); +// get_ms(&curr_time); +// LOG("led test done @ %d\r\n", curr_time); // vibr testVibr(); - get_ms(&curr_time); - LOG("vibr test done @ %d\r\n", curr_time); +// get_ms(&curr_time); +// LOG("vibr test done @ %d\r\n", curr_time); + + // charge state + int chg = charge.read(); + LOG("charge:%d\r\n", chg); + + wait(3.0); + + int tf = testFlash(); + LOG("flash:%d\r\n", tf); // uid and mac address - LOG("DEVICE ADDR: %x,%x\r\n", NRF_FICR->DEVICEADDR[0], NRF_FICR->DEVICEADDR[1]); - LOG("DEVICE ID: %x,%x\r\n", NRF_FICR->DEVICEID[0], NRF_FICR->DEVICEID[1]); + LOG("MAC: %x,%x\r\n", NRF_FICR->DEVICEADDR[0], NRF_FICR->DEVICEADDR[1]); + LOG("UID: %x,%x\r\n", NRF_FICR->DEVICEID[0], NRF_FICR->DEVICEID[1]); + +// uint32_t d0 = NRF_FICR->DEVICEADDR[0]; +// uint32_t d1 = NRF_FICR->DEVICEADDR[1]; +// LOG("%d, %d, %x, %x\r\n", d0, d1, d0, d1); +// flash.chipErase(); +// char str[8] = {0}; +// memcpy(&str[0], &d0, 4); +// memcpy(&str[4], &d1, 4); +// flash.writeStream(0x36, str, 8); + +// char str3[8] = {0}; +// flash.readStream(0x12, str3, 100); +// for (int8_t i=0; i<100; i++) { +// LOG("%x", str3[i]); +// } +// LOG("\r\n"); // mpu9250 mbed_spi_init(MPU9250_MOSI, MPU9250_MISO, MPU9250_SCLK, MPU9250_CS); @@ -477,7 +530,7 @@ Ticker batteryTicker; batteryTicker.attach(checkBatteryCallback, 90.0f); Ticker chargeTicker; - chargeTicker.attach(chargeCallback, 1.0f); + chargeTicker.attach(chargeCallback, 2.0f); // Ticker tickPrint; // tickPrint.attach(printCallback, 60.0f); @@ -529,6 +582,7 @@ memcpy(&mpuValue[6], gyro, 6); memcpy(&mpuValue[12], compass, 6); ble.updateCharacteristicValue(mpuChar.getValueHandle(), mpuValue, 18); + LOG("accel:%.3f %.3f %.3f,gyro:%.3f %.3f %.3f\r\n", accel[0]/2048.0f, accel[1]/2048.0f, accel[2]/2048.0f, gyro[0]/16.4, gyro[1]/16.4, gyro[2]/16.4); } } }