adding BLECentralCharacteritic, add hid_camerashutter sketch

This commit is contained in:
hathach committed 2017-03-22 13:38:22 +07:00
1 parent b710d6f056
commit 6f0e361b8f
12 files changed
+242 -37

No files matched your search

@@ -0,0 +1,117 @@
/*********************************************************************
This is an example for our nRF52 based Bluefruit LE modules
Pick one up today in the adafruit shop!
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
MIT license, check LICENSE for more information
All text above, and the splash screen below must be included in
any redistribution
*********************************************************************/
/*
* Sketch use HID Consumer Key API to send Volume Down key when
* PIN_SHUTTER is grounded. Which cause mobile to capture photo
* when you are in Camera App
*/
#include <bluefruit.h>
BLEDis bledis;
BLEHidAdafruit blehid;
#define PIN_SHUTTER 27
void setup()
{
pinMode(PIN_SHUTTER, INPUT_PULLUP);
Serial.begin(115200);
Serial.println("Bluefruit52 HID Camera Shutter Example");
Serial.println("--------------------------------------");
Serial.println();
Serial.println("Go to your phone's Bluetooth settings to pair your device");
Serial.println("then open an Camera application");
Serial.println();
Serial.printf("Wire your Pin %d to GND to capture picture\n", PIN_SHUTTER);
Serial.println();
Bluefruit.begin();
Bluefruit.setName("Bluefruit52");
// Configure and Start Device Information Service
bledis.setManufacturer("Adafruit Industries");
bledis.setModel("Bluefruit Feather 52");
bledis.begin();
/* Start BLE HID
* Note: Apple requires BLE device must have min connection interval >= 20m
* ( The smaller the connection interval the faster we could send data).
* However for HID and MIDI device, Apple could accept min connection interval
* up to 11.25 ms. Therefore BLEHidAdafruit::begin() will try to set the min and max
* connection interval to 11.25 ms and 15 ms respectively for best performance.
*/
blehid.begin();
/* Set connection interval (min, max) to your perferred value.
* Note: It is already set by BLEHidAdafruit::begin() to 11.25ms - 15ms
* min = 9*1.25=11.25 ms, max = 12*1.25= 15 ms
*/
/* Bluefruit.setConnInterval(9, 12); */
// Setup Advertising Packet
setupAdv();
// Start Advertising
Bluefruit.Advertising.start();
}
void setupAdv(void)
{
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
Bluefruit.Advertising.addTxPower();
Bluefruit.Advertising.addAppearance(BLE_APPEARANCE_HID_KEYBOARD);
// Include BLE HID service
Bluefruit.Advertising.addService(blehid);
// There is enough room for the dev name in the advertising packet
Bluefruit.Advertising.addName();
}
void loop()
{
// Connected and Bonded/Paired
if ( Bluefruit.connected() && Bluefruit.connBonded() )
{
// Pin is wired to GND
if ( digitalRead(PIN_SHUTTER) == 0 )
{
// Turn on LED Red when start sending
digitalWrite(LED_RED, 1);
// Send Volumn Down key press
// Check BLEHidGerneric.h for list of defined consumer usage code
blehid.consumerKeyPress(HID_USAGE_CONSUMER_VOLUME_DECREMENT);
// Delay a bit between repots
delay(10);
// Send key release
blehid.consumerKeyRelease();
// Turn off LED Red
digitalWrite(LED_RED, 0);
// Delay to avoid constant capturing
delay(500);
}
}
}
@@ -14,7 +14,6 @@
#include <bluefruit.h>
BLEDis bledis;
BLEUart bleuart;
BLEHidAdafruit blehid;
bool hasKeyPressed = false;
@@ -24,18 +23,24 @@ void setup()
Serial.begin(115200);
Serial.println("Bluefruit52 HID Keyboard Example");
Serial.println("--------------------------------");
Serial.println();
Serial.println("Go to your phone's Bluetooth settings to pair your device");
Serial.println("then open an application that accepts keyboard input");
Serial.println();
Serial.println("Enter the character(s) to send:");
Serial.println();
Bluefruit.begin();
Bluefruit.setName("Bluefruit52");
// Configure and Start Device Information Service
bledis.setManufacturer("Adafruit Industries");
bledis.setModel("Bluefruit Feather52");
bledis.setModel("Bluefruit Feather 52");
bledis.begin();
// Configure and Start BLE Uart Service
bleuart.begin();
/* Start BLE HID
* Note: Apple requires BLE device must have min connection interval >= 20m
* ( The smaller the connection interval the faster we could send data).
@@ -56,14 +61,6 @@ void setup()
// Start Advertising
Bluefruit.Advertising.start();
Serial.println();
Serial.println("Go to your phone's Bluetooth settings to pair your device");
Serial.println("then open an application that accepts keyboard input");
Serial.println();
Serial.println("Enter the character(s) to send:");
Serial.println();
}
void setupAdv(void)
@@ -14,7 +14,6 @@
#include <bluefruit.h>
BLEDis bledis;
BLEUart bleuart;
BLEHidAdafruit blehid;
#define MOVE_STEP 10
@@ -41,12 +40,9 @@ void setup()
// Configure and Start Device Information Service
bledis.setManufacturer("Adafruit Industries");
bledis.setModel("Bluefruit Feather52");
bledis.setModel("Bluefruit Feather 52");
bledis.begin();
// Configure and Start BLE Uart Service
bleuart.begin();
// BLE HID
blehid.begin();
+10
View File
@@ -186,6 +186,16 @@ notifyEnabled KEYWORD2
setRxCallback KEYWORD2
notifyEnabled KEYWORD2
#######################################
# Constants (LITERAL1)
#######################################
LED_RED LITERAL1
LED_BLUE LITERAL1
LED_BUILTIN LITERAL1
LED_CONN LITERAL1
#######################################
# Constants (LITERAL1)
#######################################
+1 -1
View File
@@ -1,5 +1,5 @@
name=Adafruit BLE Libraries for Bluefruit52
version=0.2.1
version=0.5.5
author=Adafruit
maintainer=Adafruit <info@adafruit.com>
sentence=Arduino library for nRF52-based Adafruit Bluefruit LE modules
@@ -41,6 +41,7 @@
#include "BLEUuid.h"
#include "BLECharacteristic.h"
#include "BLECentralCharacteristic.h"
#include "BLEService.h"
class AdafruitBluefruit;
@@ -0,0 +1,38 @@
/**************************************************************************/
/*!
@file BLECentralCharacteristic.cpp
@author hathach
@section LICENSE
Software License Agreement (BSD License)
Copyright (c) 2017, Adafruit Industries (adafruit.com)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**************************************************************************/
#include "bluefruit.h"
@@ -0,0 +1,52 @@
/**************************************************************************/
/*!
@file BLECentralCharacteristic.h
@author hathach
@section LICENSE
Software License Agreement (BSD License)
Copyright (c) 2017, Adafruit Industries (adafruit.com)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**************************************************************************/
#ifndef BLECHARACTERISTICCENTRAL_H_
#define BLECHARACTERISTICCENTRAL_H_
#include "bluefruit_common.h"
#include "BLEUuid.h"
#include "BLECharacteristic.h"
class BLECharacteristicCentral
{
public:
private:
ble_gattc_char_t _chr;
};
#endif /* BLECHARACTERISTICCENTRAL_H_ */
@@ -269,7 +269,7 @@ err_t BLECharacteristic::begin(void)
}
// Currently Only register to Bluefruit when having callback support
// And The Characteristic must not be temporary memory aka local variable
// And The Characteristic must not be temporary memory i.e local variable
if ( !_is_temp &&
(_rd_authorize_cb || _wr_authorize_cb || _wr_cb || _cccd_wr_cb) )
{
@@ -115,15 +115,12 @@ class BLECharacteristic
BLECharacteristic(void);
BLECharacteristic(BLEUuid bleuuid);
BLEService& parentService()
{
return *_service;
}
BLEService& parentService() { return *_service; }
void setUuid(BLEUuid bleuuid);
void setTempMemory(void);
// Configure
/*------------- Configure -------------*/
void setUuid(BLEUuid bleuuid);
void setProperties(uint8_t prop);
void setPermission(BleSecurityMode read_perm, BleSecurityMode write_perm);
void setMaxLen(uint16_t max_len);
@@ -131,10 +128,9 @@ class BLECharacteristic
void setStringDescriptor(const char* descriptor); // aka user descriptor
void setReportRefDescriptor(uint8_t id, uint8_t type);
// Callback
/*------------- Callback -------------*/
void setWriteCallback(write_cb_t fp);
void setCccdWriteCallback(write_cccd_cb_t fp);
void setReadAuthorizeCallback(read_authorize_cb_t fp);
void setWriteAuthorizeCallbak(write_authorize_cb_t fp);
@@ -142,7 +138,7 @@ class BLECharacteristic
ble_gatts_char_handles_t handles(void);
// Write
/*------------- Write -------------*/
err_t write(const void* data, int len, uint16_t offset = 0);
err_t write(const char * str);
@@ -151,26 +147,23 @@ class BLECharacteristic
err_t write(uint16_t num);
err_t write(uint8_t num);
// Read
/*------------- Read -------------*/
uint16_t read(void* buffer, int bufsize, uint16_t offset = 0);
uint16_t read(uint32_t* num);
uint16_t read(uint16_t* num);
uint16_t read(uint8_t* num);
// Notify
/*------------- Notify -------------*/
bool notifyEnabled(void);
err_t notify(const void* data, int len, uint16_t offset);
err_t notify(const void* data, int len);
err_t notify(const char * str);
err_t notify(int num);
err_t notify(uint32_t num);
err_t notify(uint16_t num);
err_t notify(uint8_t num);
friend class AdafruitBluefruit;
};
+3 -2
View File
@@ -41,7 +41,9 @@
#include "BLEAdvertising.h"
#include "BLECharacteristic.h"
#include "BLEService.h"
#include "BLECentral.h"
#include "BLECentralCharacteristic.h"
// Services
#include "services/BLEDis.h"
@@ -146,9 +148,8 @@ class AdafruitBluefruit
uint16_t _conn_hdl;
bool _bonded;
// TODO move to bonding place
public: // temporary
public: // TODO temporary for bledfu to load bonding data
struct
{
// Keys
+1 -1
View File
@@ -17,7 +17,7 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
name=Adafruit Boards
version=0.5.1
version=0.5.5
# Compile variables
# -----------------