byte_input.c 21 KB

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