nfc_maker_scene_bluetooth.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "../nfc_maker.h"
  2. enum ByteInputResult {
  3. ByteInputResultOk,
  4. };
  5. static void nfc_maker_scene_bluetooth_byte_input_callback(void* context) {
  6. NfcMaker* app = context;
  7. view_dispatcher_send_custom_event(app->view_dispatcher, ByteInputResultOk);
  8. }
  9. static void reverse_mac_addr(uint8_t mac_addr[GAP_MAC_ADDR_SIZE]) {
  10. uint8_t tmp;
  11. for(size_t i = 0; i < GAP_MAC_ADDR_SIZE / 2; i++) {
  12. tmp = mac_addr[i];
  13. mac_addr[i] = mac_addr[GAP_MAC_ADDR_SIZE - 1 - i];
  14. mac_addr[GAP_MAC_ADDR_SIZE - 1 - i] = tmp;
  15. }
  16. }
  17. void nfc_maker_scene_bluetooth_on_enter(void* context) {
  18. NfcMaker* app = context;
  19. ByteInput* byte_input = app->byte_input;
  20. byte_input_set_header_text(byte_input, "Enter Bluetooth MAC:");
  21. for(size_t i = 0; i < sizeof(app->mac_buf); i++) {
  22. app->mac_buf[i] = 0x42;
  23. }
  24. byte_input_set_result_callback(
  25. byte_input,
  26. nfc_maker_scene_bluetooth_byte_input_callback,
  27. NULL,
  28. app,
  29. app->mac_buf,
  30. sizeof(app->mac_buf));
  31. view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewByteInput);
  32. }
  33. bool nfc_maker_scene_bluetooth_on_event(void* context, SceneManagerEvent event) {
  34. NfcMaker* app = context;
  35. bool consumed = false;
  36. if(event.type == SceneManagerEventTypeCustom) {
  37. consumed = true;
  38. switch(event.event) {
  39. case ByteInputResultOk:
  40. reverse_mac_addr(app->mac_buf);
  41. scene_manager_next_scene(app->scene_manager, NfcMakerSceneSaveGenerate);
  42. break;
  43. default:
  44. break;
  45. }
  46. }
  47. return consumed;
  48. }
  49. void nfc_maker_scene_bluetooth_on_exit(void* context) {
  50. NfcMaker* app = context;
  51. byte_input_set_result_callback(app->byte_input, NULL, NULL, NULL, NULL, 0);
  52. byte_input_set_header_text(app->byte_input, "");
  53. }