Falling,
Both
}
+ [StructLayout(LayoutKind.Sequential)]
+ public struct callbackInfo
+ {
+ public int vermagic;
+ public int gpioPinValue;
+ // skip the rest fields in structure as we do not need it
+ }
+ [StructLayout(LayoutKind.Sequential)]
+ public struct PeripherialGpio
+ {
+ public int vermagic;
+ public callbackInfo cbInfo;
+ // skip the rest fields in structure as we do not need it
+ }
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void InterruptedEventCallback(IntPtr handle, ErrorCode error, IntPtr data);
internal static extern ErrorCode UnsetInterruptedCb(IntPtr handle);
}
}
-}
\ No newline at end of file
+}
private void OnInterrupted(IntPtr handle, ErrorCode error, IntPtr data)
{
- ValueChanged?.Invoke(this, new PinUpdatedEventArgs(PinNumber, Read()));
+ NativeGpio.PeripherialGpio pio = (NativeGpio.PeripherialGpio)
+ System.Runtime.InteropServices.Marshal.PtrToStructure(handle,
+ typeof(NativeGpio.PeripherialGpio));
+ // check magic values to verify capi structures integrity
+ if (pio.vermagic != 13712 || pio.cbInfo.vermagic != 14469)
+ {
+ Log.Error("Peripheral",
+ "Unable to parse gpio structure in callback - vermagic is wrong");
+ return;
+ }
+ ValueChanged?.Invoke(this, new PinUpdatedEventArgs(PinNumber, pio.cbInfo.gpioPinValue == 1 ?
+ GpioPinValue.High : GpioPinValue.Low));
}
/// <summary>