instantiator / flipper-zero-experimental-apps

Experimentation building apps for flipper zero
MIT License
57 stars 7 forks source link

Resistance calculator: app causes Flipper to hang on the `dev` firmware #4

Open instantiator opened 1 year ago

instantiator commented 1 year ago

When running on the dev firmware, the app causes the Flipper to hang when attempting to show the resistor editing scene.

To reproduce

NB. Back button + left will restart the Flipper.

instantiator commented 1 year ago

Debugging help and commentary from @jamisonderek

So the issue is:

widget_alloc does...

view_set_input_callback(widget->view, ...)

then later you do...

view_set_input_callback(widget_get_view(app->widget), widget_input_callback);

which does..

void view_set_input_callback(View* view, ViewInputCallback callback) {
    furi_assert(view);
    furi_assert(view->input_callback == NULL); <<<<<
debug-dev-fw-issue

For your issue, gui_widget_view_input_callback calls all of the widget's input handlers. Ideally you would create something new like widget_element_button_action that would invoke a callback when a button was pressed. Unfortunately, widget_add_element is static. 😦

instantiator commented 1 year ago

Working through this, the issue is that:

Therefore, under circumstances where furi_assert is enforced (eg. the dev firmware?) it's not possible to assign an alternate input callback.

It also doesn't seem possible to modify any of the various structs directly:

It's also not possible to craft a new element type, and add it to the widget, as:

So, the only option seems to be to add a button:

instantiator commented 1 year ago

An alternative is to modify the firmware to give some more flexbility to developers.

option 1

Modify the firmware to support definition of new elements, and their addition to widgets, ie.

option 2 (simpler)

Alter View to permit direct alteration of the input callback, ie.

instantiator commented 1 year ago

Filed the simplest possible PR against the firmware: https://github.com/flipperdevices/flipperzero-firmware/pull/2623