Example #1
0
        public static Gadgeteer.SocketInterfaces.AnalogInput Create(Socket socket, Socket.Pin pin, Module module)
        {
            socket.EnsureTypeIsSupported('A', module);
            socket.ReservePin(pin, module);
            Cpu.AnalogChannel channel = Cpu.AnalogChannel.ANALOG_NONE;
            switch (pin)
            {
            case Socket.Pin.Three:
                channel = socket.AnalogInput3;
                break;

            case Socket.Pin.Four:
                channel = socket.AnalogInput4;
                break;

            case Socket.Pin.Five:
                channel = socket.AnalogInput5;
                break;
            }
            if ((channel == Cpu.AnalogChannel.ANALOG_NONE) && (socket.AnalogInputIndirector != null))
            {
                return(socket.AnalogInputIndirector(socket, pin, module));
            }
            return(new NativeAnalogInput(socket, pin, module, channel));
        }
        /// <summary>
        /// Creates an instance of <see cref="AnalogInput" /> for the given socket and pin number.
        /// </summary>
        /// <remarks>This automatically checks that the socket supports Type A, and reserves the pin used.
        /// An exception will be thrown if there is a problem with these checks.</remarks>
        /// <param name="socket">The socket.</param>
        /// <param name="pin">The analog input pin to use.</param>
        /// <param name="module">The module using the socket, which can be null if unspecified.</param>
        /// <returns>An instance of <see cref="AnalogInput" /> for the given socket and pin number.</returns>
        public static AnalogInput Create(Socket socket, Socket.Pin pin, Module module)
        {
            socket.EnsureTypeIsSupported('A', module);
            socket.ReservePin(pin, module);

            Cpu.AnalogChannel channel = Cpu.AnalogChannel.ANALOG_NONE;
            switch (pin)
            {
            case Socket.Pin.Three:
                channel = socket.AnalogInput3;
                break;

            case Socket.Pin.Four:
                channel = socket.AnalogInput4;
                break;

            case Socket.Pin.Five:
                channel = socket.AnalogInput5;
                break;
            }

            // native implementation is preferred to an indirected one
            if (channel == Cpu.AnalogChannel.ANALOG_NONE && socket.AnalogInputIndirector != null)
            {
                return(socket.AnalogInputIndirector(socket, pin, module));
            }

            else
            {
                return(new NativeAnalogInput(socket, pin, module, channel));
            }
        }
Example #3
0
 /// <summary>
 /// PinKit センサーボードのコンストラクター
 /// </summary>
 /// <param name="vr1">分圧抵抗値(サーミスター用)</param>
 /// <param name="vr2">分圧抵抗値(端子台用)</param>
 public SensorBoard(double vr1, double vr2)
 {
     _tempChannel = Pins.ANALOG_5;   // サーミスターはAnalog 5番ピン
     _termChannel = Pins.ANALOG_4;   // 端子台はAnalog 4番ピン
     _vr1         = vr1;
     _vr2         = vr2;
 }
 /// <summary>
 /// PinKit �Z���T�[�{�[�h�̃R���X�g���N�^�[
 /// </summary>
 /// <param name="vr1">������R�l�i�T�[�~�X�^�[�p�j</param>
 /// <param name="vr2">������R�l�i�[�q��p�j</param>
 public SensorBoard(double vr1, double vr2)
 {
     _tempChannel = Pins.ANALOG_5;   // �T�[�~�X�^�[��Analog 5�ԃs��
     _termChannel = Pins.ANALOG_4;   // �[�q���Analog 4�ԃs��
     _vr1 = vr1;
     _vr2 = vr2;
 }
        public IRDistanceUpdater(Cpu.AnalogChannel channel, int sampleCount, int delay = 1000)
        {
            _irSensor = new IrDistanceSensor(channel, sampleCount);
            _workItem = new WorkItem(BroadcastIrUpdate, false, true, true);

            _delay = delay;
        }
        public TemperatureSensor(Cpu.AnalogChannel AnalogInputPin)
        {
            analogInput = new AnalogInput(AnalogInputPin);

            gather_input          = new Thread(GatherInput);
            gather_input.Priority = ThreadPriority.Lowest;
            gather_input.Start();
        }
