Hiroh Satoh / keyboard Featured

Dependencies:   BLE_API mbed-dev nRF51822

Revision:
3:266dfa9f8709
Parent:
2:c2e3f240640c
Child:
4:54cb552e50c4
--- a/main.cpp	Mon Jul 18 09:23:15 2016 +0900
+++ b/main.cpp	Tue Jul 19 01:06:00 2016 +0900
@@ -48,6 +48,20 @@
 // I2C i2c(D2, D3);
 AnalogIn batteryInput(A4);
 
+void updateBatteryLevel() {
+	if (!batteryService) return;
+	static const float BATTERY_MAX = 2.4;
+
+	float batteryVoltage = batteryInput.read() * 1.2 * 3;
+	float percentage = (batteryVoltage / BATTERY_MAX) * 100;
+	if (percentage > 100) {
+		percentage = 100;
+	}
+	printf("updateBatteryLevel %d\r\n",static_cast<uint8_t>(percentage));
+	batteryService->updateBatteryLevel(static_cast<uint8_t>(percentage));
+}
+
+
 static void onConnect(const Gap::ConnectionCallbackParams_t *params) {
 	printf("onConnect\r\n");
 }
@@ -110,7 +124,8 @@
 
 	keyboardService = new KeyboardService(ble);
 	deviceInformationService = new DeviceInformationService(ble, "lowreal.net", MODEL_NAME, SERIAL_NUMBER, HARDWARE_REVISION, FIRMWARE_REVISION, SOFTWARE_REVISION);
-	batteryService = new BatteryService(ble, 10);
+	batteryService = new BatteryService(ble, 100);
+	updateBatteryLevel();
 
 	printf("general setup\r\n");
 	error = ble.gap().accumulateAdvertisingPayload(
@@ -178,18 +193,6 @@
 	send_string("hello world!\n");
 }
 
-void updateBatteryLevel() {
-	if (!batteryService) return;
-	static const float BATTERY_MAX = 2.4;
-
-	float batteryVoltage = batteryInput.read() * 1.2 * 3;
-	float percentage = (batteryVoltage / BATTERY_MAX) * 100;
-	if (percentage > 100) {
-		percentage = 100;
-	}
-	batteryService->updateBatteryLevel(static_cast<uint8_t>(percentage));
-}
-
 int main(void) {
 	// Use internal 1.2V reference for batteryInput
 	//	1/3 pre-scaled input and 1.2V internal band gap reference
@@ -201,7 +204,6 @@
 		(ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos) |
 		(ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos);
 
-
 	// https://github.com/jpbrucker/BLE_HID/blob/master/examples/examples_common.cpp
 
 	printf("ble.init\r\n");