Skip to content

Support for stable effects / palettes configuration #230

Open
@henrygab

Description

@henrygab

Currently, when the list of palettes or effects changes, any saved configuration is implicitly invalidated. This is because, currently, the value is stored as an integer index into the array. However, it is not currently detected as an invalid saved index. This is also true for the definition of the per-product default effect.

Goals:

  • Store selected default pattern in a manner that detects the implicit invalidation
  • Allow declaration of default pattern using a name (not an array index)

Work-in-Progress

Solution is now written (but not yet tested on real hardware). Feedback on design is welcome on PR #234.


complex thoughts using constexpr, now moot

Note

Here, I use the term string to refer to const char *, typically stored in ROM. The term String is an Arduino-specific construct, that unfortunately is not currently constexpr compliant. The term F-string refers to the Arduino-specific flash string helper, which is also not constexpr compliant.


Expected functionality required:

  • A constexpr class that can be constructed from F-String or const char * as constexpr, and supports the below functionalities
    • constexpr case-sensitive comparison
    • constexpr case-sensitive equality
    • constexpr case-insensitive (US-EN, ASCII only) comparison
    • constexpr case-insensitive (US-EN, ASCII only) equality
    • constexpr case-sensitive uint32_t result hash function
    • constexpr conversion to lowercase (US-EN, ASCII only) version of string

Then, given constant arrays of const POD structures, where one member is a const char * null-terminated string...

  • A constexpr function that, given that array and a hash of a target string, returns a first index to the matching string.

  • A constexpr function that, given that array and a target string or F-String, returns an array index that contains a matching string.

    Psuedocode strawman

    // ignoring the C++11 requirement that a constexpr be a single return statement ... this is just psuedocode
    template<typename T, size_t INDEX>
    size_t IndexOfMatchingMemberImpl(T type, const char * stringToFind) {
        return ( constexpr_compliant_string_comparison( T[INDEX].Name, stringToFind ) == 0 ) ?
            INDEX :
            IndexOfMatchingMemberImpl<T, INDEX-1>(type, stringToFind);
    }
    template<typename T>
    size_t IndexOfMatchingMemberImpl<T,0>(T type, const char * stringToFind) {
        static_assert( constexpr_compliant_string_comparison( T[0].Name, stringToFind ) == 0, "Unable to find matching string" );
        return ( constexpr_compliant_string_comparison( T[0].Name, stringToFind ) == 0 ) ? 0 : -1;
    }
    template<typename T, size_t N>
    size_t IndexOfMatchingMember(T type[N], const char * stringToFind) {
        return IndexOfMatchingMemberImpl<T, N-1>(type, stringToFind);
    }

What the above could enable

  • Products can store default patterns using friendly name, rather than opaque (and unstable) array index
  • Configuration can store array index + hash of the string, to detect invalidation

Other considerations

Maybe there's already a library to do this?

See also:

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions