Skip to content
This repository was archived by the owner on Feb 21, 2020. It is now read-only.

Ble led #25

Merged
merged 2 commits into from
Apr 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions cores/arduino/wiring_digital.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void pinMode( uint32_t ulPin, uint32_t ulMode )

if ( (ulPin == 34) && (ulMode == STM32_IT) )
{
delay(15);
nrf_delay_ms(15);
TwoWire_begin();
TwoWire_beginTransmission(0x48);
TwoWire_write(GPIO_USER1_IT);
Expand Down Expand Up @@ -278,7 +278,7 @@ void digitalWrite( uint32_t ulPin, uint32_t ulVal )
switch ( ulPin )
{
case 38:
delay(15);
nrf_delay_ms(15);
if(ulVal == HIGH)
{
TwoWire_begin();
Expand All @@ -296,7 +296,7 @@ void digitalWrite( uint32_t ulPin, uint32_t ulVal )
break ;

case 39:
delay(15);
nrf_delay_ms(15);
if(ulVal == HIGH)
{
TwoWire_begin();
Expand All @@ -314,7 +314,7 @@ void digitalWrite( uint32_t ulPin, uint32_t ulVal )
break ;

case 40:
delay(15);
nrf_delay_ms(15);
if(ulVal == HIGH)
{
TwoWire_begin();
Expand All @@ -332,7 +332,7 @@ void digitalWrite( uint32_t ulPin, uint32_t ulVal )
break ;

case 41:
delay(15);
nrf_delay_ms(15);
if(ulVal == HIGH)
{
TwoWire_begin();
Expand All @@ -350,7 +350,7 @@ void digitalWrite( uint32_t ulPin, uint32_t ulVal )
break ;

case 42:
delay(15);
nrf_delay_ms(15);
if(ulVal == HIGH)
{
TwoWire_begin();
Expand Down Expand Up @@ -396,12 +396,12 @@ int digitalRead( uint32_t ulPin )
switch ( ulPin )
{
case 44:
delay(15);
nrf_delay_ms(15);
TwoWire_begin();
TwoWire_beginTransmission(0x48);
TwoWire_write(USER2_BUTTON_IN);
TwoWire_endTransmission();
delay(15);
nrf_delay_ms(15);
TwoWire_requestFrom(0x48, 2, true);
char c = TwoWire_read();
if (c == 0xC3)
Expand Down
11 changes: 10 additions & 1 deletion libraries/BLE/BLECentralRole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
BLECentralRole::BLECentralRole() :
_messageEventHandler(NULL),

_status(DISCONNECT),

_localAttributes(NULL),
_numLocalAttributes(0),
_remoteAttributes(NULL),
Expand Down Expand Up @@ -224,6 +226,10 @@ void BLECentralRole::allowMultilink(uint8_t linksNo){
_allowedPeripherals = linksNo;
}

BLEStatus BLECentralRole::status(){
return _status;
}

void BLECentralRole::setBondStore(BLEBondStore& bondStore){
this->_bondStore = bondStore;
}
Expand Down Expand Up @@ -604,7 +610,7 @@ void BLECentralRole::begin(){
}

this->startScan();

this->_status = SCANNING;
}

void BLECentralRole::poll(ble_evt_t *bleEvt){
Expand All @@ -627,6 +633,7 @@ void BLECentralRole::poll(ble_evt_t *bleEvt){
}
break;
case BLE_GAP_EVT_CONNECTED:
_status = CONNECT;
uint8_t index;
//save the handler in the first free location
for(index = 0; index < _allowedPeripherals; index++)
Expand Down Expand Up @@ -685,6 +692,7 @@ void BLECentralRole::poll(ble_evt_t *bleEvt){
break;
case BLE_GAP_EVT_DISCONNECTED:
uint8_t currentPeripheral;
this->_status = DISCONNECT;
for(currentPeripheral = 0; currentPeripheral < _allowedPeripherals; currentPeripheral++)
if(this->_connectionHandle[currentPeripheral] == bleEvt->evt.gap_evt.conn_handle)
break;
Expand Down Expand Up @@ -712,6 +720,7 @@ void BLECentralRole::poll(ble_evt_t *bleEvt){

this->_remoteRequestInProgress = false;
this->startScan();
this->_status = SCANNING;
break;

case BLE_GAP_EVT_CONN_PARAM_UPDATE:
Expand Down
4 changes: 4 additions & 0 deletions libraries/BLE/BLECentralRole.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class BLECentralRole : public BLECharacteristicValueChangeListener,
void disconnect();

void allowMultilink(uint8_t linksNo);

BLEStatus status();

void setBondStore(BLEBondStore& bondStore);
void enableBond(BLEBondingType type = JUST_WORKS);
Expand Down Expand Up @@ -138,6 +140,8 @@ class BLECentralRole : public BLECharacteristicValueChangeListener,
uint16_t valueHandle;
};

BLEStatus _status;

short _scanInterval = 0x0004;
short _scanWindow = 0x0004;
short _scanTimeout = 0;
Expand Down
1 change: 1 addition & 0 deletions libraries/BLE/BLEDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ BLEDevice::BLEDevice() :
_lesc(0),
_io_caps(BLE_GAP_IO_CAPS_NONE),
_passkey({0,0,0,0,0,0}),
_status(1),
_userConfirm(false)
{
}
Expand Down
2 changes: 2 additions & 0 deletions libraries/BLE/BLEDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ class BLEDevice
bool _userConfirm;
BLEBondStore* _bondStore;
BLEDeviceEventListener* _eventListener;
uint8_t _status;

};

#endif
4 changes: 4 additions & 0 deletions libraries/BLE/BLEPeripheral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ bool BLEPeripheral::connected() {
return this->_central;
}

BLEStatus BLEPeripheral::status(){
return (BLEStatus)this->_device->_status;
}

void BLEPeripheral::printBleMessage(int eventCode, int messageCode){
if(eventCode > sizeof(this->_evt_code_to_string))
return;
Expand Down
9 changes: 9 additions & 0 deletions libraries/BLE/BLEPeripheral.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ enum BLEBondingType {
LESC_CONFIRM_PASSKEY = 6
};

enum BLEStatus {
CONNECT = 0,
DISCONNECT,
ADVERTISING,
SCANNING
};

typedef void (*BLEPeripheralEventHandler)(BLECentral& central);
typedef void (*BLEMessageEventHandler)(int eventNo, int messageCode);

Expand Down Expand Up @@ -108,6 +115,8 @@ class BLEPeripheral : public BLEDeviceEventListener,

BLECentral central();
bool connected();

BLEStatus status();

void printBleMessage(int eventCode, int messageCode);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
Use the complementary example showPasskey.ino in File->Examples->BLE->Peripheral->Bonding
to test this feature.

In this example BLE_LED shows the status of the board. It will blink every 200 ms when the board is scanning.
It will be on when the board is connected to a peripheral. It will be off when the board is disconnected.

This example code is in the public domain.
*/

Expand All @@ -27,6 +30,9 @@ BLERemoteCharacteristic dummyRemoteCharacteristic = BLERemote
void setup() {
Serial.begin(9600);

//initialize BLE led
pinMode(BLE_LED, OUTPUT);

// add service and characteristic
bleCentral.addRemoteAttribute(dummyRemoteService);
bleCentral.addRemoteAttribute(dummyRemoteCharacteristic);
Expand All @@ -51,7 +57,18 @@ void setup() {
}

void loop() {
// Do nothing
// Handle BLE led
blinkOnScan();
}

void blinkOnScan(){
// retrieve the central status in order to blink only when scanning
if(bleCentral.status() == SCANNING){
digitalWrite(BLE_LED, LOW);
delay(200);
digitalWrite(BLE_LED, HIGH);
delay(200);
}
}

void receiveAdvPck(BLEPeripheralPeer& peer){
Expand All @@ -73,12 +90,16 @@ void bleCentralConnectHandler(BLEPeripheralPeer& peer) {
// peer connected event handler
Serial.print("Connected event, peripheral: ");
Serial.println(peer.address());
// turn BLE_LED on
digitalWrite(BLE_LED, HIGH);
}

void bleCentralDisconnectHandler(BLEPeripheralPeer& peer) {
// peer disconnected event handler
Serial.print("Disconnected event, peripheral: ");
Serial.println(peer.address());
// turn BLE_LED off
digitalWrite(BLE_LED, LOW);
}

void writePasskey(BLEPeripheralPeer& peer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
to bond them.
Use the complementary example numericComparison.ino in File->Examples->BLE->Peripheral->Bonding
to test this feature.


In this example BLE_LED shows the status of the board. It will blink every 200 ms when the board is scanning.
It will be on when the board is connected to a peripheral. It will be off when the board is disconnected.

This example code is in the public domain.
*/

Expand All @@ -30,6 +33,9 @@ BLERemoteCharacteristic dummyRemoteCharacteristic = BLERemote

void setup() {
Serial.begin(9600);

//initialize BLE led
pinMode(BLE_LED, OUTPUT);

// initialize button
pinMode(CONFIRM_BUTTON, INPUT);
Expand Down Expand Up @@ -58,7 +64,18 @@ void setup() {
}

void loop() {
// Do nothing
// Handle BLE led
blinkOnScan();
}

void blinkOnScan(){
// retrieve the central status in order to blink only when scanning
if(bleCentral.status() == SCANNING){
digitalWrite(BLE_LED, LOW);
delay(200);
digitalWrite(BLE_LED, HIGH);
delay(200);
}
}

void receiveAdvPck(BLEPeripheralPeer& peer){
Expand All @@ -80,12 +97,16 @@ void bleCentralConnectHandler(BLEPeripheralPeer& peer) {
// peer connected event handler
Serial.print("Connected event, peripheral: ");
Serial.println(peer.address());
// turn BLE_LED on
digitalWrite(BLE_LED, HIGH);
}

void bleCentralDisconnectHandler(BLEPeripheralPeer& peer) {
// peer disconnected event handler
Serial.print("Disconnected event, peripheral: ");
Serial.println(peer.address());
// turn BLE_LED off
digitalWrite(BLE_LED, LOW);
}

void showPasskey(BLEPeripheralPeer& peer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

Use the complementary example enterPasskeyBond.ino in File->Examples->BLE->Peripheral->Bonding
to test this feature.

In this example BLE_LED shows the status of the board. It will blink every 200 ms when the board is scanning.
It will be on when the board is connected to a peripheral. It will be off when the board is disconnected.

This example code is in the public domain.
*/
Expand All @@ -27,6 +30,9 @@ BLERemoteCharacteristic dummyRemoteCharacteristic = BLERemote
void setup() {
Serial.begin(9600);

//initialize BLE led
pinMode(BLE_LED, OUTPUT);

// add service and characteristic
bleCentral.addRemoteAttribute(dummyRemoteService);
bleCentral.addRemoteAttribute(dummyRemoteCharacteristic);
Expand All @@ -51,7 +57,18 @@ void setup() {
}

void loop() {
// Do nothing
// Handle BLE led
blinkOnScan();
}

void blinkOnScan(){
// retrieve the central status in order to blink only when scanning
if(bleCentral.status() == SCANNING){
digitalWrite(BLE_LED, LOW);
delay(200);
digitalWrite(BLE_LED, HIGH);
delay(200);
}
}

void receiveAdvPck(BLEPeripheralPeer& peer){
Expand All @@ -73,12 +90,16 @@ void bleCentralConnectHandler(BLEPeripheralPeer& peer) {
// peer connected event handler
Serial.print("Connected event, peripheral: ");
Serial.println(peer.address());
// turn BLE_LED on
digitalWrite(BLE_LED, HIGH);
}

void bleCentralDisconnectHandler(BLEPeripheralPeer& peer) {
// peer disconnected event handler
Serial.print("Disconnected event, peripheral: ");
Serial.println(peer.address());
// turn BLE_LED off
digitalWrite(BLE_LED, LOW);
}

void showPasskey(BLEPeripheralPeer& peer) {
Expand Down
Loading