device-mx2125

bradzilla84/x2125/device-mx2125

A simple Wrapper for the MX2125 Library by Aaron Magill
device-mx2125
@/device-mx2125
A simple Wrapper for the MX2125 Library by Aaron Magill
XPinport
Constructor which sets the pins being used for the X-Axis. xPin and yPin should be digital pins, while tPin should be an analog pin. Undefined results if you choose poorly.
YPinport
Constructor which sets the pins being used for the Y-Axis reading. xPin and yPin should be digital pins, while tPin should be an analog pin. Undefined results if you choose poorly.
TPinport
Constructor which sets the pins being used for the T-Out reading for input. xPin and yPin should be digital pins, while tPin should be an analog pin. Undefined results if you choose poorly.
device-mx2125
OUT
XPin
YPin
TPin
OUT@/device-mx2125
To use the node in your project you should have the bradzilla84/x2125 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/asmagill/Mx2125"

{{#global}}
#include <Mx2125.h>
{{/global}}

struct State {
    uint8_t mem[sizeof(Mx2125)];
};

// Define our custom type as a pointer on the class instance.
using Type = Mx2125*;

{{ GENERATED_CODE }}

void evaluate(Context ctx) {

        // It should be evaluated only once on the first (setup) transaction
    if (!isSettingUp())
        return;

    auto state = getState(ctx);
    auto xPin = getValue<input_XPin>(ctx);
    auto yPin = getValue<input_YPin>(ctx);
    auto tPin = getValue<input_TPin>(ctx);

    // Create a new object in the memory area reserved previously.
    Type Accelerometer = new (state->mem) Mx2125(xPin, yPin, tPin);

    emitValue<output_OUT>(ctx, Accelerometer);

}