add throughput close #17
- add notifyEnabled() for BLEUART - rename MIDI configured() to notifyEnabled() - add macro ARUDINO_BSP_VERSION for currnet libraries version, to use with FirmwareRev in BLEDIS
This commit is contained in:
1 parent
2efe5dcbc1
commit
12ca4c0a28
10 files changed
+180
-9
No files matched your search
@@ -42,7 +42,7 @@ void setup()
|
||||
bledis.setManufacturer("Adafruit Industries");
|
||||
bledis.setModel("Bluefruit Feather 52");
|
||||
bledis.setHardwareRev("Rev E");
|
||||
bledis.setFirmwareRev("0.1.0");
|
||||
bledis.setFirmwareRev(ARUDINO_BSP_VERSION); // ARUDINO_BSP_VERSION is BSP Libraries version
|
||||
bledis.start();
|
||||
|
||||
/* Start BLE MIDI
|
||||
@@ -91,7 +91,7 @@ void midi_write_callback(uint32_t tstamp, uint8_t data[])
|
||||
|
||||
void loop()
|
||||
{
|
||||
if ( Bluefruit.connected() && blemidi.configured() )
|
||||
if ( Bluefruit.connected() && blemidi.notifyEnabled() )
|
||||
{
|
||||
static int current_note = 60;
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ void setup()
|
||||
bledis.setManufacturer("Adafruit Industries");
|
||||
bledis.setModel("Bluefruit Feather 52");
|
||||
bledis.setHardwareRev("Rev E");
|
||||
bledis.setFirmwareRev("0.1.0");
|
||||
bledis.setFirmwareRev(ARUDINO_BSP_VERSION); // ARUDINO_BSP_VERSION is BSP Libraries version
|
||||
bledis.start();
|
||||
|
||||
// Configure and Start BLE Uart Service
|
||||
@@ -65,7 +65,6 @@ void setup()
|
||||
|
||||
void setupAdv(void)
|
||||
{
|
||||
//Bluefruit.addAdvTxPower();
|
||||
Bluefruit.addAdvFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
|
||||
Bluefruit.addAdvTxPower();
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ void setup()
|
||||
bledis.setManufacturer("Adafruit Industries");
|
||||
bledis.setModel("Bluefruit Feather 52");
|
||||
bledis.setHardwareRev("Rev E");
|
||||
bledis.setFirmwareRev("0.1.0");
|
||||
bledis.setFirmwareRev(ARUDINO_BSP_VERSION); // ARUDINO_BSP_VERSION is BSP Libraries version
|
||||
bledis.start();
|
||||
|
||||
// Configure and Start BLE Uart Service
|
||||
|
||||
@@ -37,7 +37,7 @@ void setup()
|
||||
bledis.setManufacturer("Adafruit Industries");
|
||||
bledis.setModel("Bluefruit Feather 52");
|
||||
bledis.setHardwareRev("Rev E");
|
||||
bledis.setFirmwareRev("0.1.0");
|
||||
bledis.setFirmwareRev(ARUDINO_BSP_VERSION); // ARUDINO_BSP_VERSION is BSP Libraries version
|
||||
bledis.start();
|
||||
|
||||
// Configure and Start BLE Uart Service
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
/*********************************************************************
|
||||
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
|
||||
*********************************************************************/
|
||||
|
||||
#include <bluefruit.h>
|
||||
|
||||
// String to send in the throughput test
|
||||
#define TEST_STRING "01234567899876543210"
|
||||
const int TEST_STRLEN = strlen(TEST_STRING);
|
||||
|
||||
// Number of total data sent ( 1024 times the test string)
|
||||
#define TOTAL_BYTES (1024 * strlen(TEST_STRING))
|
||||
|
||||
BLEDis bledis;
|
||||
BLEUart bleuart;
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets up the HW an the BLE module (this function is called
|
||||
automatically on startup)
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void setup(void)
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println("Bluefruit52 Throughput Example");
|
||||
|
||||
// Setup the BLE LED to be enabled on CONNECT
|
||||
// Note: This is actually the default behaviour, but provided
|
||||
// here in case you want to control this manually via PIN 19
|
||||
Bluefruit.autoConnLed(true);
|
||||
|
||||
Bluefruit.begin();
|
||||
Bluefruit.setName("Bluefruit52");
|
||||
Bluefruit.setConnectCallback(connect_callback);
|
||||
Bluefruit.setDisconnectCallback(disconnect_callback);
|
||||
|
||||
// Configure and Start Device Information Service
|
||||
bledis.setManufacturer("Adafruit Industries");
|
||||
bledis.setModel("Bluefruit Feather 52");
|
||||
bledis.setHardwareRev("Rev E");
|
||||
bledis.setFirmwareRev(ARUDINO_BSP_VERSION); // ARUDINO_BSP_VERSION is BSP Libraries version
|
||||
bledis.start();
|
||||
|
||||
// Configure and Start BLE Uart Service
|
||||
bleuart.start();
|
||||
|
||||
// Set up Advertising Packet
|
||||
setupAdv();
|
||||
|
||||
// Start Advertising
|
||||
Bluefruit.startAdvertising();
|
||||
}
|
||||
|
||||
void setupAdv(void)
|
||||
{
|
||||
Bluefruit.addAdvFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
|
||||
Bluefruit.addAdvTxPower();
|
||||
|
||||
// Include bleuart 128-bit uuid
|
||||
Bluefruit.addAdvService(bleuart);
|
||||
|
||||
// There is no room for Name in Advertising packet
|
||||
// Use Scan response for Name
|
||||
Bluefruit.addScanRespName();
|
||||
}
|
||||
|
||||
void connect_callback(void)
|
||||
{
|
||||
Serial.println("Connected");
|
||||
}
|
||||
|
||||
void disconnect_callback(uint8_t reason)
|
||||
{
|
||||
(void) reason;
|
||||
|
||||
Serial.println();
|
||||
Serial.println("Disconnected");
|
||||
Serial.println("Bluefruit will auto start advertising (default)");
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Constantly poll for new command or response data
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void loop(void)
|
||||
{
|
||||
uint32_t start, stop, sent;
|
||||
uint32_t remaining = TOTAL_BYTES;
|
||||
start = stop = sent = 0;
|
||||
|
||||
if (Bluefruit.connected() && bleuart.notifyEnabled())
|
||||
{
|
||||
// Wait for user input before trying again
|
||||
Serial.println("Connected. Send a key and press enter to start test");
|
||||
getUserInput();
|
||||
|
||||
Serial.print("Sending ");
|
||||
Serial.print(remaining);
|
||||
Serial.println(" bytes ...");
|
||||
|
||||
start = millis();
|
||||
while (remaining > 0)
|
||||
{
|
||||
bleuart.print(TEST_STRING);
|
||||
|
||||
sent += TEST_STRLEN;
|
||||
remaining -= TEST_STRLEN;
|
||||
|
||||
// Only print every 100th time
|
||||
// if ( (sent % (100*TEST_STRLEN) ) == 0 )
|
||||
// {
|
||||
// Serial.print("Sent: "); Serial.print(sent);
|
||||
// Serial.print(" Remaining: "); Serial.println(remaining);
|
||||
// }
|
||||
}
|
||||
stop = millis() - start;
|
||||
|
||||
Serial.print("Sent ");
|
||||
Serial.print(sent);
|
||||
Serial.print(" bytes in ");
|
||||
Serial.print(stop / 1000.0F, 2);
|
||||
Serial.println(" seconds.");
|
||||
|
||||
Serial.println("Speed ");
|
||||
Serial.print( (sent / 1000.0F) / (stop / 1000.0F), 2);
|
||||
Serial.println(" KB/s.\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Get user input from Serial
|
||||
*/
|
||||
/**************************************************************************/
|
||||
char* getUserInput(void)
|
||||
{
|
||||
static char inputs[64+1];
|
||||
memset(inputs, 0, sizeof(inputs));
|
||||
|
||||
// wait until data is available
|
||||
while( Serial.available() == 0 ) { delay(1); }
|
||||
|
||||
uint8_t count=0;
|
||||
do
|
||||
{
|
||||
count += Serial.readBytes(inputs+count, 64);
|
||||
} while( (count < 64) && Serial.available() );
|
||||
|
||||
return inputs;
|
||||
}
|
||||
@@ -120,7 +120,7 @@ BLEMidi::BLEMidi(void)
|
||||
_write_cb = NULL;
|
||||
}
|
||||
|
||||
bool BLEMidi::configured()
|
||||
bool BLEMidi::notifyEnabled(void)
|
||||
{
|
||||
return Bluefruit.connBonded() && _io.notifyEnabled();
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ class BLEMidi: public BLEService
|
||||
|
||||
virtual err_t start(void);
|
||||
|
||||
bool configured();
|
||||
bool notifyEnabled(void);
|
||||
|
||||
err_t send(uint8_t data[]);
|
||||
err_t send(uint8_t status, uint8_t byte1, uint8_t byte2);
|
||||
|
||||
@@ -114,6 +114,11 @@ err_t BLEUart::start(void)
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
bool BLEUart::notifyEnabled(void)
|
||||
{
|
||||
return _txd.notifyEnabled();
|
||||
}
|
||||
|
||||
int BLEUart::read (void)
|
||||
{
|
||||
uint8_t ch;
|
||||
|
||||
@@ -56,6 +56,8 @@ class BLEUart : public BLEService, public Stream
|
||||
|
||||
virtual err_t start(void);
|
||||
|
||||
bool notifyEnabled(void);
|
||||
|
||||
void setRxCallback( rx_callback_t fp);
|
||||
|
||||
// Stream API
|
||||
@@ -67,6 +69,9 @@ class BLEUart : public BLEService, public Stream
|
||||
virtual int peek ( void );
|
||||
virtual void flush ( void );
|
||||
|
||||
// pull in write(str) and write(buf, size) from Print
|
||||
using Print::write;
|
||||
|
||||
protected:
|
||||
BLECharacteristic _txd;
|
||||
BLECharacteristic _rxd;
|
||||
|
||||
+1
-1
@@ -76,7 +76,7 @@ compiler.elf2hex.extra_flags=
|
||||
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {build.debug_flags} {compiler.nrf.flags} {includes} {nffs.includes} "{source_file}" -o "{object_file}"
|
||||
|
||||
## Compile c++ files
|
||||
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {build.debug_flags} {compiler.nrf.flags} {includes} {nffs.includes} "{source_file}" -o "{object_file}"
|
||||
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARUDINO_BSP_VERSION="{version}" {compiler.cpp.extra_flags} {build.extra_flags} {build.debug_flags} {compiler.nrf.flags} {includes} {nffs.includes} "{source_file}" -o "{object_file}"
|
||||
|
||||
## Compile S files
|
||||
recipe.S.o.pattern="{compiler.path}{compiler.S.cmd}" {compiler.S.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.S.extra_flags} {build.extra_flags} {build.debug_flags} {includes} {nffs.includes} "{source_file}" -o "{object_file}"
|
||||
|
||||
Reference in new issue
Block a user