byte_input.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  1. #include "byte_input.h"
  2. #include <gui/elements.h>
  3. #include <furi.h>
  4. struct ByteInput {
  5. View* view;
  6. };
  7. typedef struct {
  8. const uint8_t value;
  9. const uint8_t x;
  10. const uint8_t y;
  11. } ByteInputKey;
  12. typedef struct {
  13. const char* header;
  14. uint8_t* bytes;
  15. uint8_t bytes_count;
  16. ByteInputCallback input_callback;
  17. ByteChangedCallback changed_callback;
  18. void* callback_context;
  19. bool selected_high_nibble;
  20. uint8_t selected_byte;
  21. int8_t selected_row; // row -1 - input, row 0 & 1 - keyboard
  22. uint8_t selected_column;
  23. uint8_t first_visible_byte;
  24. } ByteInputModel;
  25. #ifndef MAX
  26. #define MAX(x, y) (((x) > (y)) ? (x) : (y))
  27. #endif
  28. #ifndef MIN
  29. #define MIN(x, y) (((x) < (y)) ? (x) : (y))
  30. #endif
  31. static const uint8_t keyboard_origin_x = 7;
  32. static const uint8_t keyboard_origin_y = 31;
  33. static const uint8_t keyboard_row_count = 2;
  34. static const uint8_t enter_symbol = '\r';
  35. static const uint8_t backspace_symbol = '\b';
  36. static const uint8_t max_drawable_bytes = 8;
  37. static const ByteInputKey keyboard_keys_row_1[] = {
  38. {'0', 0, 12},
  39. {'1', 11, 12},
  40. {'2', 22, 12},
  41. {'3', 33, 12},
  42. {'4', 44, 12},
  43. {'5', 55, 12},
  44. {'6', 66, 12},
  45. {'7', 77, 12},
  46. {backspace_symbol, 103, 4},
  47. };
  48. static const ByteInputKey keyboard_keys_row_2[] = {
  49. {'8', 0, 26},
  50. {'9', 11, 26},
  51. {'A', 22, 26},
  52. {'B', 33, 26},
  53. {'C', 44, 26},
  54. {'D', 55, 26},
  55. {'E', 66, 26},
  56. {'F', 77, 26},
  57. {enter_symbol, 95, 17},
  58. };
  59. /**
  60. * @brief Get row size
  61. *
  62. * @param row_index Index of row
  63. * @return uint8_t Row size
  64. */
  65. static uint8_t byte_input_get_row_size(uint8_t row_index) {
  66. uint8_t row_size = 0;
  67. switch(row_index + 1) {
  68. case 1:
  69. row_size = sizeof(keyboard_keys_row_1) / sizeof(ByteInputKey);
  70. break;
  71. case 2:
  72. row_size = sizeof(keyboard_keys_row_2) / sizeof(ByteInputKey);
  73. break;
  74. }
  75. return row_size;
  76. }
  77. /**
  78. * @brief Get row pointer
  79. *
  80. * @param row_index Index of row
  81. * @return const ByteInputKey* Row pointer
  82. */
  83. static const ByteInputKey* byte_input_get_row(uint8_t row_index) {
  84. const ByteInputKey* row = NULL;
  85. switch(row_index + 1) {
  86. case 1:
  87. row = keyboard_keys_row_1;
  88. break;
  89. case 2:
  90. row = keyboard_keys_row_2;
  91. break;
  92. }
  93. return row;
  94. }
  95. /**
  96. * @brief Get text from nibble
  97. *
  98. * @param byte byte value
  99. * @param high_nibble Get from high nibble, otherwise low nibble
  100. * @return char nibble text
  101. */
  102. static char byte_input_get_nibble_text(uint8_t byte, bool high_nibble) {
  103. if(high_nibble) {
  104. byte = byte >> 4;
  105. }
  106. byte = byte & 0x0F;
  107. switch(byte & 0x0F) {
  108. case 0x0:
  109. case 0x1:
  110. case 0x2:
  111. case 0x3:
  112. case 0x4:
  113. case 0x5:
  114. case 0x6:
  115. case 0x7:
  116. case 0x8:
  117. case 0x9:
  118. byte = byte + '0';
  119. break;
  120. case 0xA:
  121. case 0xB:
  122. case 0xC:
  123. case 0xD:
  124. case 0xE:
  125. case 0xF:
  126. byte = byte - 0xA + 'A';
  127. break;
  128. default:
  129. byte = '!';
  130. break;
  131. }
  132. return byte;
  133. }
  134. /**
  135. * @brief Draw input box (common view)
  136. *
  137. * @param canvas
  138. * @param model
  139. */
  140. static void byte_input_draw_input(Canvas* canvas, ByteInputModel* model) {
  141. const uint8_t text_x = 3;
  142. const uint8_t text_y = 25;
  143. elements_slightly_rounded_frame(canvas, 1, 14, 126, 15);
  144. for(uint8_t i = model->first_visible_byte;
  145. i < model->first_visible_byte + MIN(model->bytes_count, max_drawable_bytes);
  146. i++) {
  147. uint8_t byte_position = i - model->first_visible_byte;
  148. if(i == model->selected_byte) {
  149. canvas_draw_frame(canvas, text_x + byte_position * 14, text_y - 9, 15, 11);
  150. if(model->selected_high_nibble) {
  151. canvas_draw_glyph(
  152. canvas,
  153. text_x + 8 + byte_position * 14,
  154. text_y,
  155. byte_input_get_nibble_text(model->bytes[i], false));
  156. canvas_draw_box(canvas, text_x + 1 + byte_position * 14, text_y - 8, 7, 9);
  157. canvas_invert_color(canvas);
  158. canvas_draw_line(
  159. canvas,
  160. text_x + 14 + byte_position * 14,
  161. text_y - 6,
  162. text_x + 14 + byte_position * 14,
  163. text_y - 2);
  164. canvas_draw_glyph(
  165. canvas,
  166. text_x + 2 + byte_position * 14,
  167. text_y,
  168. byte_input_get_nibble_text(model->bytes[i], true));
  169. canvas_invert_color(canvas);
  170. } else {
  171. canvas_draw_box(canvas, text_x + 7 + byte_position * 14, text_y - 8, 7, 9);
  172. canvas_draw_glyph(
  173. canvas,
  174. text_x + 2 + byte_position * 14,
  175. text_y,
  176. byte_input_get_nibble_text(model->bytes[i], true));
  177. canvas_invert_color(canvas);
  178. canvas_draw_line(
  179. canvas,
  180. text_x + byte_position * 14,
  181. text_y - 6,
  182. text_x + byte_position * 14,
  183. text_y - 2);
  184. canvas_draw_glyph(
  185. canvas,
  186. text_x + 8 + byte_position * 14,
  187. text_y,
  188. byte_input_get_nibble_text(model->bytes[i], false));
  189. canvas_invert_color(canvas);
  190. }
  191. } else {
  192. canvas_draw_glyph(
  193. canvas,
  194. text_x + 2 + byte_position * 14,
  195. text_y,
  196. byte_input_get_nibble_text(model->bytes[i], true));
  197. canvas_draw_glyph(
  198. canvas,
  199. text_x + 8 + byte_position * 14,
  200. text_y,
  201. byte_input_get_nibble_text(model->bytes[i], false));
  202. }
  203. }
  204. if(model->bytes_count - model->first_visible_byte > max_drawable_bytes) {
  205. canvas_draw_icon_name(canvas, 123, 21, I_ButtonRightSmall_3x5);
  206. }
  207. if(model->first_visible_byte > 0) {
  208. canvas_draw_icon_name(canvas, 1, 21, I_ButtonLeftSmall_3x5);
  209. }
  210. }
  211. /**
  212. * @brief Draw input box (selected view)
  213. *
  214. * @param canvas
  215. * @param model
  216. */
  217. static void byte_input_draw_input_selected(Canvas* canvas, ByteInputModel* model) {
  218. const uint8_t text_x = 3;
  219. const uint8_t text_y = 25;
  220. canvas_draw_box(canvas, 0, 12, 128, 19);
  221. canvas_invert_color(canvas);
  222. elements_slightly_rounded_frame(canvas, 1, 14, 126, 15);
  223. for(uint8_t i = model->first_visible_byte;
  224. i < model->first_visible_byte + MIN(model->bytes_count, max_drawable_bytes);
  225. i++) {
  226. uint8_t byte_position = i - model->first_visible_byte;
  227. if(i == model->selected_byte) {
  228. canvas_draw_box(canvas, text_x + byte_position * 14, text_y - 9, 15, 11);
  229. canvas_invert_color(canvas);
  230. canvas_draw_glyph(
  231. canvas,
  232. text_x + 2 + byte_position * 14,
  233. text_y,
  234. byte_input_get_nibble_text(model->bytes[i], true));
  235. canvas_draw_glyph(
  236. canvas,
  237. text_x + 8 + byte_position * 14,
  238. text_y,
  239. byte_input_get_nibble_text(model->bytes[i], false));
  240. canvas_invert_color(canvas);
  241. } else {
  242. canvas_draw_glyph(
  243. canvas,
  244. text_x + 2 + byte_position * 14,
  245. text_y,
  246. byte_input_get_nibble_text(model->bytes[i], true));
  247. canvas_draw_glyph(
  248. canvas,
  249. text_x + 8 + byte_position * 14,
  250. text_y,
  251. byte_input_get_nibble_text(model->bytes[i], false));
  252. }
  253. }
  254. if(model->bytes_count - model->first_visible_byte > max_drawable_bytes) {
  255. canvas_draw_icon_name(canvas, 123, 21, I_ButtonRightSmall_3x5);
  256. }
  257. if(model->first_visible_byte > 0) {
  258. canvas_draw_icon_name(canvas, 1, 21, I_ButtonLeftSmall_3x5);
  259. }
  260. canvas_invert_color(canvas);
  261. }
  262. /**
  263. * @brief Set nibble at position
  264. *
  265. * @param data where to set nibble
  266. * @param position byte position
  267. * @param value char value
  268. * @param high_nibble set high nibble
  269. */
  270. static void byte_input_set_nibble(uint8_t* data, uint8_t position, char value, bool high_nibble) {
  271. switch(value) {
  272. case '0':
  273. case '1':
  274. case '2':
  275. case '3':
  276. case '4':
  277. case '5':
  278. case '6':
  279. case '7':
  280. case '8':
  281. case '9':
  282. value = value - '0';
  283. break;
  284. case 'A':
  285. case 'B':
  286. case 'C':
  287. case 'D':
  288. case 'E':
  289. case 'F':
  290. value = value - 'A' + 10;
  291. break;
  292. default:
  293. value = 0;
  294. break;
  295. }
  296. if(high_nibble) {
  297. data[position] &= 0x0F;
  298. data[position] |= value << 4;
  299. } else {
  300. data[position] &= 0xF0;
  301. data[position] |= value;
  302. }
  303. }
  304. /**
  305. * @brief What currently selected
  306. *
  307. * @return true - keyboard selected, false - input selected
  308. */
  309. static bool byte_input_keyboard_selected(ByteInputModel* model) {
  310. return model->selected_row >= 0;
  311. }
  312. /**
  313. * @brief Do transition from keyboard
  314. *
  315. * @param model
  316. */
  317. static void byte_input_transition_from_keyboard(ByteInputModel* model) {
  318. model->selected_row += 1;
  319. model->selected_high_nibble = true;
  320. }
  321. /**
  322. * @brief Increase selected byte position
  323. *
  324. * @param model
  325. */
  326. static void byte_input_inc_selected_byte(ByteInputModel* model) {
  327. if(model->selected_byte < model->bytes_count - 1) {
  328. model->selected_byte += 1;
  329. if(model->bytes_count > max_drawable_bytes) {
  330. if(model->selected_byte - model->first_visible_byte > (max_drawable_bytes - 2)) {
  331. if(model->first_visible_byte < model->bytes_count - max_drawable_bytes) {
  332. model->first_visible_byte++;
  333. }
  334. }
  335. }
  336. }
  337. }
  338. /**
  339. * @brief Decrease selected byte position
  340. *
  341. * @param model
  342. */
  343. static void byte_input_dec_selected_byte(ByteInputModel* model) {
  344. if(model->selected_byte > 0) {
  345. model->selected_byte -= 1;
  346. if(model->selected_byte - model->first_visible_byte < 1) {
  347. if(model->first_visible_byte > 0) {
  348. model->first_visible_byte--;
  349. }
  350. }
  351. }
  352. }
  353. /**
  354. * @brief Call input callback
  355. *
  356. * @param model
  357. */
  358. static void byte_input_call_input_callback(ByteInputModel* model) {
  359. if(model->input_callback != NULL) {
  360. model->input_callback(model->callback_context, model->bytes, model->bytes_count);
  361. }
  362. }
  363. /**
  364. * @brief Call changed callback
  365. *
  366. * @param model
  367. */
  368. static void byte_input_call_changed_callback(ByteInputModel* model) {
  369. if(model->changed_callback != NULL) {
  370. model->changed_callback(model->callback_context, model->bytes, model->bytes_count);
  371. }
  372. }
  373. /**
  374. * @brief Handle up button
  375. *
  376. * @param model
  377. */
  378. static void byte_input_handle_up(ByteInputModel* model) {
  379. if(model->selected_row > -1) {
  380. model->selected_row -= 1;
  381. }
  382. }
  383. /**
  384. * @brief Handle down button
  385. *
  386. * @param model
  387. */
  388. static void byte_input_handle_down(ByteInputModel* model) {
  389. if(byte_input_keyboard_selected(model)) {
  390. if(model->selected_row < keyboard_row_count - 1) {
  391. model->selected_row += 1;
  392. }
  393. } else {
  394. byte_input_transition_from_keyboard(model);
  395. }
  396. }
  397. /**
  398. * @brief Handle left button
  399. *
  400. * @param model
  401. */
  402. static void byte_input_handle_left(ByteInputModel* model) {
  403. if(byte_input_keyboard_selected(model)) {
  404. if(model->selected_column > 0) {
  405. model->selected_column -= 1;
  406. } else {
  407. model->selected_column = byte_input_get_row_size(model->selected_row) - 1;
  408. }
  409. } else {
  410. byte_input_dec_selected_byte(model);
  411. }
  412. }
  413. /**
  414. * @brief Handle right button
  415. *
  416. * @param model
  417. */
  418. static void byte_input_handle_right(ByteInputModel* model) {
  419. if(byte_input_keyboard_selected(model)) {
  420. if(model->selected_column < byte_input_get_row_size(model->selected_row) - 1) {
  421. model->selected_column += 1;
  422. } else {
  423. model->selected_column = 0;
  424. }
  425. } else {
  426. byte_input_inc_selected_byte(model);
  427. }
  428. }
  429. /**
  430. * @brief Handle OK button
  431. *
  432. * @param model
  433. */
  434. static void byte_input_handle_ok(ByteInputModel* model) {
  435. if(byte_input_keyboard_selected(model)) {
  436. uint8_t value = byte_input_get_row(model->selected_row)[model->selected_column].value;
  437. if(value == enter_symbol) {
  438. byte_input_call_input_callback(model);
  439. } else if(value == backspace_symbol) {
  440. model->bytes[model->selected_byte] = 0;
  441. model->selected_high_nibble = true;
  442. byte_input_dec_selected_byte(model);
  443. byte_input_call_changed_callback(model);
  444. } else {
  445. byte_input_set_nibble(
  446. model->bytes, model->selected_byte, value, model->selected_high_nibble);
  447. if(model->selected_high_nibble == true) {
  448. model->selected_high_nibble = false;
  449. } else {
  450. byte_input_inc_selected_byte(model);
  451. model->selected_high_nibble = true;
  452. }
  453. byte_input_call_changed_callback(model);
  454. }
  455. } else {
  456. byte_input_transition_from_keyboard(model);
  457. }
  458. }
  459. /**
  460. * @brief Draw callback
  461. *
  462. * @param canvas
  463. * @param _model
  464. */
  465. static void byte_input_view_draw_callback(Canvas* canvas, void* _model) {
  466. ByteInputModel* model = _model;
  467. canvas_clear(canvas);
  468. canvas_set_color(canvas, ColorBlack);
  469. canvas_draw_str(canvas, 2, 9, model->header);
  470. canvas_set_font(canvas, FontKeyboard);
  471. if(model->selected_row == -1) {
  472. byte_input_draw_input_selected(canvas, model);
  473. } else {
  474. byte_input_draw_input(canvas, model);
  475. }
  476. for(uint8_t row = 0; row < keyboard_row_count; row++) {
  477. const uint8_t column_count = byte_input_get_row_size(row);
  478. const ByteInputKey* keys = byte_input_get_row(row);
  479. for(size_t column = 0; column < column_count; column++) {
  480. if(keys[column].value == enter_symbol) {
  481. canvas_set_color(canvas, ColorBlack);
  482. if(model->selected_row == row && model->selected_column == column) {
  483. canvas_draw_icon_name(
  484. canvas,
  485. keyboard_origin_x + keys[column].x,
  486. keyboard_origin_y + keys[column].y,
  487. I_KeySaveSelected_24x11);
  488. } else {
  489. canvas_draw_icon_name(
  490. canvas,
  491. keyboard_origin_x + keys[column].x,
  492. keyboard_origin_y + keys[column].y,
  493. I_KeySave_24x11);
  494. }
  495. } else if(keys[column].value == backspace_symbol) {
  496. canvas_set_color(canvas, ColorBlack);
  497. if(model->selected_row == row && model->selected_column == column) {
  498. canvas_draw_icon_name(
  499. canvas,
  500. keyboard_origin_x + keys[column].x,
  501. keyboard_origin_y + keys[column].y,
  502. I_KeyBackspaceSelected_16x9);
  503. } else {
  504. canvas_draw_icon_name(
  505. canvas,
  506. keyboard_origin_x + keys[column].x,
  507. keyboard_origin_y + keys[column].y,
  508. I_KeyBackspace_16x9);
  509. }
  510. } else {
  511. if(model->selected_row == row && model->selected_column == column) {
  512. canvas_set_color(canvas, ColorBlack);
  513. canvas_draw_box(
  514. canvas,
  515. keyboard_origin_x + keys[column].x - 3,
  516. keyboard_origin_y + keys[column].y - 10,
  517. 11,
  518. 13);
  519. canvas_set_color(canvas, ColorWhite);
  520. } else if(model->selected_row == -1 && row == 0 && model->selected_column == column) {
  521. canvas_set_color(canvas, ColorBlack);
  522. canvas_draw_frame(
  523. canvas,
  524. keyboard_origin_x + keys[column].x - 3,
  525. keyboard_origin_y + keys[column].y - 10,
  526. 11,
  527. 13);
  528. } else {
  529. canvas_set_color(canvas, ColorBlack);
  530. }
  531. canvas_draw_glyph(
  532. canvas,
  533. keyboard_origin_x + keys[column].x,
  534. keyboard_origin_y + keys[column].y,
  535. keys[column].value);
  536. }
  537. }
  538. }
  539. }
  540. /**
  541. * @brief Input callback
  542. *
  543. * @param event
  544. * @param context
  545. * @return true
  546. * @return false
  547. */
  548. static bool byte_input_view_input_callback(InputEvent* event, void* context) {
  549. ByteInput* byte_input = context;
  550. furi_assert(byte_input);
  551. bool consumed = false;
  552. if(event->type == InputTypeShort || event->type == InputTypeRepeat) {
  553. switch(event->key) {
  554. case InputKeyLeft:
  555. with_view_model(
  556. byte_input->view, (ByteInputModel * model) {
  557. byte_input_handle_left(model);
  558. return true;
  559. });
  560. consumed = true;
  561. break;
  562. case InputKeyRight:
  563. with_view_model(
  564. byte_input->view, (ByteInputModel * model) {
  565. byte_input_handle_right(model);
  566. return true;
  567. });
  568. consumed = true;
  569. break;
  570. case InputKeyUp:
  571. with_view_model(
  572. byte_input->view, (ByteInputModel * model) {
  573. byte_input_handle_up(model);
  574. return true;
  575. });
  576. consumed = true;
  577. break;
  578. case InputKeyDown:
  579. with_view_model(
  580. byte_input->view, (ByteInputModel * model) {
  581. byte_input_handle_down(model);
  582. return true;
  583. });
  584. consumed = true;
  585. break;
  586. case InputKeyOk:
  587. with_view_model(
  588. byte_input->view, (ByteInputModel * model) {
  589. byte_input_handle_ok(model);
  590. return true;
  591. });
  592. consumed = true;
  593. break;
  594. default:
  595. break;
  596. }
  597. }
  598. return consumed;
  599. }
  600. /**
  601. * @brief Reset all input-related data in model
  602. *
  603. * @param model ByteInputModel
  604. */
  605. static void byte_input_reset_model_input_data(ByteInputModel* model) {
  606. model->bytes = NULL;
  607. model->bytes_count = 0;
  608. model->selected_high_nibble = true;
  609. model->selected_byte = 0;
  610. model->selected_row = 0;
  611. model->selected_column = 0;
  612. model->first_visible_byte = 0;
  613. }
  614. /**
  615. * @brief Allocate and initialize byte input. This byte input is used to enter bytes.
  616. *
  617. * @return ByteInput instance pointer
  618. */
  619. ByteInput* byte_input_alloc() {
  620. ByteInput* byte_input = furi_alloc(sizeof(ByteInput));
  621. byte_input->view = view_alloc();
  622. view_set_context(byte_input->view, byte_input);
  623. view_allocate_model(byte_input->view, ViewModelTypeLocking, sizeof(ByteInputModel));
  624. view_set_draw_callback(byte_input->view, byte_input_view_draw_callback);
  625. view_set_input_callback(byte_input->view, byte_input_view_input_callback);
  626. with_view_model(
  627. byte_input->view, (ByteInputModel * model) {
  628. model->header = "";
  629. model->input_callback = NULL;
  630. model->changed_callback = NULL;
  631. model->callback_context = NULL;
  632. byte_input_reset_model_input_data(model);
  633. return true;
  634. });
  635. return byte_input;
  636. }
  637. /**
  638. * @brief Deinitialize and free byte input
  639. *
  640. * @param byte_input Byte input instance
  641. */
  642. void byte_input_free(ByteInput* byte_input) {
  643. furi_assert(byte_input);
  644. view_free(byte_input->view);
  645. free(byte_input);
  646. }
  647. /**
  648. * @brief Get byte input view
  649. *
  650. * @param byte_input byte input instance
  651. * @return View instance that can be used for embedding
  652. */
  653. View* byte_input_get_view(ByteInput* byte_input) {
  654. furi_assert(byte_input);
  655. return byte_input->view;
  656. }
  657. /**
  658. * @brief Deinitialize and free byte input
  659. *
  660. * @param byte_input byte input instance
  661. * @param input_callback input callback fn
  662. * @param changed_callback changed callback fn
  663. * @param callback_context callback context
  664. * @param bytes buffer to use
  665. * @param bytes_count buffer length
  666. */
  667. void byte_input_set_result_callback(
  668. ByteInput* byte_input,
  669. ByteInputCallback input_callback,
  670. ByteChangedCallback changed_callback,
  671. void* callback_context,
  672. uint8_t* bytes,
  673. uint8_t bytes_count) {
  674. with_view_model(
  675. byte_input->view, (ByteInputModel * model) {
  676. byte_input_reset_model_input_data(model);
  677. model->input_callback = input_callback;
  678. model->changed_callback = changed_callback;
  679. model->callback_context = callback_context;
  680. model->bytes = bytes;
  681. model->bytes_count = bytes_count;
  682. return true;
  683. });
  684. }
  685. /**
  686. * @brief Set byte input header text
  687. *
  688. * @param byte_input byte input instance
  689. * @param text text to be shown
  690. */
  691. void byte_input_set_header_text(ByteInput* byte_input, const char* text) {
  692. with_view_model(
  693. byte_input->view, (ByteInputModel * model) {
  694. model->header = text;
  695. return true;
  696. });
  697. }