| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- /**
- * @file infrared_app_remote_manager.h
- * Infrared: Remote manager class.
- * It holds remote, can load/save/rename remote,
- * add/remove/rename buttons.
- */
- #pragma once
- #include "infrared_app_signal.h"
- #include "m-string.h"
- #include <infrared_worker.h>
- #include <infrared.h>
- #include <cstdint>
- #include <string>
- #include <memory>
- #include <vector>
- /** Class to handle remote button */
- class InfraredAppRemoteButton {
- /** Allow field access */
- friend class InfraredAppRemoteManager;
- /** Name of signal */
- std::string name;
- /** Signal data */
- InfraredAppSignal signal;
- public:
- /** Initialize remote button
- *
- * @param name - button name
- * @param signal - signal to copy for remote button
- */
- InfraredAppRemoteButton(const char* name, const InfraredAppSignal& signal)
- : name(name)
- , signal(signal) {
- }
- /** Initialize remote button
- *
- * @param name - button name
- * @param signal - signal to move for remote button
- */
- InfraredAppRemoteButton(const char* name, InfraredAppSignal&& signal)
- : name(name)
- , signal(std::move(signal)) {
- }
- /** Deinitialize remote button */
- ~InfraredAppRemoteButton() {
- }
- };
- /** Class to handle remote */
- class InfraredAppRemote {
- /** Allow field access */
- friend class InfraredAppRemoteManager;
- /** Button container */
- std::vector<InfraredAppRemoteButton> buttons;
- /** Name of remote */
- std::string name;
- /** Path to remote file */
- string_t path;
- public:
- /** Initialize new remote
- *
- * @param path - remote file path
- */
- InfraredAppRemote(string_t file_path) {
- string_init_set(path, file_path);
- }
- ~InfraredAppRemote() {
- string_clear(path);
- }
- };
- /** Class to handle remote manager */
- class InfraredAppRemoteManager {
- /** Remote instance. There can be 1 remote loaded at a time. */
- std::unique_ptr<InfraredAppRemote> remote;
- public:
- /** Restriction to button name length. Buttons larger are ignored. */
- static constexpr const uint32_t max_button_name_length = 22;
- /** Restriction to remote name length. Remotes larger are ignored. */
- static constexpr const uint32_t max_remote_name_length = 22;
- /** Construct button from signal, and create remote
- *
- * @param button_name - name of button to create
- * @param signal - signal to create button from
- * @retval true for success, false otherwise
- * */
- bool add_remote_with_button(const char* button_name, const InfraredAppSignal& signal);
- /** Add button to current remote
- *
- * @param button_name - name of button to create
- * @param signal - signal to create button from
- * @retval true for success, false otherwise
- * */
- bool add_button(const char* button_name, const InfraredAppSignal& signal);
- /** Rename button in current remote
- *
- * @param index - index of button to rename
- * @param str - new button name
- */
- bool rename_button(uint32_t index, const char* str);
- /** Rename current remote
- *
- * @param str - new remote name
- */
- bool rename_remote(const char* str);
- /** Find vacant remote name. If suggested name is occupied,
- * incremented digit(2,3,4,etc) added to name and check repeated.
- *
- * @param name - suggested remote name
- * @param path - remote file path
- */
- void find_vacant_remote_name(string_t name, string_t path);
- /** Get button list
- *
- * @retval container of button names
- */
- std::vector<std::string> get_button_list() const;
- /** Get button name by index
- *
- * @param index - index of button to get name from
- * @retval button name
- */
- std::string get_button_name(uint32_t index);
- /** Get remote name
- *
- * @retval remote name
- */
- std::string get_remote_name();
- /** Get number of buttons
- *
- * @retval number of buttons
- */
- size_t get_number_of_buttons();
- /** Get button's signal
- *
- * @param index - index of interested button
- * @retval signal
- */
- const InfraredAppSignal& get_button_data(size_t index) const;
- /** Delete button
- *
- * @param index - index of interested button
- * @retval true if success, false otherwise
- */
- bool delete_button(uint32_t index);
- /** Delete remote
- *
- * @retval true if success, false otherwise
- */
- bool delete_remote();
- /** Clean all loaded info in current remote */
- void reset_remote();
- /** Store current remote data on disk
- *
- * @retval true if success, false otherwise
- */
- bool store();
- /** Load data from disk into current remote
- *
- * @param path - path to remote file
- * @retval true if success, false otherwise
- */
- bool load(string_t path);
- };
|