ibutton-scene-select-key.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "ibutton-scene-select-key.h"
  2. #include "../ibutton-app.h"
  3. #include "../ibutton-event.h"
  4. #include "../ibutton-key.h"
  5. void iButtonSceneSelectKey::on_enter(iButtonApp* app) {
  6. // Input events and views are managed by file_select
  7. bool res = app->get_sd_ex_api()->file_select(
  8. app->get_sd_ex_api()->context,
  9. "ibutton",
  10. "*",
  11. app->get_file_name(),
  12. app->get_file_name_size());
  13. // Process file_select return
  14. if(res) {
  15. // Get key file path
  16. string_t key_str;
  17. string_init_set_str(key_str, "ibutton/");
  18. string_cat_str(key_str, app->get_file_name());
  19. // Read data from file
  20. File key_file;
  21. uint8_t key_data[IBUTTON_KEY_DATA_SIZE + 1] = {};
  22. // TODO process false result from file system service
  23. app->get_fs_api()->file.open(
  24. &key_file, string_get_cstr(key_str), FSAM_READ, FSOM_OPEN_EXISTING);
  25. app->get_fs_api()->file.read(&key_file, key_data, IBUTTON_KEY_DATA_SIZE + 1);
  26. app->get_fs_api()->file.close(&key_file);
  27. string_clear(key_str);
  28. // Set key data
  29. iButtonKeyType key_type = static_cast<iButtonKeyType>(key_data[0]);
  30. if(key_type > iButtonKeyType::KeyMetakom) {
  31. app->switch_to_next_scene(iButtonApp::Scene::SceneStart);
  32. }
  33. app->get_key()->set_name(app->get_file_name());
  34. app->get_key()->set_type(key_type);
  35. app->get_key()->set_data(key_data + 1, IBUTTON_KEY_DATA_SIZE);
  36. app->switch_to_next_scene(iButtonApp::Scene::SceneSavedKeyMenu);
  37. } else {
  38. app->switch_to_previous_scene();
  39. }
  40. }
  41. bool iButtonSceneSelectKey::on_event(iButtonApp* app, iButtonEvent* event) {
  42. return false;
  43. }
  44. void iButtonSceneSelectKey::on_exit(iButtonApp* app) {
  45. }