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 Inp_Fiber_Logo_FOTA by
Diff: main.cpp
- Revision:
- 8:1ad3ab5148bc
- Parent:
- 7:4118d5a717bc
- Child:
- 9:4363af5affba
--- a/main.cpp Mon Jun 19 00:47:31 2017 +0000 +++ b/main.cpp Tue Jul 04 00:36:43 2017 +0000 @@ -1,3 +1,5 @@ +// 20170703 BRIGHTNESS_MAXを100に変更 +// シリアル通信のプロトコルを、文字列→バイト列に変更 // 20170619 DeviceInformationのSerialNumberにIND+Macアドレスを適用し、DEVICENAMEはINUPATHYとした // 20170617 ストレス値を"R"(relax)から"S"(stress)に変更し、(1.0 - relaxRatio)を送るよう改変 // 20170617 輝度調整の方法をrgbの合計値を基準にするように調整した。 @@ -28,7 +30,7 @@ #define MAXCONARRAY 10 #define MAXSTRESSARRAY 3 -#define BRIGHTNESS_MAX 150 // RGBLED1セットのpwm合計値の上限 ws2812b型のneopixelが6個の場合、150を超えた値にするとセンサーが誤作動する +#define BRIGHTNESS_MAX 100 // RGBLED1セットのpwm合計値の上限 ws2812b型のneopixelが6個の場合、150を超えた値にするとセンサーが誤作動する #define DIM_LED ((float)(BRIGHTNESS_MAX) / (float)(255)) // R, G, Bそれぞれのpwm値がBRIGHTNESS_MAXを超えない様にする制限 @@ -296,6 +298,7 @@ int main(void) { +/* char msgIBI[100]; int nMsgIBILen = 0; char msgHappy[10]; @@ -304,9 +307,11 @@ int nMsgConcentrationLen = 0; char msgRelax[10]; int nMsgRelaxLen = 0; +*/ + byte_t msgHeader[3] = {0x49,0x4e,0x50}; - char msg[256]; - int nMsgLen = 0; + byte_t msg[19]; +// int nMsgLen = 0; float Brightness = 1.0; bool brighten = true; @@ -558,7 +563,7 @@ // nMsgLen = sprintf(msg,"B%d\0", BPM); // ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), (uint8_t*)msg, nMsgLen); - nMsgIBILen = sprintf(msgIBI,"Q%d\0", IBI); +// nMsgIBILen = sprintf(msgIBI,"Q%d\0", IBI); // ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), (uint8_t*)msg, nMsgLen); // 平均値算出用配列に値を詰める @@ -629,7 +634,7 @@ // リラックスの係数を算出する relaxRatio = diffRatio; - nMsgRelaxLen = sprintf(msgRelax,"S%0.2f\0", (1-relaxRatio)); +// nMsgRelaxLen = sprintf(msgRelax,"S%0.2f\0", (1-relaxRatio)); // nMsgLen = sprintf(msg,"R%0.2f\0", relaxRatio); // ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), (uint8_t*)msg, nMsgLen); @@ -772,7 +777,7 @@ conRatio = averageConRatio; conRatio = 1 - conRatio; - nMsgConcentrationLen = sprintf(msgConcentration,"C%0.2f\0", conRatio); +// nMsgConcentrationLen = sprintf(msgConcentration,"C%0.2f\0", conRatio); // nMsgLen = sprintf(msg,"C%0.2f\0", conRatio); // ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), (uint8_t*)msg, nMsgLen); @@ -884,7 +889,7 @@ // happyRatio = averageStressRatio ;// @@@ - nMsgHappyLen = sprintf(msgHappy,"H%0.2f\0", happyRatio); +// nMsgHappyLen = sprintf(msgHappy,"H%0.2f\0", happyRatio); // nMsgLen = sprintf(msg,"H%0.2f\0", happyRatio); // ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), (uint8_t*)msg, nMsgLen); @@ -941,9 +946,18 @@ // printf("R%d\n", rval); // printf("C%d\n", cval); - sprintf(msg,"%s%s%s%s\0", msgIBI, msgHappy, msgRelax, msgConcentration); +// sprintf(msg,"%s%s%s%s\0", msgIBI, msgHappy, msgRelax, msgConcentration); + + float relaxRatioFloat = float(1-relaxRatio); + + memcpy(msg, msgHeader, sizeof(msgHeader)); + memcpy(&(msg[ 3]), &IBI , sizeof(IBI) ); + memcpy(&(msg[ 7]), &happyRatio , sizeof(happyRatio)); + memcpy(&(msg[11]), &relaxRatioFloat, sizeof(relaxRatioFloat)); + memcpy(&(msg[15]), &conRatio , sizeof(conRatio) ); ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), - (uint8_t*)msg, nMsgIBILen + nMsgHappyLen + nMsgRelaxLen + nMsgConcentrationLen); + (uint8_t*)msg, sizeof(msg)); +// (uint8_t*)msg, nMsgIBILen + nMsgHappyLen + nMsgRelaxLen + nMsgConcentrationLen); // (uint8_t*)msg, nMsgIBILen + 1 + nMsgHappyLen + 1 + nMsgRelaxLen + 1 + nMsgConcentrationLen); // determine color range