irda-app-remote-manager.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #pragma once
  2. #include "sys/_stdint.h"
  3. #include <algorithm>
  4. #include <stdint.h>
  5. #include <string>
  6. #include <list>
  7. #include <vector>
  8. #include <memory>
  9. #include <irda.h>
  10. #include <sd-card-api.h>
  11. #include <filesystem-api.h>
  12. class IrdaAppRemoteButton {
  13. friend class IrdaAppRemoteManager;
  14. std::string name;
  15. IrdaMessage message;
  16. public:
  17. IrdaAppRemoteButton(const char* name, const IrdaMessage* message)
  18. : name(name), message (*message) {}
  19. ~IrdaAppRemoteButton() {}
  20. };
  21. class IrdaAppRemote {
  22. friend class IrdaAppRemoteManager;
  23. std::vector<IrdaAppRemoteButton> buttons;
  24. std::string name;
  25. public:
  26. IrdaAppRemote(const std::string& name);
  27. IrdaAppRemote& operator=(std::string& new_name) noexcept
  28. {
  29. name = new_name;
  30. buttons.clear();
  31. return *this;
  32. }
  33. };
  34. class IrdaAppRemoteManager {
  35. static const char* irda_directory;
  36. static const char* irda_extension;
  37. std::unique_ptr<IrdaAppRemote> remote;
  38. // TODO: make FS_Api and SdCard_Api unique_ptr
  39. SdCard_Api* sd_ex_api;
  40. FS_Api* fs_api;
  41. void show_file_error_message(const char* error_text) const;
  42. bool parse_button(std::string& str);
  43. std::string make_filename(const std::string& name) const;
  44. char file_buf[48];
  45. size_t file_buf_cnt = 0;
  46. public:
  47. bool add_remote_with_button(const char* button_name, const IrdaMessage* message);
  48. bool add_button(const char* button_name, const IrdaMessage* message);
  49. int find_remote_name(const std::vector<std::string>& strings);
  50. bool rename_button(uint32_t index, const char* str);
  51. bool rename_remote(const char* str);
  52. bool get_remote_list(std::vector<std::string>& remote_names) const;
  53. std::vector<std::string> get_button_list() const;
  54. std::string get_button_name(uint32_t index);
  55. std::string get_remote_name();
  56. size_t get_number_of_buttons();
  57. const IrdaMessage* get_button_data(size_t button_index) const;
  58. bool delete_button(uint32_t index);
  59. bool delete_remote();
  60. IrdaAppRemoteManager();
  61. ~IrdaAppRemoteManager();
  62. bool store();
  63. bool load(const std::string& name);
  64. bool check_fs() const;
  65. };