davetcc / tcMenu

Menu library for Arduino, mbed and ESP with designer UI and remote control capabilities.
https://www.thecoderscorner.com/products/arduino-libraries/tc-menu/
Apache License 2.0
271 stars 25 forks source link

Boolean menu item de-serialization #405

Closed vzahradnik closed 8 months ago

vzahradnik commented 9 months ago

Describe the bug Boolean menu item is incorrectly de/serialized. We have 4 naming types - TRUE_FALSE, ON_OFF, YES_NO and CHECKBOX. It looks like the checkbox was added just recently as there is no direct support in the parser.

In the toNaming() function it will fallback to YES_NO and in the fromNaming() function it will fallback to TRUE_FALSE

    private int fromNaming(BooleanMenuItem.BooleanNaming naming) {
        switch (naming) {

            case ON_OFF:
                return 1;
            case YES_NO:
                return 2;
            case TRUE_FALSE:
            default:
                return 0;
        }
    }

    private BooleanMenuItem.BooleanNaming toNaming(int i) {
        if(i==0) {
            return BooleanMenuItem.BooleanNaming.TRUE_FALSE;
        }
        else if(i==1) {
            return BooleanMenuItem.BooleanNaming.ON_OFF;
        }
        else {
            return BooleanMenuItem.BooleanNaming.YES_NO;
        }
    }

To Reproduce Just read the Java source code.

Expected behavior An explicit value is assigned for the Checkbox naming. Suggestion: CHECKBOX = 3. This is what I'll assign in the Python code until this issue is resolved.

davetcc commented 9 months ago

I'm really doubling down on the API at the moment, checking it for bugs while implementing the mobile app.