public static IPin ByDirection(IBaseFilter vSource, PinDirection vDir, int iIndex) { IEnumPins pins; IPin[] ppPins = new IPin[1]; if (vSource == null) { return(null); } DsError.ThrowExceptionForHR(vSource.EnumPins(out pins)); try { while (pins.Next(1, ppPins, IntPtr.Zero) == 0) { PinDirection direction; DsError.ThrowExceptionForHR(ppPins[0].QueryDirection(out direction)); if (direction == vDir) { if (iIndex == 0) { return(ppPins[0]); } iIndex--; } Marshal.ReleaseComObject(ppPins[0]); } } finally { Marshal.ReleaseComObject(pins); } return(null); }
/// <summary> /// ピンの入出力方向を設定 /// </summary> /// <param name="port">ポート番号</param> /// <param name="pin">ピン番号</param> /// <param name="pinDirection">設定値</param> public void SetPinDirection(int port, int pin, PinDirection pinDirection) { if (port < 0 || PortMax < port) { throw new ArgumentOutOfRangeException(nameof(port)); } if (pin < 0 || 7 < pin) { throw new ArgumentOutOfRangeException(nameof(pin)); } byte value; if (pinDirection == PinDirection.Input) { value = (byte)(_portDirection.Span[port] | (1 << pin)); } else { value = (byte)(_portDirection.Span[port] & ~(1 << pin)); } SetPortDirection(port, value); }
public BasePin(PinDirection direction, BaseFilter filter) { AcceptsAnyMedia = true; MediaTypes.Add(new AMMediaType()); _Direction = direction; _Filter = filter; }
public static IPin GetPin(IBaseFilter filter, PinDirection dir, int num) { IPin[] array = new IPin[1]; IEnumPins enumPins = null; if (filter.EnumPins(out enumPins) == 0) { try { int pinsFetched; while (enumPins.Next(1, array, out pinsFetched) == 0) { array[0].QueryDirection(out PinDirection pinDirection); if (pinDirection == dir) { if (num == 0) { return(array[0]); } num--; } Marshal.ReleaseComObject(array[0]); array[0] = null; } } finally { Marshal.ReleaseComObject(enumPins); } } return(null); }
protected GPIOPin(PinDirection direction, PhysicalPin pin) { Pin = pin; Direction = direction; ExportPin(); }
private static void SetPinDirection(string fullFilePath, PinDirection direction) { using (var streamWriter = new StreamWriter(fullFilePath, false)) { streamWriter.Write(direction == PinDirection.Input ? "in" : "out"); } }
/// <summary> /// Allocates the specified pin. /// </summary> /// <param name="pin">The pin.</param> /// <param name="direction">The direction.</param> public void Allocate(ProcessorPin pin, PinDirection direction) { this.Release(pin); using (var streamWriter = new StreamWriter(Path.Combine(GpioPath, "export"), false)) { streamWriter.Write((int)pin); } if (!GpioPathList.ContainsKey(pin)) { var gpio = new FileGpioHandle { GpioPath = GuessGpioPath(pin) }; GpioPathList.Add(pin, gpio); } var filePath = Path.Combine(GpioPathList[pin].GpioPath, "direction"); try { SetPinDirection(filePath, direction); } catch (UnauthorizedAccessException) { // program hasn't been started as root, give it a second to correct file permissions Thread.Sleep(TimeSpan.FromSeconds(1)); SetPinDirection(filePath, direction); } GpioPathList[pin].GpioStream = new FileStream(Path.Combine(GuessGpioPath(pin), "value"), FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); }
/// <summary> /// Allocates the specified pin. /// </summary> /// <param name="pin">The pin.</param> /// <param name="direction">The direction.</param> public void Allocate(ProcessorPin pin, PinDirection direction) { var gpioId = string.Format("gpio{0}", (int)pin); if (Directory.Exists(Path.Combine(gpioPath, gpioId))) { // Reinitialize pin virtual file using (var streamWriter = new StreamWriter(Path.Combine(gpioPath, "unexport"), false)) streamWriter.Write((int)pin); } // Export pin for file mode using (var streamWriter = new StreamWriter(Path.Combine(gpioPath, "export"), false)) streamWriter.Write((int)pin); // Set the direction on the pin and update the exported list SetPinMode(pin, direction == PinDirection.Input ? Interop.BCM2835_GPIO_FSEL_INPT : Interop.BCM2835_GPIO_FSEL_OUTP); // Set direction in pin virtual file var filePath = Path.Combine(gpioId, "direction"); using (var streamWriter = new StreamWriter(Path.Combine(gpioPath, filePath), false)) streamWriter.Write(direction == PinDirection.Input ? "in" : "out"); if (direction == PinDirection.Input) { SetPinResistor(pin, PinResistor.None); SetPinDetectedEdges(pin, PinDetectedEdges.Both); InitializePoll(pin); } }
/// <summary> /// Allocates the specified pin. /// </summary> /// <param name="pin">The pin.</param> /// <param name="direction">The direction.</param> public void Allocate(ProcessorPin pin, PinDirection direction) { Release(pin); using (var streamWriter = new StreamWriter(Path.Combine(gpioPath, "export"), false)) streamWriter.Write((int)pin); if (!gpioPathList.ContainsKey(pin)) { var gpio = new FileGpioHandle { GpioPath = GuessGpioPath(pin) }; gpioPathList.Add(pin, gpio); } var filePath = Path.Combine(gpioPathList[pin].GpioPath, "direction"); try { SetPinDirection(filePath, direction); } catch (UnauthorizedAccessException) { // program hasn't been started as root, give it a second to correct file permissions Thread.Sleep(TimeSpan.FromSeconds(1)); SetPinDirection(filePath, direction); } gpioPathList[pin].GpioStream = new FileStream(Path.Combine(GuessGpioPath(pin), "value"), FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); }
public PinAttribs(string name, PinDirection direction, DataType dataType) { this.name = name; this.description = ""; this.dataType = dataType; this.direction = direction; }
internal static IPin LocatePin(IBaseFilter filter, PinDirection direction) { int reply = 0; IEnumPins enumPins = null; IPin[] pins = new IPin[1]; reply = filter.EnumPins(out enumPins); DsError.ThrowExceptionForHR(reply); while (enumPins.Next(pins.Length, pins, IntPtr.Zero) == 0) { PinDirection pinDirection; reply = pins[0].QueryDirection(out pinDirection); DsError.ThrowExceptionForHR(reply); if (pinDirection == direction) { Marshal.ReleaseComObject(enumPins); return(pins[0]); } } Marshal.ReleaseComObject(enumPins); return(null); }
public static IPin GetPin(this IBaseFilter filter, PinDirection dir, int num) { IPin[] pin = new IPin[1]; IEnumPins pinsEnum = null; if (filter.EnumPins(out pinsEnum) == 0) { PinDirection pinDir; int n; while (pinsEnum.Next(1, pin, out n) == 0) { pin[0].QueryDirection(out pinDir); if (pinDir == dir) { if (num == 0) return pin[0]; num--; } Marshal.ReleaseComObject(pin[0]); pin[0] = null; } } return null; }
/// <summary>Get filter's pin.</summary> /// <param name="filter">Filter to get pin of.</param> /// <param name="dir">Pin's direction.</param> /// <param name="num">Pin's number.</param> /// <returns>Returns filter's pin.</returns> public static IPin GetPin(IBaseFilter filter, PinDirection dir, int num) { var pins = new IPin[1]; if (filter.EnumPins(out var enumPins) == 0) { try { while (enumPins.Next(1, pins, IntPtr.Zero) == 0) { pins[0].QueryDirection(out var pinDirection); if (pinDirection == dir) { if (num == 0) { return(pins[0]); } --num; } Marshal.ReleaseComObject(pins[0]); pins[0] = null; } } finally { Marshal.ReleaseComObject(enumPins); } } return(null); }
public void SetPinDirection(IEnumerable <int> indexes, PinDirection direction, PinState?state = null) { foreach (var index in indexes) { this.SetPinDirection(index, direction, state); } }
/// <summary> /// Allocates the specified pin. /// </summary> /// <param name="pin">The pin.</param> /// <param name="direction">The direction.</param> public void Allocate(ProcessorPin pin, PinDirection direction) { var gpioId = string.Format("gpio{0}", (int)pin); if (Directory.Exists(Path.Combine(gpioPath, gpioId))) { HelperFileStream.SaveToFile(Path.Combine(gpioPath, "unexport"), (int)pin); } // Export pin for file mode HelperFileStream.SaveToFile(Path.Combine(gpioPath, "export"), (int)pin); // Set the direction on the pin and update the exported list SetPinMode(pin, direction == PinDirection.Input ? Interop.BCM2835_GPIO_FSEL_INPT : Interop.BCM2835_GPIO_FSEL_OUTP); // Set direction in pin virtual file var filePath = Path.Combine(gpioId, "direction"); HelperFileStream.SaveToFile(Path.Combine(gpioPath, filePath), direction == PinDirection.Input ? "in" : "out"); if (direction == PinDirection.Input) { PinResistor pinResistor; if (!pinResistors.TryGetValue(pin, out pinResistor) || pinResistor != PinResistor.None) { SetPinResistor(pin, PinResistor.None); } SetPinDetectedEdges(pin, PinDetectedEdges.Both); InitializePoll(pin); } }
public static IPin GetPin(this IBaseFilter filter, PinDirection dir, int num) { IPin[] pin = new IPin[1]; IEnumPins pinsEnum = null; if (filter.EnumPins(out pinsEnum) == 0) { PinDirection pinDir; int n; while (pinsEnum.Next(1, pin, out n) == 0) { pin[0].QueryDirection(out pinDir); if (pinDir == dir) { if (num == 0) { return(pin[0]); } num--; } Marshal.ReleaseComObject(pin[0]); pin[0] = null; } } return(null); }
public void InitGPIO(int num, PinDirection direction, PinInterrupt interrupt = PinInterrupt.Unknown) { string dir = (direction == PinDirection.Input ? "in" : "out"); string inter = (interrupt != PinInterrupt.Unknown ? "," + (char)interrupt : ""); Write("AT+S.GPIOC=" + num + "," + dir + inter); }
/// <summary> /// Allocates the specified pin. /// </summary> /// <param name="pin">The pin.</param> /// <param name="direction">The direction.</param> public void Allocate(ProcessorPin pin, PinDirection direction) { var gpioId = string.Format("gpio{0}", (int)pin); if (Directory.Exists(Path.Combine(gpioPath, gpioId))) { // Reinitialize pin virtual file using (var streamWriter = new StreamWriter(Path.Combine(gpioPath, "unexport"), false)) streamWriter.Write((int) pin); } // Export pin for file mode using (var streamWriter = new StreamWriter(Path.Combine(gpioPath, "export"), false)) streamWriter.Write((int)pin); // Set the direction on the pin and update the exported list SetPinMode(pin, direction == PinDirection.Input ? Interop.BCM2835_GPIO_FSEL_INPT : Interop.BCM2835_GPIO_FSEL_OUTP); // Set direction in pin virtual file var filePath = Path.Combine(gpioId, "direction"); using (var streamWriter = new StreamWriter(Path.Combine(gpioPath, filePath), false)) streamWriter.Write(direction == PinDirection.Input ? "in" : "out"); if (direction == PinDirection.Input) { PinResistor pinResistor; if (!pinResistors.TryGetValue(pin, out pinResistor) || pinResistor != PinResistor.None) SetPinResistor(pin, PinResistor.None); SetPinDetectedEdges(pin, PinDetectedEdges.Both); InitializePoll(pin); } }
// Get pin of the filter public static IPin GetPin(IBaseFilter filter, PinDirection dir, int num) { IPin[] pin = new IPin[1]; // enum filter pins if (filter.EnumPins(out IEnumPins pinsEnum) == 0) { // get next pin while (pinsEnum.Next(1, pin, out int n) == 0) { // query pin`s direction pin[0].QueryDirection(out PinDirection pinDir); if (pinDir == dir) { if (num == 0) { return(pin[0]); } num--; } Marshal.ReleaseComObject(pin[0]); pin[0] = null; } } return(null); }
//protected override void ConfigureVMR9InWindowlessMode(int numberOfStream) //{ // int hr = 0; // IVMRFilterConfig9 filterConfig = this.videoRenderer as IVMRFilterConfig9; // // Configure VMR-9 in Windowsless mode // hr = filterConfig.SetRenderingMode(VMR9Mode.Windowless); // DsError.ThrowExceptionForHR(hr); // // With 1 input stream // hr = filterConfig.SetNumberOfStreams(numberOfStream); // DsError.ThrowExceptionForHR(hr); // IVMRWindowlessControl9 windowlessControl = this.videoRenderer as IVMRWindowlessControl9; // // The main form is hosting the VMR-9 // hr = windowlessControl.SetVideoClippingWindow(this.hostingControl.Handle); // DsError.ThrowExceptionForHR(hr); // // Keep the aspect-ratio OK // //hr = windowlessControl.SetAspectRatioMode(VMR9AspectRatioMode.LetterBox); // hr = windowlessControl.SetAspectRatioMode(VMR9AspectRatioMode.None); // DsError.ThrowExceptionForHR(hr); // // Init the VMR-9 with default size values // OnResizeMoveHandler(null, null); // // Add Windows Messages handlers // AddHandlers(); //} public int FindCrossbarPin(IAMCrossbar pXBar, PhysicalConnectorType PhysicalType, PinDirection Dir, out int pIndex) { pIndex = -1; bool bInput = (Dir == PinDirection.Input ? true : false); // Find out how many pins the crossbar has. int cOut, cIn; int hr = pXBar.get_PinCounts(out cOut, out cIn); if (hr < 0) { return(hr); } // Enumerate pins and look for a matching pin. int count = (bInput ? cIn : cOut); for (int i = 0; i < count; i++) { int iRelated = 0; PhysicalConnectorType ThisPhysicalType = 0; hr = pXBar.get_CrossbarPinInfo(bInput, i, out iRelated, out ThisPhysicalType); if (hr >= 0 && ThisPhysicalType == PhysicalType) { // Found a match, return the index. pIndex = i; return(0); } } // Did not find a matching pin. return(-1); }
internal IPin FindPin(IBaseFilter filter, Guid mediaType, Guid mediaSubType, PinDirection direction) { IEnumPins enumPins = null; IPin[] pins = new IPin[1]; reply = filter.EnumPins(out enumPins); DsError.ThrowExceptionForHR(reply); while (enumPins.Next(pins.Length, pins, IntPtr.Zero) == 0) { PinDirection pinDirection; reply = pins[0].QueryDirection(out pinDirection); DsError.ThrowExceptionForHR(reply); if (pinDirection == direction) { bool mediaReply = DirectShowGraph.checkMediaTypes(pins[0], mediaType, mediaSubType); if (mediaReply) { Marshal.ReleaseComObject(enumPins); return(pins[0]); } } } Marshal.ReleaseComObject(enumPins); return(null); }
// Get pin of the filter public IPin GetPin(PinDirection dir, int num) { IPin[] pin = new IPin[1]; IEnumPins pinsEnum = null; // enum filter pins if (m_Filter.EnumPins(out pinsEnum) == 0) { PinDirection pinDir; int n; // get next pin while (pinsEnum.Next(1, pin, out n) == 0) { // query pin`s direction pin[0].QueryDirection(out pinDir); if (pinDir == dir) { if (num == 0) return pin[0]; num--; } Marshal.ReleaseComObject(pin[0]); pin[0] = null; } } return null; }
/// <summary> /// Erzeugt eine neue Beschreibung. /// </summary> /// <param name="direction">Die Übertragunsrichtung des Endpunktes.</param> /// <param name="name">Der eindeutige Name des Endpunktes.</param> /// <param name="filter">Der Filter, zu dem dieser Endpunkt gehört.</param> public PinInfo( PinDirection direction, string name, IBaseFilter filter ) { // Remember all Filter = Marshal.GetComInterfaceForObject( filter, typeof( IBaseFilter ) ); Direction = direction; Name = name; }
/// <summary> /// Erzeugt eine neue Beschreibung. /// </summary> /// <param name="direction">Die Übertragunsrichtung des Endpunktes.</param> /// <param name="name">Der eindeutige Name des Endpunktes.</param> /// <param name="filter">Der Filter, zu dem dieser Endpunkt gehört.</param> public PinInfo(PinDirection direction, string name, IBaseFilter filter) { // Remember all Filter = Marshal.GetComInterfaceForObject(filter, typeof(IBaseFilter)); Direction = direction; Name = name; }
/// <summary> /// Find all the immediate upstream or downstream filters given a filter reference /// </summary> /// <param name="pFilter">Starting filter</param> /// <param name="Dir">Direction to search (upstream or downstream)</param> /// <param name="FilterList">Collect the results in this filter list</param> /// <returns>True if successful in getting filter chain</returns> private bool GetFilterChain(IBaseFilter pFilter, PinDirection Dir, List <IBaseFilter> FilterList) { int hr; IntPtr fetched = IntPtr.Zero; if (pFilter == null || FilterList == null) { return(false); } IEnumPins pEnum; IPin[] pPin = new IPin[1]; hr = pFilter.EnumPins(out pEnum); if (FAILED(hr)) { return(false); } while (pEnum.Next(pPin.Length, pPin, fetched) == 0) { // See if this pin matches the specified direction. PinDirection ThisPinDir; hr = pPin[0].QueryDirection(out ThisPinDir); if (FAILED(hr)) { // Something strange happened. return(false); } if (ThisPinDir == Dir) { // Check if the pin is connected to another pin. IPin pPinNext; IntPtr ptr; hr = pPin[0].ConnectedTo(out ptr); if (SUCCEEDED(hr)) { // Get the filter that owns that pin. PinInfo PinInfo; pPinNext = (IPin)Marshal.GetObjectForIUnknown(ptr); hr = pPinNext.QueryPinInfo(out PinInfo); if (FAILED(hr) || (PinInfo.filter == null)) { // Something strange happened. return(false); } // Insert the filter into the list. AddFilterUnique(FilterList, PinInfo.filter); // Go recursive through the filter chain GetFilterChain(PinInfo.filter, Dir, FilterList); } } } return(true); }
/// <summary> /// Allocates the specified pin. /// </summary> /// <param name="pin">The pin.</param> /// <param name="direction">The direction.</param> public void Allocate(ProcessorPin pin, PinDirection direction) { // Set the direction on the pin and update the exported list SetPinMode(pin, direction == PinDirection.Input ? Interop.BCM2835_GPIO_FSEL_INPT : Interop.BCM2835_GPIO_FSEL_OUTP); if (direction == PinDirection.Input) SetPinResistor(pin, PinResistor.None); }
public Pin(string name, string description, DataType dataType, PinDirection direction, Node owner) { this.name = name; this.description = description; this.direction = direction; this.dataType = dataType; this.owner = owner; }
public WavFormatInfoCollection(IBaseFilter filter, PinDirection direction) { IEnumerator <WavFormatInfo> enumerator = WavFormatInfoUtils.EnumerateFormatsForDirection(filter, direction); while (enumerator.MoveNext()) { Add(enumerator.Current); } }
public void gpio_dir(ref gpio_t obj, PinDirection direction) { if (!interfaces.TryGetValue(obj.id, out var uif)) { throw new ArgumentException(); } ((Gpio)uif).SetDirection(direction); }
protected ArrayList findAudioSources(ICaptureGraphBuilder2 graphBuilder, IBaseFilter deviceFilter) { ArrayList sources = new ArrayList(); IAMAudioInputMixer audioInputMixer = deviceFilter as IAMAudioInputMixer; if (audioInputMixer != null) { // Get a pin enumerator off the filter IEnumPins pinEnum; int hr = deviceFilter.EnumPins(out pinEnum); pinEnum.Reset(); if ((hr == 0) && (pinEnum != null)) { // Loop through each pin IPin[] pins = new IPin[1]; #if VS2003 || DSHOWNET int f; #else IntPtr f = IntPtr.Zero; #endif do { // Get the next pin #if VS2003 || DSHOWNET hr = pinEnum.Next(1, pins, out f); #else hr = pinEnum.Next(1, pins, f); #endif if ((hr == 0) && (pins[0] != null)) { // Is this an input pin? PinDirection dir = PinDirection.Output; hr = pins[0].QueryDirection(out dir); if ((hr == 0) && (dir == (PinDirection.Input))) { // Add the input pin to the sources list AudioSource source = new AudioSource(pins[0]); sources.Add(source); } pins[0] = null; } }while(hr == 0); Marshal.ReleaseComObject(pinEnum); pinEnum = null; } } // If there is only one source, don't return it // because there is nothing for the user to choose. // (Hopefully that single source is already enabled). if (sources.Count == 1) { sources.Clear(); } return(sources); }
/// <summary> /// Return the first unconnected input or output pin. /// </summary> /// <param name="pFilter">Specifies the filter to check.</param> /// <param name="pinDir">Specifies the pin direction to look for.</param> /// <param name="ppPin">Returns the first unconnected pin in the direction specified.</param> /// <returns>An error value < 0 is returned or 0 for success.</returns> public static int FindUnconnectedPin(IBaseFilter pFilter, PinDirection pinDir, out IPin ppPin) { uint VFW_E_NOT_FOUND = 0x80040216; IEnumPins pEnum = null; bool bFound = false; ppPin = null; int hr = pFilter.EnumPins(out pEnum); if (hr < 0) { return(hr); } IPin[] rgPin = new IPin[1]; int nFetched; while (pEnum.Next(1, rgPin, out nFetched) == 0) { hr = MatchPin(rgPin[0], pinDir, false, out bFound); if (hr < 0) { return(hr); } if (bFound) { ppPin = rgPin[0]; break; } if (rgPin[0] != null) { Marshal.ReleaseComObject(rgPin[0]); rgPin[0] = null; } } if (!bFound) { hr = (int)VFW_E_NOT_FOUND; } if (rgPin[0] != null && ppPin == null) { Marshal.ReleaseComObject(rgPin[0]); } if (pEnum != null) { Marshal.ReleaseComObject(pEnum); } return(hr); }
public bool RemovePin(string name, PinDirection direction) { if (direction == PinDirection.Input) { DX11InputPin ip = null; foreach (DX11InputPin vi in this.InputPins) { if (vi.Name == name) { ip = vi; } } if (ip != null) { //Diconnect parent if applicable if (ip.ParentPin != null) { if (ip.ParentPin.ChildrenPins.Contains(ip)) { ip.ParentPin.ChildrenPins.Remove(ip); } } this.InputPins.Remove(ip); } return(ip != null); } if (direction == PinDirection.Output) { DX11OutputPin op = null; foreach (DX11OutputPin vo in this.OutputPins) { if (vo.Name == name) { op = vo; } } if (op != null) { foreach (DX11InputPin vip in op.ChildrenPins) { vip.ParentPin = null; } op.ChildrenPins.Clear(); this.OutputPins.Remove(op); } return(op != null); } return(false); }
/// <summary> /// Allocates the specified pin. /// </summary> /// <param name="pin">The pin.</param> /// <param name="direction">The direction.</param> public void Allocate(ProcessorPin pin, PinDirection direction) { // Set the direction on the pin and update the exported list SetPinMode(pin, direction == PinDirection.Input ? Interop.BCM2835_GPIO_FSEL_INPT : Interop.BCM2835_GPIO_FSEL_OUTP); if (direction == PinDirection.Input) { SetPinResistor(pin, PinResistor.None); } }
public void SetDirection(int pinNumber, PinDirection direction) { if (IsEnabled(pinNumber)) { var pin = GetPin(pinNumber); pin.Direction = direction; SetDirection(pin); } }
/// <summary> /// Allocates the specified pin. /// </summary> /// <param name="pin">The pin.</param> /// <param name="direction">The direction.</param> public void Allocate(ProcessorPin pin, PinDirection direction) { var gpioId = string.Format("gpio{0}", (int)pin); if (Directory.Exists(Path.Combine(gpioPath, gpioId))) { // Reinitialize pin virtual file using (var streamWriter = new StreamWriter(Path.Combine(gpioPath, "unexport"), false)) { streamWriter.Write((int)pin); streamWriter.Close(); } } // Export pin for file mode using (var streamWriter = new StreamWriter(Path.Combine(gpioPath, "export"), false)) { streamWriter.Write((int)pin); streamWriter.Close(); } // Set the direction on the pin and update the exported list SetPinMode(pin, direction == PinDirection.Input ? Interop.BCM2835_GPIO_FSEL_INPT : Interop.BCM2835_GPIO_FSEL_OUTP); if (Environment.OSVersion.Platform == PlatformID.Unix) { UnixDirectoryInfo udi = new UnixDirectoryInfo(Path.Combine(gpioPath, gpioId)); while ((udi.OwnerGroup.GroupName != "gpio") && (!udi.CanAccess(AccessModes.W_OK))) { Thread.Sleep(1); udi.Refresh(); } } // Set direction in pin virtual file var filePath = Path.Combine(gpioId, "direction"); using (var streamWriter = new StreamWriter(Path.Combine(gpioPath, filePath), false)) { streamWriter.Write(direction == PinDirection.Input ? "in" : "out"); } if (direction == PinDirection.Input) { PinResistor pinResistor; if (!pinResistors.TryGetValue(pin, out pinResistor) || pinResistor != PinResistor.None) { SetPinResistor(pin, PinResistor.None); } SetPinDetectedEdges(pin, PinDetectedEdges.Both); InitializePoll(pin); } }
public bool HasFreePins(PinDirection dir) //has not connected pins of given direction { foreach (Pin pin in pins) { if (pin.Direction == dir && pin.Connection == null) { return(true); } } return(false); }
public static IPin FindPin(IBaseFilter filter, PinDirection direction, Guid mediaType, Guid pinCategory, string preferredName) { if (Guid.Empty != pinCategory) { int idx = 0; do { IPin pinByCategory = DsFindPin.ByCategory(filter, pinCategory, idx); if (pinByCategory != null) { if (IsMatchingPin(pinByCategory, direction, mediaType)) return PrintInfoAndReturnPin(filter, pinByCategory, direction, mediaType, pinCategory, "found by category"); Marshal.ReleaseComObject(pinByCategory); } else break; idx++; } while (true); } if (!string.IsNullOrEmpty(preferredName)) { IPin pinByName = DsFindPin.ByName(filter, preferredName); if (pinByName != null && IsMatchingPin(pinByName, direction, mediaType)) return PrintInfoAndReturnPin(filter, pinByName, direction, mediaType, pinCategory, "found by name"); Marshal.ReleaseComObject(pinByName); } IEnumPins pinsEnum; IPin[] pins = new IPin[1]; int hr = filter.EnumPins(out pinsEnum); DsError.ThrowExceptionForHR(hr); while (pinsEnum.Next(1, pins, IntPtr.Zero) == 0) { IPin pin = pins[0]; if (pin != null) { if (IsMatchingPin(pin, direction, mediaType)) return PrintInfoAndReturnPin(filter, pin, direction, mediaType, pinCategory, "found by direction and media type"); Marshal.ReleaseComObject(pin); } } return null; }
public GPIOPin RemapPin(PinDirection direction, PhysicalPin pin) { if (UsedPins.ContainsKey((uint)pin)) { if (direction == UsedPins[(uint) pin].Direction) return UsedPins[(uint) pin]; UsedPins[(uint)pin].Dispose(); UsedPins.Remove((uint) pin); } return CreatePin(direction, pin); }
/// <summary> /// Finds a pin that exists in a graph. /// </summary> /// <param name="majorOrMinorMediaType">The GUID of the major or minor type of the media</param> /// <param name="pinDirection">The direction of the pin - in/out</param> /// <param name="graph">The graph to search in</param> /// <returns>Returns null if the pin was not found, or if a pin is found, returns the first instance of it</returns> protected static IPin FindPinInGraphByMediaType(Guid majorOrMinorMediaType, PinDirection pinDirection, IGraphBuilder graph) { IEnumFilters enumFilters; /* Get the filter enum */ graph.EnumFilters(out enumFilters); /* Init our vars */ var filters = new IBaseFilter[1]; var fetched = IntPtr.Zero; IPin pin = null; IEnumMediaTypes mediaTypesEnum = null; /* Loop over each filter in the graph */ while (enumFilters.Next(1, filters, fetched) == 0) { var filter = filters[0]; int i = 0; /* Loop over each pin in the filter */ while ((pin = DsFindPin.ByDirection(filter, pinDirection, i)) != null) { /* Get the pin enumerator */ pin.EnumMediaTypes(out mediaTypesEnum); var mediaTypesFetched = IntPtr.Zero; var mediaTypes = new AMMediaType[1]; /* Enumerate the media types on the pin */ while (mediaTypesEnum.Next(1, mediaTypes, mediaTypesFetched) == 0) { /* See if the major or subtype meets our requirements */ if (mediaTypes[0].majorType.Equals(majorOrMinorMediaType) || mediaTypes[0].subType.Equals(majorOrMinorMediaType)) { /* We found a match */ goto done; } } i++; } } done: if (mediaTypesEnum != null) { mediaTypesEnum.Reset(); Marshal.ReleaseComObject(mediaTypesEnum); } enumFilters.Reset(); Marshal.ReleaseComObject(enumFilters); return(pin); }
/// <summary> /// Allocates the specified pin. /// </summary> /// <param name="pin">The pin.</param> /// <param name="direction">The direction.</param> public void Allocate(ProcessorPin pin, PinDirection direction) { var gpioId = string.Format("gpio{0}", (int)pin); if (Directory.Exists(Path.Combine(gpioPath, gpioId))) Release(pin); using (var streamWriter = new StreamWriter(Path.Combine(gpioPath, "export"), false)) streamWriter.Write((int)pin); var filePath = Path.Combine(gpioId, "direction"); using (var streamWriter = new StreamWriter(Path.Combine(gpioPath, filePath), false)) streamWriter.Write(direction == PinDirection.Input ? "in" : "out"); }
private void SetDirection(PinDirection newDirection) { if (direction == newDirection) return; if (direction.HasValue) driver.Release(pin); driver.Allocate(pin, newDirection); if (newDirection == PinDirection.Input && resistor != PinResistor.None) driver.SetPinResistor(pin, resistor); direction = newDirection; }
/// <summary> /// Allocates the specified pin. /// </summary> /// <param name="pin">The pin.</param> /// <param name="direction">The direction.</param> public void Allocate(ProcessorPin pin, PinDirection direction) { // Set the direction on the pin and update the exported list // BCM2835_GPIO_FSEL_INPT = 0 // BCM2835_GPIO_FSEL_OUTP = 1 Interop.bcm2835_gpio_fsel((uint)pin, (uint)(direction == PinDirection.Input ? 0 : 1)); if (direction == PinDirection.Input) { // BCM2835_GPIO_PUD_OFF = 0b00 = 0 // BCM2835_GPIO_PUD_DOWN = 0b01 = 1 // BCM2835_GPIO_PUD_UP = 0b10 = 2 Interop.bcm2835_gpio_set_pud((uint)pin, 0); } }
public static WavFormatInfo FindFormat(IBaseFilter filter, PinDirection direction, AudioFormat format) { IEnumerator<WavFormatInfo> enumerator = EnumerateFormatsForDirection(filter, direction); while (enumerator.MoveNext()) { if ((enumerator.Current.IsMono == format.IsMono) && (enumerator.Current.Khz == format.Khz) && (enumerator.Current.Kbps == format.Kbps)) { return enumerator.Current; } enumerator.Current.Dispose(); } return null; }
/// <summary> /// Allocates the specified pin. /// </summary> /// <param name="pin">The pin.</param> /// <param name="direction">The direction.</param> public void Allocate(ProcessorPin pin, PinDirection direction) { var gpioId = string.Format("gpio{0}", (int)pin); if (Directory.Exists(Path.Combine(gpioPath, gpioId))) Release(pin); using (var streamWriter = new StreamWriter(Path.Combine(gpioPath, "export"), false)) streamWriter.Write((int)pin); var filePath = Path.Combine(gpioPath, gpioId, "direction"); try { SetPinDirection(filePath, direction); } catch (UnauthorizedAccessException) { // program hasn't been started as root, give it a second to correct file permissions Thread.Sleep(TimeSpan.FromSeconds(1)); SetPinDirection(filePath, direction); } }
public GPIOPin CreatePin(PinDirection direction, PhysicalPin pin) { if (UsedPins.ContainsKey((uint)pin)) { if (direction == UsedPins[(uint) pin].Direction) return UsedPins[(uint) pin]; throw new Exception("Pin already in use. Use RemapPin() to remap the pin."); } GPIOPin returnPin; if (direction == PinDirection.In) { returnPin = new GPIOInputPin(pin); } else { returnPin = new GPIOOutputPin(pin); } UsedPins.Add((uint)returnPin.Pin, returnPin); return returnPin; }
private static bool IsMatchingPin(IPin pin, PinDirection direction, Guid mediaType) { PinDirection pinDirection; int hr = pin.QueryDirection(out pinDirection); DsError.ThrowExceptionForHR(hr); if (pinDirection != direction) // The pin lacks direction return false; IPin connectedPin; hr = pin.ConnectedTo(out connectedPin); if ((uint)hr != 0x80040209 /* Pin is not connected */) DsError.ThrowExceptionForHR(hr); if (connectedPin != null) { // The pin is already connected Marshal.ReleaseComObject(connectedPin); return false; } IEnumMediaTypes mediaTypesEnum; hr = pin.EnumMediaTypes(out mediaTypesEnum); DsError.ThrowExceptionForHR(hr); AMMediaType[] mediaTypes = new AMMediaType[1]; while (mediaTypesEnum.Next(1, mediaTypes, IntPtr.Zero) == 0) { Guid majorType = mediaTypes[0].majorType; DsUtils.FreeAMMediaType(mediaTypes[0]); if (majorType == mediaType) { // We have found the pin we were looking for return true; } } return false; }
/// <summary> /// Gets a specific pin of a specific filter /// </summary> /// <param name="filter">Filter to retrieve the pin for (defines which object should make this method available)</param> /// <param name="dir">Direction</param> /// <param name="num">Number</param> /// <returns>IPin object or null</returns> public static IPin GetPin(this IBaseFilter filter, PinDirection dir, int num) { // Declare variables IPin[] pin = new IPin[1]; IEnumPins pinsEnum = null; // Enumerator the pins if (filter.EnumPins(out pinsEnum) == 0) { // Get the pin direction PinDirection pinDir; int n = 0; ; // Loop the pins while (pinsEnum.Next(1, pin, out n) == 0) { // Query the direction pin[0].QueryDirection(out pinDir); // Is the pin direction correct? if (pinDir == dir) { // Yes, check the pins if (num == 0) { return pin[0]; } num--; } // Release the pin, this is not the one we are looking for Marshal.ReleaseComObject(pin[0]); pin[0] = null; } } // Not found return null; }
/// <summary> /// Get filter's pin. /// </summary> /// /// <param name="filter">Filter to get pin of.</param> /// <param name="dir">Pin's direction.</param> /// <param name="num">Pin's number.</param> /// /// <returns>Returns filter's pin.</returns> /// public static IPin GetPin( IBaseFilter filter, PinDirection dir, int num ) { IPin[] pin = new IPin[1]; IEnumPins pinsEnum; // enum filter pins if ( filter.EnumPins( out pinsEnum ) == 0 ) { try { // get next pin int n; while ( pinsEnum.Next( 1, pin, out n ) == 0 ) { // query pin`s direction if (pin[0] != null) { PinDirection pinDir; pin[0].QueryDirection(out pinDir); if (pinDir == dir) { if (num == 0) return pin[0]; num--; } Marshal.ReleaseComObject(pin[0]); } pin[0] = null; } } finally { Marshal.ReleaseComObject( pinsEnum ); } } return null; }
protected IPin GetUnconnectedPin(IBaseFilter filter, PinDirection direction) { IPin destPin = null; IEnumPins iEnum; var pins = new IPin[1]; var hr = filter.EnumPins(out iEnum); Marshal.ThrowExceptionForHR(hr); var fetched = Marshal.AllocCoTaskMem(4); hr = iEnum.Next(1, pins, fetched); Marshal.ThrowExceptionForHR(hr); while (Marshal.ReadInt32(fetched) == 1) { PinDirection pinDir; IPin pPin; destPin = pins[0]; hr = destPin.QueryDirection(out pinDir); Marshal.ThrowExceptionForHR(hr); PinInfo info; destPin.QueryPinInfo(out info); //var name = info.name; destPin.ConnectedTo(out pPin); if (pPin == null && pinDir == direction) break; hr = iEnum.Next(1, pins, fetched); Marshal.ThrowExceptionForHR(hr); } Marshal.FreeCoTaskMem(fetched); return destPin; }
// from 'DShowUtil.cpp' public int GetPin( IBaseFilter filter, PinDirection dirrequired, int num, out IPin ppPin ) { ppPin = null; int hr; IEnumPins pinEnum; hr = filter.EnumPins( out pinEnum ); if( (hr < 0) || (pinEnum == null) ) return hr; IPin[] pins = new IPin[1]; int f; PinDirection dir; do { hr = pinEnum.Next( 1, pins, out f ); if( (hr != 0) || (pins[0] == null) ) break; dir = (PinDirection) 3; hr = pins[0].QueryDirection( out dir ); if( (hr == 0) && (dir == dirrequired) ) { if( num == 0 ) { ppPin = pins[0]; pins[0] = null; break; } num--; } Marshal.ReleaseComObject( pins[0] ); pins[0] = null; } while( hr == 0 ); Marshal.ReleaseComObject( pinEnum ); pinEnum = null; return hr; }
public static IPin FindPinForMajorType(IBaseFilter filter, PinDirection direction, Guid majorType) { if (filter == null) throw new ArgumentNullException("filter"); int hr = 0; IEnumPins pinsEnum = null; try { hr = filter.EnumPins(out pinsEnum); DsError.ThrowExceptionForHR(hr); var pins = new IPin[1]; int numberFetched = 1; while (numberFetched > 0) { IntPtr pcFetched = Marshal.AllocCoTaskMem(4); try { hr = pinsEnum.Next(1, pins, pcFetched); DsError.ThrowExceptionForHR(hr); numberFetched = Marshal.ReadInt32(pcFetched); } finally { Marshal.FreeCoTaskMem(pcFetched); } if (numberFetched > 0) { PinDirection currentPinDirection; hr = pins[0].QueryDirection(out currentPinDirection); DsError.ThrowExceptionForHR(hr); if (currentPinDirection != direction) continue; IEnumMediaTypes mediaTypesEnum = null; try { var mediaTypes = new AMMediaType[1]; pins[0].EnumMediaTypes(out mediaTypesEnum); int numberFetched2 = 1; while (numberFetched2 > 0) { IntPtr fetched2 = IntPtr.Zero; try { hr = mediaTypesEnum.Next(1, mediaTypes, fetched2); DsError.ThrowExceptionForHR(hr); numberFetched2 = Marshal.ReadInt32(fetched2); } finally { Marshal.FreeCoTaskMem(fetched2); } if (numberFetched2 > 0) { if (mediaTypes[0].majorType == majorType) { // success, return the pin return pins[0]; } } Marshal.ReleaseComObject(pins[0]); } } finally { if (mediaTypesEnum != null) Marshal.ReleaseComObject(mediaTypesEnum); } } } } finally { if (pinsEnum != null) Marshal.ReleaseComObject(pinsEnum); } return null; }
int IPin.QueryDirection(out PinDirection pPinDir) { pPinDir = PinDirection.Output; return S_OK; }
/// <summary> /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.IO.GpioBase"/> /// class with a board Revision 1.0 pin and the pin direction. /// </summary> /// <param name="pin"> /// The GPIO pin. /// </param> /// <param name="direction"> /// The I/O pin direction. /// </param> public GpioBase(GpioPins pin, PinDirection direction) : this(pin, direction, false) { }
public static IPin FindPinByMediaType(IBaseFilter filter, PinDirection direction, Guid mType, Guid sType) { IPin pRet = null; IPin tPin = null; int hr; int index = 0; tPin = DsFindPin.ByDirection(filter, direction, index); while (tPin != null) { IEnumMediaTypes emtDvr = null; AMMediaType[] amtDvr = new AMMediaType[1]; try { tPin.EnumMediaTypes(out emtDvr); hr = emtDvr.Next(1, amtDvr, IntPtr.Zero); DsError.ThrowExceptionForHR(hr); if (amtDvr[0] != null && amtDvr[0].majorType == mType && (amtDvr[0].subType == sType || sType == MediaSubType.Null)) { pRet = tPin; break; } } finally { DsUtils.FreeAMMediaType(amtDvr[0]); if (emtDvr != null) Marshal.ReleaseComObject(emtDvr); } if (tPin != null) Marshal.ReleaseComObject(tPin); tPin = null; index++; tPin = DsFindPin.ByDirection(filter, direction, index); } return pRet; }
/// <summary> /// Gets the video resolution of a pin on a renderer. /// </summary> /// <param name="renderer">The renderer to inspect</param> /// <param name="direction">The direction the pin is</param> /// <param name="pinIndex">The zero based index of the pin to inspect</param> /// <returns>If successful a video resolution is returned. If not, a 0x0 size is returned</returns> protected static Size GetVideoSize(IBaseFilter renderer, PinDirection direction, int pinIndex) { var size = new Size(); var mediaType = new AMMediaType(); IPin pin = DsFindPin.ByDirection(renderer, direction, pinIndex); if (pin == null) goto done; int hr = pin.ConnectionMediaType(mediaType); if (hr != 0) goto done; /* Check to see if its a video media type */ if (mediaType.formatType != FormatType.VideoInfo2 && mediaType.formatType != FormatType.VideoInfo) { goto done; } var videoInfo = new VideoInfoHeader(); /* Read the video info header struct from the native pointer */ Marshal.PtrToStructure(mediaType.formatPtr, videoInfo); Rectangle rect = videoInfo.SrcRect.ToRectangle(); size = new Size(rect.Width, rect.Height); done: DsUtils.FreeAMMediaType(mediaType); return size; }
public bool SetDirection(int pin, PinDirection direction) { WriteToFSLocation(GPIOFSLocation + "gpio" + pin.ToString() + "/direction", Enum.GetName(typeof(PinDirection), direction).Trim().ToLower()); return GetDirection(pin) == direction; }
private IReadOnlyList<IPin> CollectPins(Type nodeType, PinDirection direction) { var pinAttributeType = direction == PinDirection.Input ? typeof (InputAttribute) : typeof (OutputAttribute); var pins = nodeType .GetProperties() .Where(propertyInfo => propertyInfo.GetCustomAttributes(pinAttributeType, true).Any()) .Select(propertyInfo => (IPin)new PropertyPin(this, direction, propertyInfo)) .ToArray(); return new ReadOnlyCollection<IPin>(pins); }
/// <summary> /// Initializes a new instance of the <see cref="CyrusBuilt.MonoPi.IO.GpioBase"/> /// class with a board Revision 1.0 GPIO pin, the pin direction, and /// the initial pin value. /// </summary> /// <param name="pin"> /// The GPIO pin. /// </param> /// <param name="direction"> /// The I/O pin direction. /// </param> /// <param name="value"> /// The initial pin value. /// </param> public GpioBase(GpioPins pin, PinDirection direction, Boolean value) { this._pin = pin; this._direction = direction; this._revision = BoardRevision.Rev2; }
public int QueryDirection(out PinDirection pPinDir) { pPinDir = PinDirection.Input; if (m_pUnknown == IntPtr.Zero) return E_NOINTERFACE; QueryDirectionProc _Proc = GetProcDelegate<QueryDirectionProc>(9); if (_Proc == null) return E_UNEXPECTED; return (HRESULT)_Proc( m_pUnknown, out pPinDir ); }
/// <summary> /// Finds a pin that exists in a graph. /// </summary> /// <param name="majorOrMinorMediaType">The GUID of the major or minor type of the media</param> /// <param name="pinDirection">The direction of the pin - in/out</param> /// <param name="graph">The graph to search in</param> /// <returns>Returns null if the pin was not found, or if a pin is found, returns the first instance of it</returns> protected static IPin FindPinInGraphByMediaType(Guid majorOrMinorMediaType, PinDirection pinDirection, IGraphBuilder graph) { IEnumFilters enumFilters; /* Get the filter enum */ graph.EnumFilters(out enumFilters); /* Init our vars */ var filters = new IBaseFilter[1]; var fetched = IntPtr.Zero; IPin pin = null; IEnumMediaTypes mediaTypesEnum = null; /* Loop over each filter in the graph */ while (enumFilters.Next(1, filters, fetched) == 0) { var filter = filters[0]; int i = 0; /* Loop over each pin in the filter */ while ((pin = DsFindPin.ByDirection(filter, pinDirection, i)) != null) { /* Get the pin enumerator */ pin.EnumMediaTypes(out mediaTypesEnum); var mediaTypesFetched = IntPtr.Zero; var mediaTypes = new AMMediaType[1]; /* Enumerate the media types on the pin */ while (mediaTypesEnum.Next(1, mediaTypes, mediaTypesFetched) == 0) { /* See if the major or subtype meets our requirements */ if (mediaTypes[0].majorType.Equals(majorOrMinorMediaType) || mediaTypes[0].subType.Equals(majorOrMinorMediaType)) { /* We found a match */ goto done; } } i++; } } done: if (mediaTypesEnum != null) { mediaTypesEnum.Reset(); Marshal.ReleaseComObject(mediaTypesEnum); } enumFilters.Reset(); Marshal.ReleaseComObject(enumFilters); return pin; }