//--// /// <summary> /// Builds an instance of AnalogOutput type for the specified channel /// </summary> /// <param name="channel">The channel for the AnalogOutput</param> /// <param name="scale">A multiplicative factor to apply to the value written to the sensor</param> /// <param name="offset">A constant factor to add to the value written to the sensor</param> /// <param name="precisionInBits">The desired bit precision for the D/A conversion. A value of -1 indicates default precision.</param> public AnalogOutput(Cpu.AnalogOutputChannel channel, double scale, double offset, int precisionInBits) { m_channel = channel; HardwareProvider hwProvider = HardwareProvider.HwProvider; if (hwProvider == null) { throw new InvalidOperationException(); } m_pin = hwProvider.GetAnalogOutputPinForChannel(channel); m_scale = scale; m_offset = offset; int[] availablePrecisions = hwProvider.GetAvailableAnalogOutputPrecisionInBitsForChannel(channel); if (precisionInBits == -1) { if (availablePrecisions.Length == 0) { throw new InvalidOperationException(); } m_precision = availablePrecisions[0]; } else { bool found = false; foreach (int precision in availablePrecisions) { if (precisionInBits == precision) { m_precision = precision; found = true; break; } } if (!found) { throw new ArgumentException(); } } bool fReserved = false; try { lock (s_syncRoot) { fReserved = Port.ReservePin(m_pin, true); Initialize(channel, m_precision); } } catch { if (fReserved) { Port.ReservePin(m_pin, false); } throw; } }
public NativeAnalogOutput(Socket socket, Socket.Pin pin, Module module, Cpu.AnalogOutputChannel channel) { if (channel == Cpu.AnalogOutputChannel.ANALOG_OUTPUT_NONE) { Socket.InvalidSocketException.ThrowIfOutOfRange(pin, Socket.Pin.Five, Socket.Pin.Five, "AnalogOutput", module); throw Socket.InvalidSocketException.FunctionalityException(socket, "AnalogOutput"); } this._channel = channel; this._socket = socket; }
/// <summary> /// Allows .wav file playback through AnalogOut /// </summary> /// <param name="channel">AnalogOut Channel</param> /// <param name="data">.wav file buffer</param> /// <param name="offset">Array offset</param> /// <param name="count">Size of playback sample</param> /// <param name="dataRate">Frequency in Hz</param> public static void PlayPCMAudio(Cpu.AnalogOutputChannel channel, byte[] data, int offset, int count, int dataRate) { if (DeviceInfo.GetDeviceID() == DeviceID.FEZ_CERB) { PlayPCMAudio((byte)channel, data, offset, count, dataRate); } else { throw new NotSupportedException(); } }
public static Gadgeteer.SocketInterfaces.AnalogOutput Create(Socket socket, Socket.Pin pin, Module module) { socket.EnsureTypeIsSupported('O', module); socket.ReservePin(pin, module); Cpu.AnalogOutputChannel channel = socket.AnalogOutput5; if ((channel == Cpu.AnalogOutputChannel.ANALOG_OUTPUT_NONE) && (socket.AnalogOutputIndirector != null)) { return(socket.AnalogOutputIndirector(socket, pin, module)); } return(new NativeAnalogOutput(socket, pin, module, channel)); }
/// <summary> /// Creates an instance of <see cref="AnalogOutput" /> for the given socket and pin number. /// </summary> /// <remarks>This automatically checks that the socket supports Type O, and reserves the pin. /// An exception will be thrown if there is a problem with these checks.</remarks> /// <param name="socket">The analog output capable socket.</param> /// <param name="pin">The pin to assign to the analog output.</param> /// <param name="module">The module using this analog output interface, which can be null if unspecified.</param> /// <returns>An instance of <see cref="AnalogOutput" /> for the given socket and pin number.</returns> public static AnalogOutput Create(Socket socket, Socket.Pin pin, Module module) { socket.EnsureTypeIsSupported('O', module); socket.ReservePin(pin, module); Cpu.AnalogOutputChannel channel = socket.AnalogOutput5; // native implementation is preferred to an indirected one if (channel == Cpu.AnalogOutputChannel.ANALOG_OUTPUT_NONE && socket.AnalogOutputIndirector != null) { return(socket.AnalogOutputIndirector(socket, pin, module)); } else { return(new NativeAnalogOutput(socket, pin, module, channel)); } }
/// <summary> /// Initialize a new instance of <see cref="AnalogSignalGenerator"/> for the specified channel /// </summary> /// <param name="channel">The analog output channel</param> /// <param name="clockDivisor">The divisor applied to <see cref="Cpu.SlowClock"/> to define the sample clock</param> public AnalogSignalGenerator(Cpu.AnalogOutputChannel channel, int clockDivisor) { int channelCount = GetChannelCount(); if ((int)channel < 0 || (int)channel >= channelCount) { throw new ArgumentOutOfRangeException("channel"); } _channel = channel; _pin = GetPin(channel); if (!Port.ReservePin(_pin, true)) { throw new InvalidOperationException("Pin already reserved for another task"); } _signalInfo = new int[8]; ClockDivisor = (UInt16)clockDivisor; NativeInitialize(); }
//--// /// <summary> /// Builds an instance of AnalogOutput type for the specified channel /// </summary> /// <param name="channel">The channel for the AnalogOutput</param> /// <param name="scale">A multiplicative factor to apply to the value written to the sensor</param> /// <param name="offset">A constant factor to add to the value written to the sensor</param> /// <param name="precisionInBits">The desired bit precision for the D/A conversion. A value of -1 indicates default precision.</param> public AnalogOutput(Cpu.AnalogOutputChannel channel, double scale, double offset, int precisionInBits) { m_channel = channel; HardwareProvider hwProvider = HardwareProvider.HwProvider; if (hwProvider == null) throw new InvalidOperationException(); m_pin = hwProvider.GetAnalogOutputPinForChannel(channel); m_scale = scale; m_offset = offset; int[] availablePrecisions = hwProvider.GetAvailableAnalogOutputPrecisionInBitsForChannel(channel); if(precisionInBits == -1) { if(availablePrecisions.Length == 0) throw new InvalidOperationException(); m_precision = availablePrecisions[0]; } else { bool found = false; foreach(int precision in availablePrecisions) { if(precisionInBits == precision) { m_precision = precision; found = true; break; } } if(!found) { throw new ArgumentException(); } } bool fReserved = false; try { lock (s_syncRoot) { fReserved = Port.ReservePin(m_pin, true); Initialize(channel, m_precision); } } catch { if (fReserved) { Port.ReservePin(m_pin, false); } throw; } }
public virtual Cpu.Pin GetAnalogOutputPinForChannel(Cpu.AnalogOutputChannel channel) { throw new HardwareProvidedNotRegistered(); }
/// <summary> /// Builds an instance of AnalogOutput type for the specified channel. /// </summary> /// <param name="channel">The channel for the AnalogOutput</param> public AnalogOutput(Cpu.AnalogOutputChannel channel) : this(channel, 1.0, 0.0, -1) { }
extern private Cpu.Pin NativeGetAnalogOutputPinForChannel(Cpu.AnalogOutputChannel channel);
extern private int[] NativeGetAvailableAnalogOutputPrecisionInBitsForChannel(Cpu.AnalogOutputChannel channel);
/// <summary> /// Builds an instance of AnalogOutput type for the specified channel /// </summary> /// <param name="channel">The channel for the AnalogOutput</param> /// <param name="precisionInBits">The desired bit precision for the D/A conversion.</param> public AnalogOutput(Cpu.AnalogOutputChannel channel, int precisionInBits) : this(channel, 1.0, 0.0, precisionInBits) { }
protected static extern void Initialize(Cpu.AnalogOutputChannel channel, int precisionInBits);
protected static extern void Uninitialize(Cpu.AnalogOutputChannel channel);
/// <summary> /// Initialize a new instance of <see cref="AnalogSignalGenerator"/> for the specified channel /// </summary> /// <param name="channel">The analog output channel</param> /// <param name="clockDivisor">The divisor applied to <see cref="Cpu.SlowClock"/> to define the sample clock</param> public AnalogSignalGenerator(Cpu.AnalogOutputChannel channel, int clockDivisor) { int channelCount = GetChannelCount(); if ((int)channel < 0 || (int)channel >= channelCount) throw new ArgumentOutOfRangeException("channel"); _channel = channel; _pin = GetPin(channel); if (!Port.ReservePin(_pin, true)) throw new InvalidOperationException("Pin already reserved for another task"); _signalInfo = new int[8]; ClockDivisor = (UInt16)clockDivisor; NativeInitialize(); }
static public extern Cpu.Pin GetPin(Cpu.AnalogOutputChannel channel);
public virtual int[] GetAvailableAnalogOutputPrecisionInBitsForChannel(Cpu.AnalogOutputChannel channel) { return(NativeGetAvailableAnalogOutputPrecisionInBitsForChannel(channel)); }
public FEZCerberus_AnalogOut(Cpu.AnalogOutputChannel pin) { this.pin = pin; }
public FEZCerbuinoBee_AnalogOut(Cpu.AnalogOutputChannel pin) { this.pin = pin; }
override public int[] GetAvailableAnalogOutputPrecisionInBitsForChannel(Cpu.AnalogOutputChannel channel) { throw new NotImplementedException(); }
override public Cpu.Pin GetAnalogOutputPinForChannel(Cpu.AnalogOutputChannel channel) { throw new NotImplementedException(); }
public virtual int[] GetAvailableAnalogOutputPrecisionInBitsForChannel(Cpu.AnalogOutputChannel channel) { throw new HardwareProvidedNotRegistered(); }
public virtual Cpu.Pin GetAnalogOutputPinForChannel(Cpu.AnalogOutputChannel channel) { return(NativeGetAnalogOutputPinForChannel(channel)); }