Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example for fus #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion BLE_LEDBlinker/mbed-os.lib
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
https://github.com/ARMmbed/mbed-os/#a6207cadad0acd1876f436dc6baeddf46c42af06
https://github.com/micgur01/mbed-os/#56c3b98a25da17bc9d5d594575297d7297dc7896


4 changes: 4 additions & 0 deletions BLE_LEDBlinker/mbed_app.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"target_overrides": {

"*": {
"platform.stdio-baud-rate" : 115200
},
"K64F": {
"target.components_add": ["BlueNRG_MS"],
"target.features_add": ["BLE"],
Expand Down
74 changes: 57 additions & 17 deletions BLE_LEDBlinker/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#include "ble/gap/Gap.h"
#include "ble/gap/AdvertisingDataParser.h"
#include "pretty_printer.h"
#include "shci.h"
#include "app_conf.h"


const static char PEER_NAME[] = "LED";

Expand All @@ -30,6 +33,11 @@ static EventQueue event_queue(/* event count */ 10 * EVENTS_EVENT_SIZE);
static DiscoveredCharacteristic led_characteristic;
static bool trigger_led_characteristic = false;


extern "C" int handle_ready_event;
static bool startBLEbyExample = false;
static bool startFUSbyExample = false;

void service_discovery(const DiscoveredService *service) {
if (service->getUUID().shortOrLong() == UUID::UUID_TYPE_SHORT) {
printf("S UUID-%x attrs[%u %u]\r\n", service->getUUID().getShortUUID(), service->getStartHandle(), service->getEndHandle());
Expand Down Expand Up @@ -84,47 +92,73 @@ void trigger_read(const GattWriteCallbackParams *response) {
}
}

volatile int _fus_option = 0;


class LEDBlinkerDemo : ble::Gap::EventHandler {
public:
LEDBlinkerDemo(BLE &ble, events::EventQueue &event_queue) :
_ble(ble),
_event_queue(event_queue),
_alive_led(LED1, 1),
_actuated_led(LED2, 0),
_is_connecting(false) { }
_is_connecting(false){ }

~LEDBlinkerDemo() { }

void start() {
_ble.gap().setEventHandler(this);

_ble.gap().setEventHandler(this);
printf("ble.init\n");
_ble.init(this, &LEDBlinkerDemo::on_init_complete);
printf("ble.init done\n");

if( startBLEbyExample && startFUSbyExample)
printf("startBLEbyExample && startFUSbyExample are true, please choose one\n");


_event_queue.call_every(500, this, &LEDBlinkerDemo::blink);
if ( startBLEbyExample ) {
printf("start BLE\n");
SHCI_C2_FUS_StartWs();
}

_event_queue.dispatch_forever();
if ( startFUSbyExample ) {
printf("start FUS\n");
SHCI_C2_FUS_GetState( NULL );
SHCI_C2_FUS_GetState( NULL );
}

printf("handle_ready_event @start %d\n", handle_ready_event);
//_event_queue.call_every(5000, this, &LEDBlinkerDemo::blink);

_event_queue.dispatch_forever();
}

private:

/** Callback triggered when the ble initialization process has finished */
void on_init_complete(BLE::InitializationCompleteCallbackContext *params) {
if (params->error != BLE_ERROR_NONE) {
printf("Ble initialization failed.");
return;
}

print_mac_address();
printf("handle_ready_event @on_init_complete %d\n", handle_ready_event);

_ble.gattClient().onDataRead(trigger_toggled_write);
_ble.gattClient().onDataWritten(trigger_read);
if( handle_ready_event == 1) {
if (params->error != BLE_ERROR_NONE) {
printf("Ble initialization failed.\n");
return;
}

print_mac_address();
_ble.gattClient().onDataRead(trigger_toggled_write);
_ble.gattClient().onDataWritten(trigger_read);

ble::ScanParameters scan_params;
_ble.gap().setScanParameters(scan_params);
_ble.gap().startScan();
ble::ScanParameters scan_params;
_ble.gap().setScanParameters(scan_params);
_ble.gap().startScan();
}
}

void blink() {
_alive_led = !_alive_led;
_alive_led = !_alive_led;
}

private:
Expand Down Expand Up @@ -216,13 +250,19 @@ void schedule_ble_events(BLE::OnEventsToProcessCallbackContext *context) {
event_queue.call(Callback<void()>(&context->ble, &BLE::processEvents));
}


int main()
{
printf("Start Example\n");

printf("CFG_OTA_REBOOT_VAL_MSG %d\n", CFG_OTA_REBOOT_VAL_MSG);
CFG_OTA_REBOOT_VAL_MSG = CFG_REBOOT_ON_FW_APP;

BLE &ble = BLE::Instance();
ble.onEventsToProcess(schedule_ble_events);
//ble.onEventsToProcess(schedule_ble_events);

LEDBlinkerDemo demo(ble, event_queue);
demo.start();

return 0;
}