code_input.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * @file code_input.h
  3. * GUI: CodeInput keyboard view module API
  4. */
  5. #pragma once
  6. #include <gui/view.h>
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. /** Code input anonymous structure */
  11. typedef struct CodeInput CodeInput;
  12. /** callback that is executed when entered code matches ext buffer */
  13. typedef void (*CodeInputOkCallback)(void* context);
  14. /** callback that is executed when entered code does not matches ext buffer */
  15. typedef void (*CodeInputFailCallback)(void* context);
  16. /** Allocate and initialize code input. This code input is used to enter codes.
  17. *
  18. * @return CodeInput instance pointer
  19. */
  20. CodeInput* code_input_alloc();
  21. /** Deinitialize and free code input
  22. *
  23. * @param code_input Code input instance
  24. */
  25. void code_input_free(CodeInput* code_input);
  26. /** Get code input view
  27. *
  28. * @param code_input code input instance
  29. *
  30. * @return View instance that can be used for embedding
  31. */
  32. View* code_input_get_view(CodeInput* code_input);
  33. /** Set code input result callback
  34. *
  35. * @param code_input code input instance
  36. * @param ok_callback ok callback fn
  37. * @param fail_callback fail callback fn
  38. * @param callback_context callback context
  39. * @param buffer buffer to use
  40. * @param buffer_length buffer length
  41. * @param update set true to update buffer
  42. */
  43. void code_input_set_result_callback(
  44. CodeInput* code_input,
  45. CodeInputOkCallback ok_callback,
  46. CodeInputFailCallback fail_callback,
  47. void* callback_context,
  48. uint8_t* buffer,
  49. uint8_t* buffer_length,
  50. bool update);
  51. /** Set code input header text
  52. *
  53. * @param code_input code input instance
  54. * @param text text to be shown
  55. */
  56. void code_input_set_header_text(CodeInput* code_input, const char* text);
  57. /** Compare two buffers
  58. *
  59. * @param in buffer to compare to source
  60. * @param len_in length of input buffer
  61. * @param src source buffer
  62. * @param len_src length of insourceput buffer
  63. * @return true if buffers match
  64. */
  65. bool code_input_compare(uint8_t* in, size_t len_in, uint8_t* src, size_t len_src);
  66. /** Push input into the end of array
  67. *
  68. * @param buffer buffer
  69. * @param length length of buffer
  70. * @param key input key
  71. * @return new length of input buffer
  72. */
  73. size_t code_input_push(uint8_t* buffer, size_t length, InputKey key);
  74. #ifdef __cplusplus
  75. }
  76. #endif