2023-10-30 19:20:35 +03:00
|
|
|
/**
|
|
|
|
* @file infrared_remote.h
|
|
|
|
* @brief Infrared remote library.
|
|
|
|
*
|
|
|
|
* An infrared remote contains zero or more infrared signals which
|
|
|
|
* have a (possibly non-unique) name each.
|
|
|
|
*
|
|
|
|
* The current implementation does load only the names into the memory,
|
|
|
|
* while the signals themselves are loaded on-demand one by one. In theory,
|
|
|
|
* this should allow for quite large remotes with relatively bulky signals.
|
|
|
|
*/
|
2022-06-21 15:45:50 +03:00
|
|
|
#pragma once
|
|
|
|
|
2023-10-30 19:20:35 +03:00
|
|
|
#include "infrared_signal.h"
|
2022-06-21 15:45:50 +03:00
|
|
|
|
2023-10-30 19:20:35 +03:00
|
|
|
/**
|
|
|
|
* @brief InfraredRemote opaque type declaration.
|
|
|
|
*/
|
2022-06-21 15:45:50 +03:00
|
|
|
typedef struct InfraredRemote InfraredRemote;
|
|
|
|
|
2023-10-30 19:20:35 +03:00
|
|
|
/**
|
|
|
|
* @brief Create a new InfraredRemote instance.
|
|
|
|
*
|
|
|
|
* @returns pointer to the created instance.
|
|
|
|
*/
|
2024-03-19 17:43:52 +03:00
|
|
|
InfraredRemote* infrared_remote_alloc(void);
|
2023-10-30 19:20:35 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Delete an InfraredRemote instance.
|
|
|
|
*
|
|
|
|
* @param[in,out] remote pointer to the instance to be deleted.
|
|
|
|
*/
|
2022-06-21 15:45:50 +03:00
|
|
|
void infrared_remote_free(InfraredRemote* remote);
|
2023-10-30 19:20:35 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Reset an InfraredRemote instance.
|
|
|
|
*
|
|
|
|
* Resetting a remote clears its signal name list and
|
|
|
|
* the associated file path.
|
|
|
|
*
|
|
|
|
* @param[in,out] remote pointer to the instance to be deleted.
|
|
|
|
*/
|
2022-06-21 15:45:50 +03:00
|
|
|
void infrared_remote_reset(InfraredRemote* remote);
|
|
|
|
|
2023-10-30 19:20:35 +03:00
|
|
|
/**
|
|
|
|
* @brief Get an InfraredRemote instance's name.
|
|
|
|
*
|
|
|
|
* The name is deduced from the file path.
|
|
|
|
*
|
|
|
|
* The return value remains valid unless one of the following functions is called:
|
|
|
|
* - infrared_remote_reset()
|
|
|
|
* - infrared_remote_load()
|
|
|
|
* - infrared_remote_create()
|
|
|
|
*
|
|
|
|
* @param[in] remote pointer to the instance to be queried.
|
|
|
|
* @returns pointer to a zero-terminated string containing the name.
|
|
|
|
*/
|
|
|
|
const char* infrared_remote_get_name(const InfraredRemote* remote);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get an InfraredRemote instance's file path.
|
|
|
|
*
|
|
|
|
* Same return value validity considerations as infrared_remote_get_name().
|
|
|
|
*
|
|
|
|
* @param[in] remote pointer to the instance to be queried.
|
|
|
|
* @returns pointer to a zero-terminated string containing the path.
|
|
|
|
*/
|
|
|
|
const char* infrared_remote_get_path(const InfraredRemote* remote);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get the number of signals listed in an InfraredRemote instance.
|
|
|
|
*
|
|
|
|
* @param[in] remote pointer to the instance to be queried.
|
|
|
|
* @returns number of signals, zero or more
|
|
|
|
*/
|
|
|
|
size_t infrared_remote_get_signal_count(const InfraredRemote* remote);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get the name of a signal listed in an InfraredRemote instance.
|
|
|
|
*
|
|
|
|
* @param[in] remote pointer to the instance to be queried.
|
|
|
|
* @param[in] index index of the signal in question. Must be less than the total signal count.
|
|
|
|
*/
|
|
|
|
const char* infrared_remote_get_signal_name(const InfraredRemote* remote, size_t index);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get the index of a signal listed in an InfraredRemote instance by its name.
|
|
|
|
*
|
|
|
|
* @param[in] remote pointer to the instance to be queried.
|
|
|
|
* @param[in] name pointer to a zero-terminated string containig the name of the signal in question.
|
|
|
|
* @param[out] index pointer to the variable to hold the signal index.
|
|
|
|
* @returns true if a signal with the given name was found, false otherwise.
|
|
|
|
*/
|
|
|
|
bool infrared_remote_get_signal_index(
|
|
|
|
const InfraredRemote* remote,
|
|
|
|
const char* name,
|
|
|
|
size_t* index);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Load a signal listed in an InfraredRemote instance.
|
|
|
|
*
|
|
|
|
* As mentioned above, the signals are loaded on-demand. The user code must call this function
|
|
|
|
* each time it wants to interact with a new signal.
|
|
|
|
*
|
|
|
|
* @param[in] remote pointer to the instance to load from.
|
|
|
|
* @param[out] signal pointer to the signal to load into. Must be allocated.
|
|
|
|
* @param[in] index index of the signal to be loaded. Must be less than the total signal count.
|
2024-09-06 12:52:00 +03:00
|
|
|
* @return InfraredErrorCodeNone if the signal was successfully loaded, otherwise error code.
|
2023-10-30 19:20:35 +03:00
|
|
|
*/
|
2024-09-06 12:52:00 +03:00
|
|
|
InfraredErrorCode
|
|
|
|
infrared_remote_load_signal(const InfraredRemote* remote, InfraredSignal* signal, size_t index);
|
2023-10-30 19:20:35 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Append a signal to the file associated with an InfraredRemote instance.
|
|
|
|
*
|
|
|
|
* The file path must be somehow initialised first by calling either infrared_remote_load() or
|
|
|
|
* infrared_remote_create(). As the name suggests, the signal will be put in the end of the file.
|
|
|
|
*
|
|
|
|
* @param[in,out] remote pointer to the instance to append to.
|
|
|
|
* @param[in] signal pointer to the signal to be appended.
|
|
|
|
* @param[in] name pointer to a zero-terminated string containing the name of the signal.
|
2024-09-06 12:52:00 +03:00
|
|
|
* @returns InfraredErrorCodeNone if the signal was successfully appended, otherwise error code.
|
2023-10-30 19:20:35 +03:00
|
|
|
*/
|
2024-09-06 12:52:00 +03:00
|
|
|
InfraredErrorCode infrared_remote_append_signal(
|
2023-10-30 19:20:35 +03:00
|
|
|
InfraredRemote* remote,
|
|
|
|
const InfraredSignal* signal,
|
|
|
|
const char* name);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Insert a signal to the file associated with an InfraredRemote instance.
|
|
|
|
*
|
|
|
|
* Same behaviour as infrared_remote_append_signal(), but the user code can decide where to
|
|
|
|
* put the signal in the file.
|
|
|
|
*
|
|
|
|
* Index values equal to or greater than the total signal count will result in behaviour
|
|
|
|
* identical to infrared_remote_append_signal().
|
|
|
|
*
|
|
|
|
* @param[in,out] remote pointer to the instance to insert to.
|
|
|
|
* @param[in] signal pointer to the signal to be inserted.
|
|
|
|
* @param[in] name pointer to a zero-terminated string containing the name of the signal.
|
|
|
|
* @param[in] index the index under which the signal shall be inserted.
|
2024-09-06 12:52:00 +03:00
|
|
|
* @returns InfraredErrorCodeNone if the signal was successfully inserted, otherwise error
|
|
|
|
* code describing what error happened ORed with index pointing which signal caused an error.
|
2023-10-30 19:20:35 +03:00
|
|
|
*/
|
2024-09-06 12:52:00 +03:00
|
|
|
InfraredErrorCode infrared_remote_insert_signal(
|
2023-10-30 19:20:35 +03:00
|
|
|
InfraredRemote* remote,
|
|
|
|
const InfraredSignal* signal,
|
|
|
|
const char* name,
|
|
|
|
size_t index);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Rename a signal in the file associated with an InfraredRemote instance.
|
|
|
|
*
|
|
|
|
* Only changes the signal's name, but neither its position nor contents.
|
|
|
|
*
|
|
|
|
* @param[in,out] remote pointer to the instance to be modified.
|
|
|
|
* @param[in] index index of the signal to be renamed. Must be less than the total signal count.
|
|
|
|
* @param[in] new_name pointer to a zero-terminated string containig the signal's new name.
|
2024-09-06 12:52:00 +03:00
|
|
|
* @returns InfraredErrorCodeNone if the signal was successfully renamed, otherwise error code.
|
2023-10-30 19:20:35 +03:00
|
|
|
*/
|
2024-09-06 12:52:00 +03:00
|
|
|
InfraredErrorCode
|
|
|
|
infrared_remote_rename_signal(InfraredRemote* remote, size_t index, const char* new_name);
|
2023-10-30 19:20:35 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Change a signal's position in the file associated with an InfraredRemote instance.
|
|
|
|
*
|
|
|
|
* Only changes the signal's position (index), but neither its name nor contents.
|
|
|
|
*
|
|
|
|
* @param[in,out] remote pointer to the instance to be modified.
|
|
|
|
* @param[in] index index of the signal to be moved. Must be less than the total signal count.
|
|
|
|
* @param[in] new_index index of the signal to be moved. Must be less than the total signal count.
|
2024-09-06 12:52:00 +03:00
|
|
|
* @returns InfraredErrorCodeNone if the signal was moved successfully, otherwise error
|
|
|
|
* code describing what error happened ORed with index pointing which signal caused an error.
|
2023-10-30 19:20:35 +03:00
|
|
|
*/
|
2024-09-06 12:52:00 +03:00
|
|
|
InfraredErrorCode
|
|
|
|
infrared_remote_move_signal(InfraredRemote* remote, size_t index, size_t new_index);
|
2023-10-30 19:20:35 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Delete a signal in the file associated with an InfraredRemote instance.
|
|
|
|
*
|
|
|
|
* @param[in,out] remote pointer to the instance to be modified.
|
|
|
|
* @param[in] index index of the signal to be deleted. Must be less than the total signal count.
|
2024-09-06 12:52:00 +03:00
|
|
|
* @returns InfraredErrorCodeNone if the signal was successfully deleted, otherwise error
|
|
|
|
* code describing what error happened ORed with index pointing which signal caused an error.
|
2023-10-30 19:20:35 +03:00
|
|
|
*/
|
2024-09-06 12:52:00 +03:00
|
|
|
InfraredErrorCode infrared_remote_delete_signal(InfraredRemote* remote, size_t index);
|
2022-06-21 15:45:50 +03:00
|
|
|
|
2023-10-30 19:20:35 +03:00
|
|
|
/**
|
|
|
|
* @brief Create a new file and associate it with an InfraredRemote instance.
|
|
|
|
*
|
|
|
|
* The instance will be reset and given a new empty file with just the header.
|
|
|
|
*
|
|
|
|
* @param[in,out] remote pointer to the instance to be assigned with a new file.
|
|
|
|
* @param[in] path pointer to a zero-terminated string containing the full file path.
|
2024-09-06 12:52:00 +03:00
|
|
|
* @returns InfraredErrorCodeNone if the file was successfully created, otherwise error code.
|
2023-10-30 19:20:35 +03:00
|
|
|
*/
|
2024-09-06 12:52:00 +03:00
|
|
|
InfraredErrorCode infrared_remote_create(InfraredRemote* remote, const char* path);
|
2022-06-21 15:45:50 +03:00
|
|
|
|
2023-10-30 19:20:35 +03:00
|
|
|
/**
|
|
|
|
* @brief Associate an InfraredRemote instance with a file and load the signal names from it.
|
|
|
|
*
|
|
|
|
* The instance will be reset and fill its signal name list from the given file.
|
|
|
|
* The file must already exist and be valid.
|
|
|
|
*
|
|
|
|
* @param[in,out] remote pointer to the instance to be assigned with an existing file.
|
|
|
|
* @param[in] path pointer to a zero-terminated string containing the full file path.
|
2024-09-06 12:52:00 +03:00
|
|
|
* @returns InfraredErrorCodeNone if the file was successfully loaded, otherwise error code.
|
2023-10-30 19:20:35 +03:00
|
|
|
*/
|
2024-09-06 12:52:00 +03:00
|
|
|
InfraredErrorCode infrared_remote_load(InfraredRemote* remote, const char* path);
|
2022-06-21 15:45:50 +03:00
|
|
|
|
2023-10-30 19:20:35 +03:00
|
|
|
/**
|
|
|
|
* @brief Rename the file associated with an InfraredRemote instance.
|
|
|
|
*
|
|
|
|
* Only renames the file, no signals are added, moved or deleted.
|
|
|
|
*
|
|
|
|
* @param[in,out] remote pointer to the instance to be modified.
|
|
|
|
* @param[in] new_path pointer to a zero-terminated string containing the new full file path.
|
2024-09-06 12:52:00 +03:00
|
|
|
* @returns InfraredErrorCodeNone if the file was successfully renamed, otherwise error code.
|
2023-10-30 19:20:35 +03:00
|
|
|
*/
|
2024-09-06 12:52:00 +03:00
|
|
|
InfraredErrorCode infrared_remote_rename(InfraredRemote* remote, const char* new_path);
|
2022-06-21 15:45:50 +03:00
|
|
|
|
2023-10-30 19:20:35 +03:00
|
|
|
/**
|
|
|
|
* @brief Remove the file associated with an InfraredRemote instance.
|
|
|
|
*
|
|
|
|
* This operation is irreversible and fully deletes the remote file
|
|
|
|
* from the underlying filesystem.
|
|
|
|
* After calling this function, the instance becomes invalid until
|
|
|
|
* infrared_remote_create() or infrared_remote_load() are successfully executed.
|
|
|
|
*
|
|
|
|
* @param[in,out] remote pointer to the instance to be modified.
|
2024-09-06 12:52:00 +03:00
|
|
|
* @returns InfraredErrorCodeNone if the file was successfully removed, otherwise error code.
|
2023-10-30 19:20:35 +03:00
|
|
|
*/
|
2024-09-06 12:52:00 +03:00
|
|
|
InfraredErrorCode infrared_remote_remove(InfraredRemote* remote);
|