Skip to content

Commit

Permalink
Add error message if the module is not connected
Browse files Browse the repository at this point in the history
  • Loading branch information
ginkage committed Jun 5, 2024
1 parent d035344 commit 3e65a46
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
14 changes: 11 additions & 3 deletions air_mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ AirMouse* air_mouse_app_alloc() {
view_dispatcher_add_view(
app->view_dispatcher, AirMouseViewSubmenu, submenu_get_view(app->submenu));

// Dialog view
// Dialog views
app->dialog = dialog_ex_alloc();
dialog_ex_set_result_callback(app->dialog, air_mouse_dialog_callback);
dialog_ex_set_context(app->dialog, app);
Expand All @@ -97,6 +97,13 @@ AirMouse* air_mouse_app_alloc() {
view_dispatcher_add_view(
app->view_dispatcher, AirMouseViewExitConfirm, dialog_ex_get_view(app->dialog));

app->error_dialog = dialog_ex_alloc();
dialog_ex_set_header(app->error_dialog, "Failed to init IMU", 63, 0, AlignCenter, AlignTop);
dialog_ex_set_text(app->error_dialog, "Please connect sensor module", 63, 30, AlignCenter, AlignTop);
view_set_previous_callback(dialog_ex_get_view(app->error_dialog), air_mouse_exit);
view_dispatcher_add_view(
app->view_dispatcher, AirMouseViewError, dialog_ex_get_view(app->error_dialog));

// Bluetooth view
app->bt_mouse = bt_mouse_alloc(app->view_dispatcher);
view_set_previous_callback(bt_mouse_get_view(app->bt_mouse), air_mouse_exit_confirm_view);
Expand Down Expand Up @@ -130,6 +137,8 @@ void air_mouse_app_free(AirMouse* app) {
submenu_free(app->submenu);
view_dispatcher_remove_view(app->view_dispatcher, AirMouseViewExitConfirm);
dialog_ex_free(app->dialog);
view_dispatcher_remove_view(app->view_dispatcher, AirMouseViewError);
dialog_ex_free(app->error_dialog);
view_dispatcher_remove_view(app->view_dispatcher, AirMouseViewBtMouse);
bt_mouse_free(app->bt_mouse);
view_dispatcher_remove_view(app->view_dispatcher, AirMouseViewUsbMouse);
Expand All @@ -151,8 +160,7 @@ int32_t air_mouse_app(void* p) {

AirMouse* app = air_mouse_app_alloc();
if(!imu_begin()) {
air_mouse_app_free(app);
return -1;
view_dispatcher_switch_to_view(app->view_dispatcher, AirMouseViewError);
}

view_dispatcher_run(app->view_dispatcher);
Expand Down
2 changes: 2 additions & 0 deletions air_mouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ typedef struct {
ViewDispatcher* view_dispatcher;
Submenu* submenu;
DialogEx* dialog;
DialogEx* error_dialog;
BtMouse* bt_mouse;
UsbMouse* usb_mouse;
Calibration* calibration;
Expand All @@ -27,4 +28,5 @@ typedef enum {
AirMouseViewUsbMouse,
AirMouseViewCalibration,
AirMouseViewExitConfirm,
AirMouseViewError,
} AirMouseView;
14 changes: 7 additions & 7 deletions tracking/imu/imu.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ struct imu_t* find_imu() {
}

bool imu_begin() {
if (imu_found != NULL)
return true;

bool ret = false;
furi_hal_i2c_acquire(&furi_hal_i2c_handle_external);
imu_found = find_imu();

if (imu_found != NULL) {
FURI_LOG_E(IMU_TAG, "Found Device %s", imu_found->name);
ret = imu_found->begin();
if (imu_found == NULL) {
imu_found = find_imu();
if (imu_found != NULL)
FURI_LOG_E(IMU_TAG, "Found Device %s", imu_found->name);
}

if (imu_found != NULL)
ret = imu_found->begin();

furi_hal_i2c_release(&furi_hal_i2c_handle_external);
return ret;
}
Expand Down

0 comments on commit 3e65a46

Please sign in to comment.