mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-12-24 19:53:08 +00:00
60a9d7e6cf
* ble: profile rework, initial * apps: hid: fix for pairing cleanup * app: hid: select transport based on #define * fixing PVS warnings * ble: serial service: fixed uid naming * bt service: on-demand dialog init; ble profiles: docs; battery svc: proper update * Added shci_cmd_resp_wait/shci_cmd_resp_release impl with semaphore * app: hid: separated transport code * ble: fixed service init order for serial svc; moved hardfault check to ble_glue * cli: ps: added thread prio to output, fixed heap display * ble_glue: naming changes; separate thread for event processing; * furi: added runtime stats; cli: added cpu% to `ps` * cli: fixed thread time calculation * furi: added getter for thread priority * fixing pvs warnings * hid profile: fixed naming * more naming fixes * hal: ble init small cleanup * cleanup & draft beacon api * f18: api sync * apps: moved example_custom_font from debug to examples * BLE extra beacon demo app * naming fix * UI fixes for demo app (wip) * desktop, ble svc: added statusbar icon for beacon * minor cleanup * Minor cleanup & naming fixes * api sync * Removed stale header * hal: added FURI_BLE_EXTRA_LOG for extra logging; comments & code cleanup * naming & macro fixes * quick fixes from review * Eliminated stock svc_ctl * cli: ps: removed runtime stats * minor include fixes * (void) * naming fixes * More naming fixes * fbt: always build all libs * fbt: explicitly globbing libs; dist: logging SDK path * scripts: fixed lib path precedence * hal: bt: profiles: naming changes, support for passing params to a profile; include cleanup * ble: hid: added parameter processing for profile template * api sync * BLE HID: long name trim * Removed unused check * desktop: updated beacon status icon; ble: hid: cleaner device name management * desktop: updated status icon Co-authored-by: あく <alleteam@gmail.com> Co-authored-by: nminaylov <nm29719@gmail.com>
97 lines
2.7 KiB
C
97 lines
2.7 KiB
C
#include "event_dispatcher.h"
|
|
#include <core/check.h>
|
|
#include <furi.h>
|
|
#include <ble/ble.h>
|
|
|
|
#include <m-list.h>
|
|
|
|
struct GapEventHandler {
|
|
void* context;
|
|
BleSvcEventHandlerCb callback;
|
|
};
|
|
|
|
LIST_DEF(GapSvcEventHandlerList, GapSvcEventHandler, M_POD_OPLIST);
|
|
|
|
static GapSvcEventHandlerList_t handlers;
|
|
static bool initialized = false;
|
|
|
|
BleEventFlowStatus ble_event_dispatcher_process_event(void* payload) {
|
|
furi_check(initialized);
|
|
|
|
GapSvcEventHandlerList_it_t it;
|
|
BleEventAckStatus ack_status = BleEventNotAck;
|
|
|
|
for(GapSvcEventHandlerList_it(it, handlers); !GapSvcEventHandlerList_end_p(it);
|
|
GapSvcEventHandlerList_next(it)) {
|
|
const GapSvcEventHandler* item = GapSvcEventHandlerList_cref(it);
|
|
ack_status = item->callback(payload, item->context);
|
|
if(ack_status == BleEventNotAck) {
|
|
/* Keep going */
|
|
continue;
|
|
} else if((ack_status == BleEventAckFlowEnable) || (ack_status == BleEventAckFlowDisable)) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
/* Handlers for client-mode events are also to be implemented here. But not today. */
|
|
|
|
/* Now, decide on a flow control action based on results of all handlers */
|
|
switch(ack_status) {
|
|
case BleEventNotAck:
|
|
/* The event has NOT been managed yet. Pass to app for processing */
|
|
return ble_event_app_notification(payload);
|
|
case BleEventAckFlowEnable:
|
|
return BleEventFlowEnable;
|
|
case BleEventAckFlowDisable:
|
|
return BleEventFlowDisable;
|
|
default:
|
|
return BleEventFlowEnable;
|
|
}
|
|
}
|
|
|
|
void ble_event_dispatcher_init(void) {
|
|
furi_assert(!initialized);
|
|
|
|
GapSvcEventHandlerList_init(handlers);
|
|
initialized = true;
|
|
}
|
|
|
|
void ble_event_dispatcher_reset(void) {
|
|
furi_assert(initialized);
|
|
furi_check(GapSvcEventHandlerList_size(handlers) == 0);
|
|
|
|
GapSvcEventHandlerList_clear(handlers);
|
|
}
|
|
|
|
GapSvcEventHandler*
|
|
ble_event_dispatcher_register_svc_handler(BleSvcEventHandlerCb handler, void* context) {
|
|
furi_check(handler);
|
|
furi_check(context);
|
|
furi_check(initialized);
|
|
|
|
GapSvcEventHandler* item = GapSvcEventHandlerList_push_raw(handlers);
|
|
item->context = context;
|
|
item->callback = handler;
|
|
|
|
return item;
|
|
}
|
|
|
|
void ble_event_dispatcher_unregister_svc_handler(GapSvcEventHandler* handler) {
|
|
furi_check(handler);
|
|
|
|
bool found = false;
|
|
GapSvcEventHandlerList_it_t it;
|
|
|
|
for(GapSvcEventHandlerList_it(it, handlers); !GapSvcEventHandlerList_end_p(it);
|
|
GapSvcEventHandlerList_next(it)) {
|
|
const GapSvcEventHandler* item = GapSvcEventHandlerList_cref(it);
|
|
|
|
if(item == handler) {
|
|
GapSvcEventHandlerList_remove(handlers, it);
|
|
found = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
furi_check(found);
|
|
}
|