flipperzero-firmware icon indicating copy to clipboard operation
flipperzero-firmware copied to clipboard

Added a text input that only accepts full numbers (int)

Open leedave opened this issue 1 year ago • 13 comments

What's new

  • I've added a new Keyboard input. It is similar to text_input and byte_input. The purpose of this one is to only allow users to input a number, nothing else. This can be very handy in app designs, as the user input is limited to expected characters.

Verification

  • #include <gui/modules/int_input.h> in a fap application the same way you would include text_input.h

Checklist (For Reviewer)

  • [ ] PR has description of feature/bug or link to Confluence/Jira task
  • [ ] Description contains actions to verify feature/bugfix
  • [ ] I've built this code, uploaded it to the device and verified feature/bugfix

leedave avatar Jan 09 '24 07:01 leedave

@hedger Thank you for the feedback. Added the requested sdk_headers and CSV entries

leedave avatar Jan 09 '24 08:01 leedave

@hedger are these fail messages normal or am I expected to do something to fix this?

leedave avatar Jan 11 '24 09:01 leedave

Sorry for delay with your PR. Can you also provide example app and rename IntInput to NumberInput, int_input to number_input?

skotopes avatar Feb 15 '24 08:02 skotopes

@skotopes Ok, tried my best to keep it as expected. Let me know if something isn't right.

  • The keyboard is renamed
  • There is an example app in applications/examples/example_number_input

leedave avatar Feb 15 '24 16:02 leedave

https://github.com/flipperdevices/flipperzero-firmware/assets/5908330/7530c74e-8b17-4775-b99e-4c433c50c6b0

leedave avatar Feb 15 '24 16:02 leedave

0x0801147c in __furi_crash_implementation () at furi/core/check.c:163
163	        RESTORE_REGISTERS_AND_HALT_MCU(debug);
(gdb) bt
#0  0x0801147c in __furi_crash_implementation () at furi/core/check.c:163
#1  0x0807a5cc in view_dispatcher_free (view_dispatcher=0x20014de8) at applications/services/gui/view_dispatcher.c:26
#2  0x200154a6 in example_number_input_free (app=app@entry=0x20015a00) at applications/examples/example_number_input/example_number_input.c:45
#3  0x2001551e in example_number_input (p=<optimized out>) at applications/examples/example_number_input/example_number_input.c:69
#4  0x080548a2 in flipper_application_thread (context=0x20014b20) at lib/flipper_application/flipper_application.c:224
#5  0x08013d6e in furi_thread_body (context=0x20014d78) at furi/core/thread.c:91
#6  0x08013d1a in furi_thread_catch () at furi/core/thread.c:62
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

crashing on exit because some view was not released from view dispatcher

skotopes avatar Feb 16 '24 04:02 skotopes

Un-draft when ready

skotopes avatar Feb 16 '24 04:02 skotopes

also please fix build issues (API mismatch)

skotopes avatar Feb 16 '24 04:02 skotopes

@leedave need help?

skotopes avatar Apr 19 '24 10:04 skotopes

@skotopes Can you give me some more hints on the view modules should own their own buffer issue. Tbh I learn how code for Flipper should look by studying the fw you provide, as there is no official developer documentation. I got the basic setup from the other two keyboards (text & hex). If you say you're not proud of what you guys did back then and ask for an update, I'm not sure where I can find something built in the way you want to see it.

leedave avatar Apr 19 '24 14:04 leedave

@leedave change model->text_buffer type to FuriString and allocate it on your module allocation

skotopes avatar Apr 19 '24 14:04 skotopes

@skotopes How did you do the check, to see if some views were not removed from view_dispatcher. I added a code update, but lack a way of testing the result

leedave avatar Apr 19 '24 14:04 leedave

So after a long wait, I finally managed to add your requests

  • model->text_buffer changed to FuriString
  • removed number digits length option
  • replaced with settings for min/max value allowed
  • added possibility to input negative numbers, added button if set to true when loading module

leedave avatar May 17 '24 21:05 leedave

Sorry for keeping you in limbo for such a long time.

This PR was bugging me a lot when I was trying to review it previous time, It's quite bad in terms of the code and clearly requires more work before we will be able to merge it.

I've highlighted some major issues, un-draft this PR when you fix it. Also feel free to ask if you need any help.

skotopes avatar Jun 11 '24 12:06 skotopes

@skotopes Thank you for taking the time to review my code. Looks like I still have a lot to learn, but I'll stay at it.

As chance has it, just like last time your review collided with the first day of my vacation. Meaning I can't update it before I get back. I did some of the small changes already, the rest will need to wait.

leedave avatar Jun 11 '24 16:06 leedave

@leedave no problem, I'll wait ;-)

skotopes avatar Jun 11 '24 16:06 skotopes

@skotopes I've done some refactoring to solve the issues you mentioned and some more.

Main additions

  • Abilitity to adjust min and max values in the demo app for easier testing of edge-cases
  • Invalid number inputs are ignored
  • In some cases you need to be able to write an invalid number to be able to finish off with a valid number later (min: 50, type in 9 then 0 for 90). A Lock button replaces the save button in this case to symbolize invalid input and prevent saving.
  • Back button no longer saves entry, but loads back the original value
  • Removed sign & useSign, as no longer needed with min/max settings
  • replaced all const char* strings in module with furiString. Only used in module and destroyed on exit.
  • Callback returns number, no longer uses string

I hope this fits better. Let me know if something is still not good.

leedave avatar Jun 24 '24 13:06 leedave

image tehe

skotopes avatar Jul 02 '24 13:07 skotopes

See comments. Un-draft when ready.

skotopes avatar Jul 02 '24 17:07 skotopes

@skotopes Your requested updates are made, ready for review.

leedave avatar Jul 03 '24 12:07 leedave

@leedave you are close to the finishing line, just a little bit more ;-)

skotopes avatar Jul 06 '24 11:07 skotopes

Thanks again for making me a better programmer

leedave avatar Jul 06 '24 12:07 leedave

Un-draft when fixed

skotopes avatar Aug 07 '24 04:08 skotopes

That was quite a journey, couple things for you to take away:

  • Read documentation
  • Plan object ownership and allocate/release cycle
  • Keep things simple
  • Test

skotopes avatar Aug 08 '24 06:08 skotopes

Yes that was a journey, but I do appreciate the help as at the time I started developing things for Flipper there was no documentation I could read, only other code from the FW I could learn from.

I've just noticed that in the mean time documentation has started appearing ... and I'm surprised to see that there's actually a page related to [this Pull Request] (https://developer.flipper.net/flipperzero/doxygen/md__2github_2workspace_2applications_2examples_2example__number__input_2_read_me.html)

leedave avatar Aug 08 '24 06:08 leedave

As long as you document your code in doxygen format it will appear in developer documentation

skotopes avatar Aug 08 '24 06:08 skotopes