Example #7
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="channel">Analog channel used for reading LDR value</param>
 /// <param name="adcResolution">ADC resolution for analog channel</param>
 /// <param name="loadResistor">Load resistor in the LDR circuit (Ohm)</param>
 /// <param name="aRef">Voltage reference for ADC</param>
 public Ldr(Cpu.AnalogChannel channel, int adcResolution, int loadResistor, double aRef = DEFAULT_AREF)
 {
     this.input         = new AnalogInput(channel);
     this.adcResolution = adcResolution;
     this.maxValue      = (int)System.Math.Pow(2, adcResolution) - 1;
     this.loadResistor  = loadResistor;
     this.aRef          = aRef;
 }
Example #8
0
        public AnalogInputPin(Cpu.AnalogChannel pin, double updateFrequency = DefaultUpdateFrequency)
            : base(updateFrequency)
        {
            input = new AnalogInput(pin, -1);

            var initialValue = input.Read();

            Analog = AddPort("Analog", Units.Ratio, initialValue);
        }
Example #9
0
        //--//

        /// <summary>
        /// Builds an instance of AnalogInput type for the specified channel
        /// </summary>
        /// <param name="channel">The channel for the AnalogInput</param>
        /// <param name="scale">A multiplicative factor to apply to the raw reading from the sensor</param>
        /// <param name="offset">A constant factor to add to the raw reading from the sensor</param>
        /// <param name="precisionInBits">The desired bit precision for the A/D conversion. A value of -1 indicates default precision.</param>
        public AnalogInput(Cpu.AnalogChannel channel, double scale, double offset, int precisionInBits) 
        {
            m_channel = channel;
            
            HardwareProvider hwProvider = HardwareProvider.HwProvider;

            if(hwProvider == null) throw new InvalidOperationException();
            
            m_pin = hwProvider.GetAnalogPinForChannel(channel);
            m_scale = scale;
            m_offset = offset;

            int[] availablePrecisions = hwProvider.GetAvailablePrecisionInBitsForChannel(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;
            }
        }
Example #10
0
            public Axis(Cpu.Pin pin, Cpu.AnalogChannel analogChannel, double voltage)
            {
                _voltage = voltage;

                var ax = new InterruptPort(pin, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);

                ax.Dispose();

                _analogInput = new AnalogInput(analogChannel);
            }
 public NativeAnalogInput(Socket socket, Socket.Pin pin, Module module, Cpu.AnalogChannel channel)
 {
     if (channel == Cpu.AnalogChannel.ANALOG_NONE)
     {
         Socket.InvalidSocketException.ThrowIfOutOfRange(pin, Socket.Pin.Three, Socket.Pin.Five, "AnalogInput", module);
         throw Socket.InvalidSocketException.FunctionalityException(socket, "AnalogInput");
     }
     this._channel = channel;
     this._socket  = socket;
 }
Example #12
0
 public KeyPad(Cpu.AnalogChannel pin)
 {
     if (pin != Cpu.AnalogChannel.ANALOG_NONE) // (select key are optional)
     {
         _keyPort = new AnalogInput(pin)
         {
             Scale = 1000
         };
     }
 }
Example #13
0
        /// <summary>
        /// コンストラクター
        /// </summary>
        /// <param name="channel">サーミスターを接続するアナログチャンネル</param>
        /// <param name="bc">サーミスターのB定数値</param>
        /// <param name="r25">摂氏25度のゼロ負荷抵抗値</param>
        /// <param name="vrd">分圧する抵抗値</param>
        /// <param name="adc">A/D変換の分解能</param>
        internal Temperature(Cpu.AnalogChannel channel, double bc, double r25, double vrd, double adc)
        {
            _temperatureInput = new AnalogInput(channel);
            _bc  = bc;
            _r25 = r25;
            _vrd = vrd;
            _adc = adc;

            _timer = new Timer(Measure_Timer, null, Timeout.Infinite, Timeout.Infinite);
        }
