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 nRF51_Vdd
Fork of BLE_Temp_Vdd_via_UART by
Diff: main.cpp
- Revision:
- 11:da2dc9a847a8
- Parent:
- 10:38852d243fb2
- Child:
- 12:4d8a543135be
--- a/main.cpp Sun Jan 24 04:21:09 2016 +0000
+++ b/main.cpp Tue Feb 09 12:21:41 2016 +0000
@@ -16,7 +16,7 @@
/*
* January 6th, 2016 Modified by Kenji Arai
- * January 24th, 2016
+ * Feburary 9th, 2016
* http://www.page.sannet.ne.jp/kenjia/index.html
* http://mbed.org/users/kenjiArai/
*
@@ -41,17 +41,27 @@
#include "nRF51_Vdd.h" // Read nRF51 Vdd voltage
// Definition ------------------------------------------------------------------------------------
+#define NEED_CONSOLE_OUTPUT 0 // Set this if you need debug messages on the console;
+
+#if NEED_CONSOLE_OUTPUT
+#define DEBUG(...) { pc.printf(__VA_ARGS__); }
+#else
+#define DEBUG(...) /* nothing */
+#endif
// Object ----------------------------------------------------------------------------------------
BLE ble;
UARTService *uart;
-nRF51_Vdd vdd(3.6f, 2.6f);
+nRF51_Vdd vdd(3.0f, 2.2f); // CR2032 3V-2.2V (http://rbs.ta36.com/?p=20398#CR2032)
+#if NEED_CONSOLE_OUTPUT
+Serial pc(USBTX,USBRX);
+#endif
// RAM -------------------------------------------------------------------------------------------
static volatile bool triggerSensorPolling = false;
// ROM / Constant data ---------------------------------------------------------------------------
-const char *deviceName = "mbedBLE";
+const char *deviceName = "mbedTY";
// Function prototypes ---------------------------------------------------------------------------
void Update_Values(void);
@@ -76,8 +86,8 @@
Ticker ticker;
ticker.attach(periodicCallback, 5);
// Opening screen
- printf("\r\nInitialising the nRF51822\r\n");
- printf("Temperature and CPU Vdd voltage via UART service\r\n");
+ DEBUG("\r\nInitialising the nRF51822\r\n");
+ DEBUG("Temperature and CPU Vdd voltage via UART service\r\n");
// setup BLE
ble.init();
ble.setDeviceName((const uint8_t *)deviceName);
@@ -85,6 +95,7 @@
// BLE Uart
uart = new UARTService(ble);
// setup advertising
+ ble.gap().setTxPower(-40);
ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
@@ -105,6 +116,18 @@
}
}
+void fill_space(char *bf){
+ uint8_t n;
+
+ n = strlen(bf);
+ bf += n;
+ for (uint8_t i = n; i <= 18; bf++, i++){
+ *bf = ' ';
+ }
+ *bf = '.';
+ *(bf + 1) = 0;
+}
+
void Update_Values(void){
char buf[32];
int32_t p_temp;
@@ -112,24 +135,28 @@
// Update a temperature (inside nRF51822 chip)
sd_temp_get(&p_temp);
- temperature = float(p_temp)/4.0f - 16.0f;
+ // -16.0f is offset vale for chip die temp to ambient temp (depend on your board)
+ temperature = float(p_temp) / 4; // Original = float(p_temp)/4.0f - 16.0f;
// 12 89
- sprintf(buf,"T:%+4.1fdC", temperature);
+ sprintf(buf,"T:%+4.1fdegC", temperature);
+ fill_space(buf);
if (uart){
uart->writeString(buf);
}
- printf(buf);
+ DEBUG("%s\b\r\n", buf);
// Update a Vdd voltage
// 01234 9
- sprintf(buf,",Vdd:%3.2fV ", vdd.read_real_value());
+ sprintf(buf,"Vdd:%3.2fV", vdd.read_real_value());
+ fill_space(buf);
if (uart){
uart->writeString(buf);
}
- printf(buf);
+ DEBUG("%s\b\r\n", buf);
// 123456789 0
- sprintf(buf,"Charge:%d%% \r\n", vdd.read());
+ sprintf(buf,"Charge:%d%%", vdd.read());
+ fill_space(buf);
if (uart){
uart->writeString(buf);
}
- printf(buf);
+ DEBUG("%s\b\r\n", buf);
}
