flipbip_scene_settings.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #include "../flipbip.h"
  2. #include <lib/toolbox/value_index.h>
  3. // From: lib/crypto
  4. #include <memzero.h>
  5. #define TEXT_LABEL_ON "ON"
  6. #define TEXT_LABEL_OFF "OFF"
  7. const char* const haptic_text[2] = {
  8. TEXT_LABEL_OFF,
  9. TEXT_LABEL_ON,
  10. };
  11. const uint32_t haptic_value[2] = {
  12. FlipBipHapticOff,
  13. FlipBipHapticOn,
  14. };
  15. const char* const bip39_strength_text[3] = {
  16. "12",
  17. "18",
  18. "24",
  19. };
  20. const uint32_t bip39_strength_value[3] = {
  21. FlipBipStrength128,
  22. FlipBipStrength192,
  23. FlipBipStrength256,
  24. };
  25. const char* const passphrase_text[2] = {
  26. TEXT_LABEL_OFF,
  27. TEXT_LABEL_ON,
  28. };
  29. const uint32_t passphrase_value[2] = {
  30. FlipBipPassphraseOff,
  31. FlipBipPassphraseOn,
  32. };
  33. static void flipbip_scene_settings_set_haptic(VariableItem* item) {
  34. FlipBip* app = variable_item_get_context(item);
  35. uint8_t index = variable_item_get_current_value_index(item);
  36. variable_item_set_current_value_text(item, haptic_text[index]);
  37. app->haptic = haptic_value[index];
  38. }
  39. static void flipbip_scene_settings_set_bip39_strength(VariableItem* item) {
  40. FlipBip* app = variable_item_get_context(item);
  41. uint8_t index = variable_item_get_current_value_index(item);
  42. variable_item_set_current_value_text(item, bip39_strength_text[index]);
  43. app->bip39_strength = bip39_strength_value[index];
  44. }
  45. static void flipbip_scene_settings_set_passphrase(VariableItem* item) {
  46. FlipBip* app = variable_item_get_context(item);
  47. uint8_t index = variable_item_get_current_value_index(item);
  48. variable_item_set_current_value_text(item, passphrase_text[index]);
  49. app->passphrase = passphrase_value[index];
  50. if(app->passphrase == FlipBipPassphraseOn) {
  51. app->input_state = FlipBipTextInputPassphrase;
  52. text_input_set_header_text(app->text_input, "Enter BIP39 passphrase");
  53. view_dispatcher_switch_to_view(app->view_dispatcher, FlipBipViewIdTextInput);
  54. } else {
  55. memzero(app->passphrase_text, TEXT_BUFFER_SIZE);
  56. }
  57. }
  58. void flipbip_scene_settings_submenu_callback(void* context, uint32_t index) {
  59. FlipBip* app = context;
  60. view_dispatcher_send_custom_event(app->view_dispatcher, index);
  61. }
  62. void flipbip_scene_settings_on_enter(void* context) {
  63. FlipBip* app = context;
  64. VariableItem* item;
  65. uint8_t value_index;
  66. // BIP39 strength
  67. item = variable_item_list_add(
  68. app->variable_item_list, "BIP39 Words:", 3, flipbip_scene_settings_set_bip39_strength, app);
  69. value_index = value_index_uint32(app->bip39_strength, bip39_strength_value, 3);
  70. variable_item_set_current_value_index(item, value_index);
  71. variable_item_set_current_value_text(item, bip39_strength_text[value_index]);
  72. // Passphrase
  73. item = variable_item_list_add(
  74. app->variable_item_list,
  75. "BIP39 Passphrase:",
  76. 2,
  77. flipbip_scene_settings_set_passphrase,
  78. app);
  79. value_index = value_index_uint32(app->passphrase, passphrase_value, 2);
  80. variable_item_set_current_value_index(item, value_index);
  81. variable_item_set_current_value_text(item, passphrase_text[value_index]);
  82. // Vibro on/off
  83. item = variable_item_list_add(
  84. app->variable_item_list, "Vibro/Haptic:", 2, flipbip_scene_settings_set_haptic, app);
  85. value_index = value_index_uint32(app->haptic, haptic_value, 2);
  86. variable_item_set_current_value_index(item, value_index);
  87. variable_item_set_current_value_text(item, haptic_text[value_index]);
  88. view_dispatcher_switch_to_view(app->view_dispatcher, FlipBipViewIdSettings);
  89. }
  90. bool flipbip_scene_settings_on_event(void* context, SceneManagerEvent event) {
  91. FlipBip* app = context;
  92. UNUSED(app);
  93. bool consumed = false;
  94. if(event.type == SceneManagerEventTypeCustom) {
  95. }
  96. return consumed;
  97. }
  98. void flipbip_scene_settings_on_exit(void* context) {
  99. FlipBip* app = context;
  100. variable_item_list_set_selected_item(app->variable_item_list, 0);
  101. variable_item_list_reset(app->variable_item_list);
  102. }