Example #14
0
 public TdsMeter(Cpu.AnalogChannel AnalogPin)
 {
     analogBuffer     = new double[SCOUNT];
     analogBufferTemp = new double[SCOUNT];
     tdsSensor        = new AnalogInput(AnalogPin);
     tdsValue         = 0;
     th1 = new Thread(new ThreadStart(Loop));
     analogSampleTimepoint = DateTime.Now;
     printTimepoint        = DateTime.Now;
     th1.Start();
 }
        public CustomMagUpdater(int dataCount, Cpu.AnalogChannel magPin)
        {
            _magPin    = new AnalogInput(magPin);
            _dataCount = dataCount;
            Rebug.Print("Initializing high frequency custom magnetometer update cycle");
            _dataArray = new byte[dataCount + MetaDataCount + TimeDataCount];
            _workItem  = new WorkItem(DumpMagData, ref _dataArray, loggable: true, persistent: true, pauseable: true);

            _dataArray[0] = (byte)PacketType.StartByte;
            _dataArray[1] = (byte)PacketType.FMagDump;
        }
Example #16
0
 public LinearActuator(Cpu.AnalogChannel actuatorSensorPin, Cpu.Pin megaMotoEnablePin, Cpu.Pin megaMotoPWMAPin, Cpu.Pin megaMotoPWMBPin, Cpu.AnalogChannel megaMotoSensorPin)
 {
     _megaMotoEnable             = new OutputPort(megaMotoEnablePin, false);
     _megaMotoPWMA               = new OutputPort(megaMotoPWMAPin, false);
     _megaMotoPWMB               = new OutputPort(megaMotoPWMBPin, false);
     _linearActuatorSensor       = new AnalogInput(actuatorSensorPin);
     _linearActuatorSensor.Scale = 255;
     _megaMotoSensor             = new AnalogInput(megaMotoSensorPin);
     _megaMotoSensor.Scale       = 255;
     RetractedPosition           = 90; // default range
     ExtendedPosition            = 270;
 }
Example #17
0
        public NativeAnalogInput(Socket socket, Socket.Pin pin, Module module, Cpu.AnalogChannel channel)
        {
            if (channel == Cpu.AnalogChannel.ANALOG_NONE)
            {
                Socket.InvalidSocketException.ThrowIfOutOfRange(pin, Socket.Pin.Three, Socket.Pin.Five, "AnalogInput", module);

                // this is a mainboard error that should not happen (we already check for it in SocketInterfaces.RegisterSocket) but just in case...
                throw Socket.InvalidSocketException.FunctionalityException(socket, "AnalogInput");
            }

            _channel = channel;
            _socket  = socket;
        }
Example #18
0
        public NativeAnalogInput(Socket socket, Socket.Pin pin, Module module, Cpu.AnalogChannel channel)
        {
            if (channel == Cpu.AnalogChannel.ANALOG_NONE)
            {
                Socket.InvalidSocketException.ThrowIfOutOfRange(pin, Socket.Pin.Three, Socket.Pin.Five, "AnalogInput", module);

                // this is a mainboard error that should not happen (we already check for it in SocketInterfaces.RegisterSocket) but just in case...
                throw Socket.InvalidSocketException.FunctionalityException(socket, "AnalogInput");
            }

            _channel = channel;
            _socket = socket;
        }
Example #19
0
 public TempProbe(string name, Cpu.AnalogChannel pin)
 {
     Name              = name;
     _aInput           = new AnalogInput(pin);
     _accumulator      = 0;
     _accumulatedCount = 0;
     TemperatureF      = -1;
     TemperatureR      = -1;
     TemperatureC      = -1;
     TemperatureFAvg   = -1;
     _steinhart        = new double[4] {
         2.3067434e-4, 2.3696596e-4, 1.2636414e-7, 1.0e+4
     };
 }
Example #20
0
        /// <summary>
        /// Create a new sensor driver instance.
        /// </summary>
        /// <param name="windSpeedPin">The Netduino pin that is connected to sensor pin 5</param>
        /// <param name="windDirectionPulse">The Netduino pin that is connected to sensor pin 2</param>
        /// <param name="windDirectionSensor">The Netduino pin that is connected to sensor pin 3</param>
        /// <param name="logger">The logger that should receive the NMEA output</param>
        public WindSensor(
            Cpu.Pin windSpeedPin,
            Cpu.Pin windDirectionPulse,
            Cpu.AnalogChannel windDirectionSensorPin,
            WindSensorCallback windSensorCallback)
        {
            windDirectionSensor = new AnalogInput(windDirectionSensorPin);
            pulsePort           = new OutputPort(windDirectionPulse, false);
            pulsePort.Write(true);
            m_callback = windSensorCallback;

            speedPort              = new InterruptPort(windSpeedPin, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeHigh);
            speedPort.OnInterrupt += new NativeEventHandler(speedPort_OnInterrupt);
            timer = new Timer(new TimerCallback(RateCallback), null, windDirectionInterval, windDirectionInterval);
        }
