blk_box_tc/main/drivers/star_code.h

60 lines
2.0 KiB
C

#ifndef STAR_CODE_H
#define STAR_CODE_H
#include <stdint.h>
/// @brief A handler for a specific star code
struct StarCodeEntry {
/// @brief The star code without the star
///
/// This must be <= 8 characters.
///
/// You may include a * in the code to match on any character
const char* code;
/// @brief The text to display when the star code is entered (or NULL).
///
/// This must be <= 9 characters.
const char* display_text;
/// @brief The number of ticks to delay when the star code is entered before calling the handler.
uint32_t delay_ticks;
/// @brief The function to call when the star code is entered.
void (*callback)(void);
};
/// @brief Adds a star code to be handled.
/// @param code the star code to add
/// @return true iff the star code was added
bool add_star_code(StarCodeEntry code);
/// @brief Adds a list of star codes to be handled.
/// @param codes the list of star codes to add
/// @param len the length of the list
/// @return true iff all the star codes were added
bool add_star_codes(const StarCodeEntry* codes, size_t len);
/// @brief removes a star code to stop handling it.
/// @param code the star code to remove
/// @return true iff the star code was removed
bool rm_star_code(const char* code);
/// @brief removes all given star codes to stop handling them.
/// @param codes the list of star codes to remove
/// @param len the length of the list
/// @return true iff all star codes were removed
bool rm_star_codes(const StarCodeEntry* codes, size_t len);
/// @brief removes all given star codes to stop handling them.
/// @param codes the list of star codes to remove
/// @param len the length of the list
/// @return true iff all star codes were removed
bool rm_star_codes_str(const char** codes, size_t len);
/// @brief clears all star codes.
void clear_star_codes();
/// @brief Triggers the given starcode.
/// @param code the star code to trigger (without the *)
/// @return true iff a star code was triggered
bool trigger_star_code(const char* code);
#endif /* STAR_CODE_H */