/// <summary> /// Wrapper for the native <see cref="GpioSerialReadUnmanaged"/>. /// </summary> /// <param name="userGpio">The user gpio.</param> /// <param name="readLength">Length of the read.</param> /// <returns>The array containing the bytes that were read.</returns> public static byte[] GpioSerialRead(UserGpio userGpio, int readLength) { var buffer = new byte[readLength]; var result = BoardException.ValidateResult(GpioSerialReadUnmanaged(userGpio, buffer, (uint)readLength)); if (result == buffer.Length) { return(buffer); } var outputBuffer = new byte[result]; Buffer.BlockCopy(buffer, 0, outputBuffer, 0, result); return(outputBuffer); }
static void Change(UserGpio pin, LevelChange change, uint time) { if (change == LevelChange.LowToHigh) { lastHigh = time; } else if (change == LevelChange.HighToLow) { uint diff = time - lastHigh; if (diff >= TICKS_MIN_DCC_ONE && diff <= TICKS_MAX_DCC_ONE) { AddDidget(true); } else if (diff >= TICKS_MIN_DCC_ZERO && diff <= TICKS_MAX_DCC_ZERO) { AddDidget(false); } } }
/// <summary> /// This function configures the level logic for bit bang serial reads. /// /// Use PI_BB_SER_INVERT to invert the serial logic and PI_BB_SER_NORMAL for /// normal logic. Default is PI_BB_SER_NORMAL. /// /// The GPIO must be opened for bit bang reading of serial data using /// <see cref="GpioSerialReadOpen"/> prior to calling this function. /// </summary> /// <param name="userGpio">0-31.</param> /// <param name="invert">0-1.</param> /// <returns>Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_GPIO_IN_USE, PI_NOT_SERIAL_GPIO, or PI_BAD_SER_INVERT.</returns> public static ResultCode GpioSerialReadInvert(UserGpio userGpio, bool invert) { return(GpioSerialReadInvertUnmanaged(userGpio, invert ? DigitalValue.True : DigitalValue.False)); }
public static extern ResultCode GpioNoiseFilter(UserGpio userGpio, uint steadyMicroseconds, uint activeMicroseconds);
public static extern ResultCode GpioSetWatchdog(UserGpio userGpio, uint timeoutMilliseconds);
public static extern ResultCode GpioSetAlertFunc(UserGpio userGpio, [In, MarshalAs(UnmanagedType.FunctionPtr)] PiGpioAlertDelegate callback);
public static extern int BbSPIXfer(UserGpio csPin, [In, MarshalAs(UnmanagedType.LPArray)] byte[] inputBuffer, [In, MarshalAs(UnmanagedType.LPArray)] byte[] outputBuffer, uint count);
public static extern ResultCode BbSPIOpen(UserGpio csPin, UserGpio misoPin, UserGpio mosiPin, UserGpio clockPin, uint baudRate, SoftSpiFlags spiFlags);
/// <summary> /// Gets the PWM duty cycle. /// </summary> /// <param name="userGpio">The user gpio.</param> /// <returns>The PWM duty cycle</returns> public static int GpioGetPwmDutyCycle(UserGpio userGpio) { return(BoardException.ValidateResult(GpioGetPwmDutyCycleUnmanaged(userGpio))); }
public static extern int BbI2CZip(UserGpio sdaPin, [In, MarshalAs(UnmanagedType.LPArray)] byte[] inputBuffer, uint inputLength, [In, MarshalAs(UnmanagedType.LPArray)] byte[] outputBuffer, uint outputLength);
public static extern ResultCode BbI2CClose(UserGpio sdaPin);
public static extern ResultCode BbI2COpen(UserGpio sdaPin, UserGpio sclPin, uint baudRate);
public static extern int GpioWaveAddSerial(UserGpio userGpio, uint baudRate, uint dataBits, uint stopBits, uint offset, uint numBytes, [In, MarshalAs(UnmanagedType.LPArray)] byte[] str);
public static extern ResultCode GpioSerialReadClose(UserGpio userGpio);
/// <summary> /// Wrapper for the native <see cref="GpioSerialReadUnmanaged"/>. /// </summary> /// <param name="userGpio">The user gpio.</param> /// <param name="buffer">The buffer.</param> /// <param name="readLength">Length of the read.</param> /// <returns>The amount of bytes read.</returns> public static int GpioSerialRead(UserGpio userGpio, byte[] buffer, int readLength) { var result = BoardException.ValidateResult(GpioSerialReadUnmanaged(userGpio, buffer, (uint)readLength)); return(result); }
public static extern ResultCode GpioPwm(UserGpio userGpio, uint dutyCycle);
private static extern int GpioGetPwmRealRangeUnmanaged(UserGpio userGpio);
/// <summary> /// Returns 0 (off), 500 (most anti-clockwise) to 2500 (most clockwise) /// </summary> /// <param name="userGpio">The user gpio.</param> /// <returns>The Servo pulse width</returns> public static int GpioGetServoPulseWidth(UserGpio userGpio) { return(BoardException.ValidateResult(GpioGetServoPulseWidthUnmanaged(userGpio))); }
public static extern ResultCode GpioServo(UserGpio userGpio, uint pulseWidth);
public static extern ResultCode GpioSetPwmRange(UserGpio userGpio, uint range);
public static extern ResultCode BbSPIClose(UserGpio csPin);
public static extern int GpioGetPwmRange(UserGpio userGpio);
/// <summary> /// This function sends a trigger pulse to a GPIO. The GPIO is set to /// level for pulseLen microseconds and then reset to not level. /// /// or PI_BAD_PULSELEN. /// </summary> /// <param name="userGpio">0-31.</param> /// <param name="pulseLength">1-100.</param> /// <param name="value">0,1.</param> /// <returns>Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_LEVEL, or PI_BAD_PULSELEN.</returns> public static ResultCode GpioTrigger(UserGpio userGpio, uint pulseLength, bool value) { return(GpioTriggerUnmanaged(userGpio, pulseLength, value ? DigitalValue.True : DigitalValue.False)); }
public static extern ResultCode GpioSetPwmFrequency(UserGpio userGpio, uint frequency);
public static extern ResultCode GpioSetAlertFuncEx(UserGpio userGpio, [In, MarshalAs(UnmanagedType.FunctionPtr)] PiGpioAlertExDelegate callback, UIntPtr userData);
public static extern int GpioGetPwmFrequency(UserGpio userGpio);
public static extern ResultCode GpioGlitchFilter(UserGpio userGpio, uint steadyMicroseconds);
private static extern int GpioGetServoPulseWidthUnmanaged(UserGpio userGpio);
private static extern ResultCode GpioTriggerUnmanaged(UserGpio userGpio, uint pulseLength, DigitalValue value);
private static extern int GpioGetPwmDutyCycleUnmanaged(UserGpio userGpio);