Example #21
0
        public AnalogInputWrapper(
            string name,
            Cpu.AnalogChannel channel,
            double scale,
            double offset,
            double normalizedTolerance = 0.05
            )
            : base(channel, scale, offset, 12)
        {
            this.Name = name;

            //precalculate the absolute variation window
            //around the reference (old) sampled value
            this._absoluteToleranceDelta = scale * normalizedTolerance;
        }
Example #22
0
 /// <summary>
 /// Analog thumb joystick
 /// </summary>
 /// <param name="HorizontalPin">Analog pin for the horizontal bar</param>
 /// <param name="VerticalPin">Analog pin for the vertical bar</param>
 /// <param name="PushPin">Pin for the push button (optionally this class handles the push button)</param>
 /// <param name="InvertHorizontal">When true, the horizontal value will be inverted</param>
 /// <param name="InvertVertical">When true, the vertical value will be inverted</param>
 public ThumbJoystick(Cpu.AnalogChannel HorizontalPin, Cpu.AnalogChannel VerticalPin, Cpu.Pin PushPin = Cpu.Pin.GPIO_NONE, bool InvertHorizontal = false, bool InvertVertical = false)
 {
     // Configures the analog inputs
     this._Horizontal = new IntegratedADC(HorizontalPin);
     this._Horizontal.RangeSet(-50, 50);
     this._Vertical = new IntegratedADC(VerticalPin);
     this._Vertical.RangeSet(-50, 50);
     // Invertion will be copied
     this.InvertHorizontal = InvertHorizontal;
     this.InvertVertical   = InvertVertical;
     // If needed, configures the digital input
     if (PushPin != Cpu.Pin.GPIO_NONE)
     {
         this._Push = new InputPort(PushPin, false, Port.ResistorMode.PullUp);
     }
 }
Example #23
0
        public PhMeter(Cpu.AnalogChannel AnalogPin)
        {
            try
            {
                phSensor = new AnalogInput(AnalogPin);

                buf = new double[10];

                PhValue = 0;
                th1     = new Thread(new ThreadStart(Loop));
                th1.Start();
            }
            catch (Exception ex)
            {
                Debug.Print("Ph Sensor Error" + ex.Message);
            }
        }
        public LightTracker(Cpu.PWMChannel panPin, Cpu.AnalogChannel topLeftPhotocell, Cpu.AnalogChannel topRightPhotocell)
        {
            _panServo = new ContServo(panPin);
            _panServo.reset_ticks();


            //_tiltServo = new Servo(tiltPin, 150) { Degree = 150 };
            //_lastY = _tiltServo.Degree;


            photoCellL = new AnalogInput(topLeftPhotocell);
            photoCellR = new AnalogInput(topRightPhotocell);
            //photoCellBL = new AnalogInput(bottomLeftPhotocell);
            //photoCellBR = new AnalogInput(bottomRightPhotocell);


            _trackAction = new WorkItem(SearchForLight, true);
        }
