void GpioChangeListener(object param) { int recvSize = 4096; byte[] buf = new byte[recvSize]; int messageSize = 12; while (m_run == true) { try { var bytesReceived = m_socket.Receive(buf, recvSize, SocketFlags.None); int offset = 0; while ((bytesReceived - offset) >= messageSize) { var seq = (ushort)PiGpioSharp.GetInt16FromByteArrayEndianessCorrected(buf, 0 + offset); var flags = (ushort)PiGpioSharp.GetInt16FromByteArrayEndianessCorrected(buf, 2 + offset); var tick = (uint)PiGpioSharp.GetInt32FromByteArrayEndianessCorrected(buf, 4 + offset); var level = (uint)PiGpioSharp.GetInt32FromByteArrayEndianessCorrected(buf, 8 + offset); offset += messageSize; if (flags == 0) { var changes = m_lastLevel ^ level; m_lastLevel = level; m_lock.WaitOne(); var tmpsubscribers = new Dictionary <int, GpioSubscriber>(m_changeSubscribers); m_lock.ReleaseMutex(); foreach (var subscriber in tmpsubscribers) { if (((1 << subscriber.Value.GpioNumber) & changes) > 0) { var newLevel = (uint)0; if (((1 << subscriber.Value.GpioNumber) & level) > 0) { newLevel = 1; } if ((newLevel ^ (uint)subscriber.Value.Edge) > 0) { subscriber.Value.Callback(subscriber.Value.GpioNumber, newLevel, tick); } } } } } /* TODO: Add other flags */ } catch (SocketException) { } } }
public Serial(PiGpioSharp pi) { m_pi = pi; }
public Gpio(PiGpioSharp pi) { m_pi = pi; m_run = false; m_lock = new Mutex(); }