unleashed-firmware/applications/debug/bt_debug_app/bt_debug_app.c
MX bf6c6c231f
[FL-3841] FuriEventLoop Pt.2 (#3703)
* Abstract primitive type from main logic in FuriEventLoop
* Remove message_queue_i.h
* Add stream buffer support for event loop
* Add semaphore support for event loop
* Add temporary unit test workaround
* Make the linter happy
* Add mutex support for event loop
* Implement event subscription and unsubscription while the event loop is running
* Implement edge events
* Fix leftover logical errors
* Add event loop timer example application
* Implement flag-based edge trigger and one-shot mode
* Add event loop mutex example application
* Only notify the event loop if stream buffer is at or above its trigger level
* Reformat comments
* Add event loop stream buffer example application
* Add event loop multiple elements example application
* Improve event loop flag names
* Remove redundant signal handler as it is already handled by the event loop
* Refactor Power service, improve ViewHolder
* Use ViewHolder instead of ViewDispatcher in About app
* Enable ViewDispatcher queue on construction, deprecate view_dispatcher_enable_queue()
* Remove all invocations of view_dispatcher_enable_queue()
* Remove app-scened-template
* Remove missing library from target.json
* Port Accessor app to ViewHolder
* Make the linter happy
* Add example_view_holder application, update ViewHolder docs
* Add example_view_dispatcher application, update ViewDispatcher docs
* Replace FuriSemaphore with FuriApiLock, remove workaround delay
* Fix logical error
* Fix another logical error
* Use the sources directive to speed up compilation
* Use constant define macro
* Improve FuriEventLoop documentation
* Improve FuriEventLoop documentation once more
* Bump API Version
* Gui: remove redundant checks from ViewDispatcher
* Gui: remove dead ifs from ViewDispatcher

Co-authored-by: Silent <CookiePLMonster@users.noreply.github.com>
Co-authored-by: hedger <hedger@users.noreply.github.com>
Co-authored-by: あく <alleteam@gmail.com>
2024-08-10 14:32:27 +03:00

118 lines
3.6 KiB
C

#include "bt_debug_app.h"
#include <furi_hal_bt.h>
#define TAG "BtDebugApp"
enum BtDebugSubmenuIndex {
BtDebugSubmenuIndexCarrierTest,
BtDebugSubmenuIndexPacketTest,
};
void bt_debug_submenu_callback(void* context, uint32_t index) {
furi_assert(context);
BtDebugApp* app = context;
if(index == BtDebugSubmenuIndexCarrierTest) {
view_dispatcher_switch_to_view(app->view_dispatcher, BtDebugAppViewCarrierTest);
} else if(index == BtDebugSubmenuIndexPacketTest) {
view_dispatcher_switch_to_view(app->view_dispatcher, BtDebugAppViewPacketTest);
}
}
uint32_t bt_debug_exit(void* context) {
UNUSED(context);
return VIEW_NONE;
}
uint32_t bt_debug_start_view(void* context) {
UNUSED(context);
return BtDebugAppViewSubmenu;
}
BtDebugApp* bt_debug_app_alloc(void) {
BtDebugApp* app = malloc(sizeof(BtDebugApp));
// Gui
app->gui = furi_record_open(RECORD_GUI);
// View dispatcher
app->view_dispatcher = view_dispatcher_alloc();
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
// Views
app->submenu = submenu_alloc();
submenu_add_item(
app->submenu,
"Carrier test",
BtDebugSubmenuIndexCarrierTest,
bt_debug_submenu_callback,
app);
submenu_add_item(
app->submenu, "Packet test", BtDebugSubmenuIndexPacketTest, bt_debug_submenu_callback, app);
view_set_previous_callback(submenu_get_view(app->submenu), bt_debug_exit);
view_dispatcher_add_view(
app->view_dispatcher, BtDebugAppViewSubmenu, submenu_get_view(app->submenu));
app->bt_carrier_test = bt_carrier_test_alloc();
view_set_previous_callback(
bt_carrier_test_get_view(app->bt_carrier_test), bt_debug_start_view);
view_dispatcher_add_view(
app->view_dispatcher,
BtDebugAppViewCarrierTest,
bt_carrier_test_get_view(app->bt_carrier_test));
app->bt_packet_test = bt_packet_test_alloc();
view_set_previous_callback(bt_packet_test_get_view(app->bt_packet_test), bt_debug_start_view);
view_dispatcher_add_view(
app->view_dispatcher,
BtDebugAppViewPacketTest,
bt_packet_test_get_view(app->bt_packet_test));
// Switch to menu
view_dispatcher_switch_to_view(app->view_dispatcher, BtDebugAppViewSubmenu);
return app;
}
void bt_debug_app_free(BtDebugApp* app) {
furi_assert(app);
// Free views
view_dispatcher_remove_view(app->view_dispatcher, BtDebugAppViewSubmenu);
submenu_free(app->submenu);
view_dispatcher_remove_view(app->view_dispatcher, BtDebugAppViewCarrierTest);
bt_carrier_test_free(app->bt_carrier_test);
view_dispatcher_remove_view(app->view_dispatcher, BtDebugAppViewPacketTest);
bt_packet_test_free(app->bt_packet_test);
view_dispatcher_free(app->view_dispatcher);
// Close gui record
furi_record_close(RECORD_GUI);
app->gui = NULL;
// Free rest
free(app);
}
int32_t bt_debug_app(void* p) {
UNUSED(p);
if(!furi_hal_bt_is_testing_supported()) {
FURI_LOG_E(TAG, "Incorrect radio stack: radio testing features are absent.");
DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS);
dialog_message_show_storage_error(dialogs, "Incorrect\nRadioStack");
return 255;
}
BtDebugApp* app = bt_debug_app_alloc();
// Was bt active?
const bool was_active = furi_hal_bt_is_active();
// Stop advertising
furi_hal_bt_stop_advertising();
view_dispatcher_run(app->view_dispatcher);
// Restart advertising
if(was_active) {
furi_hal_bt_start_advertising();
}
bt_debug_app_free(app);
return 0;
}