Example #25
0
        // Note: A constructor summary is auto-generated by the doc builder.
        /// <summary></summary>
        /// <remarks>This automatically checks that the socket supports Type A, and reserves the pin used.
        /// An exception will be thrown if there is a problem with these checks.</remarks>
        /// <param name="socket">The socket.</param>
        /// <param name="pin">The analog input pin to use.</param>
        /// <param name="module">The module using the socket, which can be null if unspecified.</param>
        public AnalogInput(Socket socket, Socket.Pin pin, Module module)
        {
            this.socket = socket;
            socket.EnsureTypeIsSupported('A', module);

            switch (pin)
            {
            case Socket.Pin.Three:
                channel = socket.AnalogInput3;
                break;

            case Socket.Pin.Four:
                channel = socket.AnalogInput4;
                break;

            case Socket.Pin.Five:
                channel = socket.AnalogInput5;
                break;

            default:
                if (module != null)
                {
                    throw new Socket.InvalidSocketException("Module " + module + " cannot use Analog Input interface on pin " + pin + " - pin must be in range 3 to 5.");
                }
                else
                {
                    throw new Socket.InvalidSocketException("Cannot use Analog Input interface on pin " + pin + " - pin must be in range 3 to 5.");
                }
            }

            if (channel == Cpu.AnalogChannel.ANALOG_NONE)
            {
                // this is a mainboard error that should not happen (we already check for it in SocketInterfaces.RegisterSocket) but just in case...
                throw new Socket.InvalidSocketException("Socket " + socket + " has an error with its Analog Input functionality. Please try a different socket.");
            }

            socket.ReservePin(pin, module);
        }
        /// <summary>
        /// New instance of the AnalogTemperatureSensor class.
        /// </summary>
        /// <param name="analogPin">Analog pin the temperature sensor is connected to.</param>
        /// <param name="sensor">Type of sensor attached to the analog port.</param>
        /// <param name="sampleReading">Sample sensor reading in degrees centigrade (Optional)</param>
        /// <param name="millivoltsAtSampleReading">Number of millivolts representing the sample reading (Optional)</param>
        /// <param name="millivoltsPerDegreeCentigrade">Number of millivolts pre degree centigrade (Optional)</param>
        public AnalogTemperatureSensor(Cpu.AnalogChannel analogPin, SensorType sensor, int sampleReading = 25,
                                       int millivoltsAtSampleReading = 250, int millivoltsPerDegreeCentigrade = 10)
        {
            AnalogPort = new AnalogInput(analogPin);
            switch (sensor)
            {
            case SensorType.TMP35:
            case SensorType.LM35:
            case SensorType.LM45:
                _yIntercept = 0;
                _millivoltsPerDegreeCentigrade = 10;
                break;

            case SensorType.LM50:
            case SensorType.TMP36:
                _yIntercept = 500;
                _millivoltsPerDegreeCentigrade = 10;
                break;

            case SensorType.TMP37:
                _yIntercept = 0;
                _millivoltsPerDegreeCentigrade = 20;
                break;

            case SensorType.Custom:
                _yIntercept = millivoltsAtSampleReading - (sampleReading * millivoltsAtSampleReading);
                _millivoltsPerDegreeCentigrade = millivoltsPerDegreeCentigrade;
                break;

            default:
                throw new ArgumentException("Unknown sensor type", "sensor");
#pragma warning disable 0162
                break;
#pragma warning restore 0162
            }
        }
Example #27
0
 /// <summary>
 /// TMP 36GZ Temperature Sensor
 /// </summary>
 /// <param name="AnalogPort">The port the sensor is connected to</param>
 public Tmp36(Cpu.AnalogChannel AnalogPort)
 {
     this._AnalogPort = new IntegratedADC(AnalogPort);
     this._AnalogPort.RangeSet(0, 1024);
 }
Example #28
0
 public SensorSound(Cpu.AnalogChannel pin, int SampleRateMilliseconds, string name)
     : base(SensorType.Sound, ValuesPerSample.One, SampleRateMilliseconds, name)
 {
     analogPin = new AnalogInput(pin, -1);
     StartMeasuring();
 }
Example #29
0
        /// <summary>
        /// コンストラクター
        /// </summary>
        /// <param name="channel">アナログチャンネル</param>
        public SensorTerminal(Cpu.AnalogChannel channel)
        {
            _sensor = new AnalogInput(channel);

            _timer = new Timer(Measure_Timer, null, Timeout.Infinite, Timeout.Infinite);
        }
 public virtual int[] GetAvailablePrecisionInBitsForChannel(Cpu.AnalogChannel channel)
 {
     //Return nothing as no analog
     return(null); // new int[0]; //NativeGetAvailablePrecisionInBitsForChannel(channel);
 }
 public virtual Cpu.Pin GetAnalogPinForChannel(Cpu.AnalogChannel channel)
 {
     return(Cpu.Pin.GPIO_NONE);
 }
Example #32
0
 public LightSensor(Cpu.AnalogChannel analogPin)
 {
     analogInput = new AnalogInput(analogPin);
 }
Example #33
0
 public SensorMoisture(Cpu.AnalogChannel pin, int SampleRateMilliseconds, string name)
     : base(pin, SampleRateMilliseconds, name, "moisture", "p")
 {
 }
 public AnalogElement(BaseShield.AnalogPorts port)
 {
     var channels = BaseShield.GetAnalogChannels(port);
     Channel1 = channels[0];
     Channel2 = channels[1];
 }