summaryrefslogtreecommitdiff
path: root/tmk_core/protocol/lufa
diff options
context:
space:
mode:
authorbwhelm <bwhelm@users.noreply.github.com>2019-09-03 14:29:23 -0400
committerFlorian Didron <fdidron@users.noreply.github.com>2019-09-26 10:08:39 +0900
commitb39dbc0342a32cb73f3460534d3e33e2d29f5a9e (patch)
tree76cb3a4156e9ff1d319cb8cf9bbf4bc9aac691ee /tmk_core/protocol/lufa
parent6e2424e6581d70d2c9e1f98ed42624d59b83bce0 (diff)
Fix battery level code in adafruit_ble.cpp (#6648)
* Fix battery level code in adafruit_ble.cpp The code in tsk_core/protocol/lufa/adafluit_ble.cpp that polls the battery level for the Adafruit feather BLE controller reads the regulated voltage, not the raw voltage coming from the battery. To do that, the Adafruit Feather docs say you should read from pin A9: https://learn.adafruit.com/adafruit-feather-32u4-basic-proto/power-management#measuring-battery-4-9. (See also https://learn.adafruit.com/adafruit-feather-32u4-bluefruit-le/pinouts#logic-pins-2-9.) I'm not sure why, but analogRead(9); doesn't read the correct pin. Checking all available analog pins experimentally, it turns out that analogRead(7); returns the correct value. So the code above should read: state.vbat = analogRead(7); * Update tmk_core/protocol/lufa/adafruit_ble.cpp Co-Authored-By: Drashna Jaelre <drashna@live.com> * Remove old comment * Fix linking error * Remove `#ifdef` around `#include analog.h`. * Really fix linking error
Diffstat (limited to 'tmk_core/protocol/lufa')
-rw-r--r--tmk_core/protocol/lufa/adafruit_ble.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/tmk_core/protocol/lufa/adafruit_ble.cpp b/tmk_core/protocol/lufa/adafruit_ble.cpp
index 71d0936f8f..1d8ae1038b 100644
--- a/tmk_core/protocol/lufa/adafruit_ble.cpp
+++ b/tmk_core/protocol/lufa/adafruit_ble.cpp
@@ -10,6 +10,7 @@
#include "action_util.h"
#include "ringbuffer.hpp"
#include <string.h>
+#include "analog.h"
// These are the pin assignments for the 32u4 boards.
// You may define them to something else in your config.h
@@ -29,6 +30,12 @@
#define SAMPLE_BATTERY
#define ConnectionUpdateInterval 1000 /* milliseconds */
+#ifdef SAMPLE_BATTERY
+#ifndef BATTERY_LEVEL_PIN
+# define BATTERY_LEVEL_PIN 7
+#endif
+#endif
+
static struct {
bool is_connected;
bool initialized;
@@ -631,15 +638,10 @@ void adafruit_ble_task(void) {
}
#ifdef SAMPLE_BATTERY
- // I don't know if this really does anything useful yet; the reported
- // voltage level always seems to be around 3200mV. We may want to just rip
- // this code out.
if (timer_elapsed(state.last_battery_update) > BatteryUpdateInterval && resp_buf.empty()) {
state.last_battery_update = timer_read();
- if (at_command_P(PSTR("AT+HWVBAT"), resbuf, sizeof(resbuf))) {
- state.vbat = atoi(resbuf);
- }
+ state.vbat = analogRead(BATTERY_LEVEL_PIN);
}
#endif
}