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-dev nRF51822
Revision 27:7370b8994603, committed 2016-08-22
- Comitter:
- cho45
- Date:
- Mon Aug 22 23:14:42 2016 +0000
- Parent:
- 26:78ee13f69ec3
- Child:
- 28:1f843a3daab0
- Commit message:
- ??? Ticker ???????????????????
Changed in this revision
--- a/HIDController_BLE.cpp Mon Aug 22 22:50:25 2016 +0000
+++ b/HIDController_BLE.cpp Mon Aug 22 23:14:42 2016 +0000
@@ -31,7 +31,9 @@
static DFUService* dfuService;
static BLEProtocol::Address_t peerAddress;
-static volatile bool connected = false;
+
+
+static volatile Status_t controllerStatus;
static void updateBatteryLevel() {
if (!batteryService) return;
@@ -85,17 +87,18 @@
peerAddress.type = params->peerAddrType;
memcpy(peerAddress.address, params->peerAddr, Gap::ADDR_LEN);
+ controllerStatus = CONNECTING;
}
static void onDisconnect(const Gap::DisconnectionCallbackParams_t *params) {
printf("onDisconnect\r\n");
- connected = false;
+ controllerStatus = DISCONNECTED;
BLE::Instance(BLE::DEFAULT_INSTANCE).gap().startAdvertising();
}
static void onTimeout(const Gap::TimeoutSource_t source) {
printf("onTimeout\r\n");
- connected = false;
+ controllerStatus = DISCONNECTED;
BLE::Instance(BLE::DEFAULT_INSTANCE).gap().startAdvertising();
}
@@ -122,7 +125,7 @@
// BLE::Instance(BLE::DEFAULT_INSTANCE).gap().setAdvertisingPolicyMode(Gap::ADV_POLICY_FILTER_SCAN_REQS);
// BLE::Instance(BLE::DEFAULT_INSTANCE).gap().setAdvertisingPolicyMode(Gap::ADV_POLICY_FILTER_CONN_REQS);
BLE::Instance(BLE::DEFAULT_INSTANCE).gap().setAdvertisingPolicyMode(Gap::ADV_POLICY_FILTER_ALL_REQS);
- connected = true;
+ controllerStatus = CONNECTED;
} else {
printf("Security failed %d\r\n", status);
}
@@ -137,7 +140,7 @@
ble_error_t error;
BLE &ble = params->ble;
- connected = false;
+ controllerStatus = DISCONNECTED;
/**< Minimum Connection Interval in 1.25 ms units, see BLE_GAP_CP_LIMITS.*/
uint16_t minConnectionInterval = Gap::MSEC_TO_GAP_DURATION_UNITS(24);
@@ -252,7 +255,11 @@
}
bool HIDController::connected() {
- return connected;
+ return controllerStatus == CONNECTED;
+}
+
+Status_t HIDController::status() {
+ return controllerStatus;
}
void HIDController::init() {
--- a/HIDController_BLE.h Mon Aug 22 22:50:25 2016 +0000
+++ b/HIDController_BLE.h Mon Aug 22 23:14:42 2016 +0000
@@ -1,8 +1,17 @@
+
+enum Status_t {
+ DISCONNECTED,
+ CONNECTING,
+ CONNECTED,
+} ;
+
+
class HIDController {
public:
static void init();
static void waitForEvent();
static bool connected();
+ static Status_t HIDController::status();
static void appendReportData(uint8_t key);
static void deleteReportData(uint8_t key);
static void queueCurrentReportData();
--- a/main.cpp Mon Aug 22 22:50:25 2016 +0000
+++ b/main.cpp Mon Aug 22 23:14:42 2016 +0000
@@ -220,7 +220,7 @@
// (pulled-up and two MCP23017 is configured with open drain INT)
InterruptIn buttonInt(P0_5);
-Ticker ticker;
+// Ticker ticker;
DigitalOut statusLed(P0_4, 1);
@@ -263,9 +263,6 @@
// DO NOT CONNECT RTS/CTS AUTOMATICALY!
NRF_UART0->PSELRTS = 0xFFFFFFFFUL;
NRF_UART0->PSELCTS = 0xFFFFFFFFUL;
-
- ticker.attach(tickerStatus, 1);
-
// 100kHz
i2c.frequency(100000);
@@ -284,7 +281,18 @@
NRF_TWI0->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos;
+ // ticker.attach(tickerStatus, 0.5);
while (1) {
+ /*
+ ticker.detach();
+ switch (HIDController::status()) {
+ case DISCONNECTED: ticker.attach(tickerStatus, 1); break;
+ case CONNECTING: ticker.attach(tickerStatus, 2); break;
+ case CONNECTED: ticker.attach(tickerStatus, 60);break;
+ }
+ */
+
+
if (pollCount > 0) {
printf("scan keys\r\n");
while (pollCount -- > 0) {