quad-display

wkov/colony/quad-display

No description
quad-display
@/quad-display
PORTport
STRstring
ENboolean
quad-display
PORT
STR
EN
DONE
DONEpulse
Pulse when updating is done.
To use the node in your project you should have the wkov/colony 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 require "https://github.com/amperka/QuadDisplay2"

#pragma XOD dirtieness disable

#include <Wire.h>
#include <QuadDisplay2.h>

nodespace {

    uint8_t find(unsigned char ch) {
        switch(ch) {
            case '0': return QD_0;
            case '1': return QD_1;
            case '2': return QD_2;
            case '3': return QD_3;
            case '4': return QD_4;
            case '5': return QD_5;
            case '6': return QD_6;
            case '7': return QD_7;
            case '8': return QD_8;
            case '9': return QD_9;

            case '.': return QD_DOT;
            case '-': return QD_MINUS;
            case '*': return QD_DEGREE;
            case '_': return QD_UNDERSCORE;

            case 'A': return QD_A;
            case 'a': return QD_a;
            case 'b': return QD_b;
            case 'C': return QD_C;
            case 'c': return QD_c;
            case 'd': return QD_d;
            case 'E': return QD_E;
            case 'F': return QD_F;
            case 'f': return QD_f;
            case 'H': return QD_H;
            case 'h': return QD_h;
            case 'I': return QD_I;
            case 'J': return QD_J;
            case 'K': return QD_K;
            case 'L': return QD_L;
            case 'n': return QD_n;
            case 'O': return QD_O;
            case 'o': return QD_o;
            case 'P': return QD_P;
            case 'r': return QD_r;
            case 'S': return QD_S;
            case 't': return QD_t;
            case 'u': return QD_u;
            case 'U': return QD_U;
            case 'Y': return QD_Y;

             default: return QD_NONE;
        }
    }

    void print(QuadDisplay* quad, XString xstr, bool show) {
        if (!show) {
            quad->displayClear();
            return;
        }

        uint8_t codes[] = { QD_NONE, QD_NONE, QD_NONE, QD_NONE };
        uint8_t code;

        size_t i = 0;

        for (auto it = xstr.iterate(); it; ++it) {
            code = find(*it);
            if (code == QD_DOT) {
                if (i == 0) {
                    break;
                }
                codes[i - 1] &= code;
            } else {
                if (i > 4) {
                    break;
                }
                codes[i++] = code;
            }
        }

        quad->displayDigits(codes[0], codes[1], codes[2], codes[3]);
    }
}

node {
    QuadDisplay* quad;

    void evaluate(Context ctx) {
        if (!quad) {
            quad = new QuadDisplay(getValue<input_PORT>(ctx));
            quad->begin();
        }
        print(quad, getValue<input_STR>(ctx), getValue<input_EN>(ctx));
        emitValue<output_DONE>(ctx, true);
    }
}