translate-status-code-to-text

wayland/vl6180x-time-of-flight/translate-status-code-to-text

Translate status code to text string.
translate-status-code-to-text
@/translate-status-code-to-text
Translate status code to text string.
CODEbyte
Status code output from read-range node.
translate-status-code-to-text
CODE
TXT
TXTstring
Status as text.
To use the node in your project you should have the wayland/vl6180x-time-of-flight library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

#pragma XOD dirtieness disable

node {
    char str[24];
    CStringView view = CStringView(str);
    
    void evaluate(Context ctx) {
        uint8_t status = getValue<input_CODE>(ctx);
        
        if (status == 0) {
            view="No error";
        }
        else if  ((status >= 1) && (status <= 5)) {
            view="System error";
        }
        else if (status == 6) {
            view="ECE failure";
        }
        else if (status == 7) {
            view="No convergence";
        }
        else if (status == 8) {
            view="Ignoring range";
        }
        else if (status == 11) {
            view="Signal/Noise error";
        }
        else if (status == 12) {
            view="Raw reading underflow";
        }
        else if (status == 13) {
            view="Raw reading overflow";
        }
        else if (status == 14) {
            view="Range reading underflow";
        }
        else if (status == 15) {
            view="Range reading overflow";
        }
        else {
            view="Unknown code";
        }
        emitValue<output_TXT>(ctx, XString(&view));
    }
}