set-gain

wayland/as7341-spectrometer/set-gain

Set the ADC gain multiplier.
set-gain
@/set-gain
Set the ADC gain multiplier.
DEV@/as7341-device
An as7341-device.
GAINnumber
ADC gain multiplier. Can take values of: 0.5, 1, 2, 4, 8, 16, 32, 64, 128, 256 and 512.
UPDpulse
Update.
set-gain
DEV
GAIN
UPD
DONE
DONEpulse
Pulses if gain is successfully set.
To use the node in your project you should have the wayland/as7341-spectrometer 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 evaluate_on_pin disable
#pragma XOD evaluate_on_pin enable input_UPD

node {
   void evaluate(Context ctx) {
       // The node responds only if there is an input pulse
       if (!isInputDirty<input_UPD>(ctx))
           return;

       auto sensor = getValue<input_DEV>(ctx);
       auto gain = getValue<input_GAIN>(ctx);


       if (gain<1) {
           if (!sensor->setGain(AS7341_GAIN_0_5X)) {
               raiseError(ctx);
               return;
           }
           emitValue<output_DONE>(ctx, 1);
       }

       if (gain==1) {
           if (!sensor->setGain(AS7341_GAIN_1X)) {
               raiseError(ctx);
               return;
           }
           emitValue<output_DONE>(ctx, 1);
       }

       if (gain==2) {
           if (!sensor->setGain(AS7341_GAIN_2X)) {
               raiseError(ctx);
               return;
           }
           emitValue<output_DONE>(ctx, 1);
       }

       if (gain==4) {
           if (!sensor->setGain(AS7341_GAIN_4X)) {
               raiseError(ctx);
               return;
           }
           emitValue<output_DONE>(ctx, 1);
       }

       if (gain==8) {
           if (!sensor->setGain(AS7341_GAIN_8X)) {
               raiseError(ctx);
               return;
           }
           emitValue<output_DONE>(ctx, 1);
       }

       if (gain==16) {
           if (!sensor->setGain(AS7341_GAIN_16X)) {
               raiseError(ctx);
               return;
           }
           emitValue<output_DONE>(ctx, 1);
       }

       if (gain==32) {
           if (!sensor->setGain(AS7341_GAIN_32X)) {
               raiseError(ctx);
               return;
           }
           emitValue<output_DONE>(ctx, 1);
       }

       if (gain==64) {
           if (!sensor->setGain(AS7341_GAIN_64X)) {
               raiseError(ctx);
               return;
           }
           emitValue<output_DONE>(ctx, 1);
       }

       if (gain==128) {
           if (!sensor->setGain(AS7341_GAIN_128X)) {
               raiseError(ctx);
               return;
           }
           emitValue<output_DONE>(ctx, 1);
       }

       if (gain==256) {
           if (!sensor->setGain(AS7341_GAIN_256X)) {
               raiseError(ctx);
               return;
           }
           emitValue<output_DONE>(ctx, 1);
       }

       if (gain==512) {
           if (!sensor->setGain(AS7341_GAIN_512X)) {
               raiseError(ctx);
               return;
           }
           emitValue<output_DONE>(ctx, 1);
       }

    }
}