byte_input.c 22 KB

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