#ifndef STAR_CODE_H #define STAR_CODE_H #include #include #include /// The max length of a starcode (not counting the star) #define STARCODE_MAX_LEN 8 extern volatile bool handling_new_starcodes; /// @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. /// Can be null. void (*callback)(void); /// @brief The binary semaphore that will be given when this star code is triggered. /// Can be null. SemaphoreHandle_t triggered_sem; }; /// @brief Initializes the star code system. void init_star_code_system(); /// @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); /// @brief Tempararilly stops the starcode system from handling new starcodes. void pause_star_code_system(); /// @brief Resumes the starcode system to start handling new starcodes again. void resume_star_code_system(); #endif /* STAR_CODE_H */