2022-02-25 15:22:58 +00:00
|
|
|
/**
|
|
|
|
* @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"
|
|
|
|
|
2022-05-27 11:19:21 +00:00
|
|
|
#include "m-string.h"
|
2022-02-25 15:22:58 +00:00
|
|
|
#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;
|
2022-03-23 18:51:40 +00:00
|
|
|
/** Path to remote file */
|
2022-05-27 11:19:21 +00:00
|
|
|
string_t path;
|
2022-02-25 15:22:58 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
/** Initialize new remote
|
2022-03-23 18:51:40 +00:00
|
|
|
*
|
|
|
|
* @param path - remote file path
|
2022-02-25 15:22:58 +00:00
|
|
|
*/
|
2022-05-27 11:19:21 +00:00
|
|
|
InfraredAppRemote(string_t file_path) {
|
|
|
|
string_init_set(path, file_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
~InfraredAppRemote() {
|
|
|
|
string_clear(path);
|
2022-02-25 15:22:58 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/** 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
|
2022-05-27 11:19:21 +00:00
|
|
|
* @param path - remote file path
|
2022-02-25 15:22:58 +00:00
|
|
|
*/
|
2022-05-27 11:19:21 +00:00
|
|
|
void find_vacant_remote_name(string_t name, string_t path);
|
2022-02-25 15:22:58 +00:00
|
|
|
|
|
|
|
/** 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
|
|
|
|
*
|
2022-05-27 11:19:21 +00:00
|
|
|
* @param path - path to remote file
|
2022-02-25 15:22:58 +00:00
|
|
|
* @retval true if success, false otherwise
|
|
|
|
*/
|
2022-05-27 11:19:21 +00:00
|
|
|
bool load(string_t path);
|
2022-02-25 15:22:58 +00:00
|
|
|
};
|