/// <summary>
 /// Costruttore
 /// </summary>
 /// <param name="res">Nome del canale analogico</param>
 /// <param name="scale">Valore di scalatura del valore letto dal canale analogico</param>
 /// <param name="offset">Offset aggiunto sul valore letto dal canale analogico</param>
 /// <param name="movingAverageSize">Dimensione del buffer per calcolo media</param>
 public AnalogIn(ADC res, double scale, double offset, int movingAverageSize)
     : base((Cpu.AnalogChannel)res)
 {
     _avg = new MovingAverageCalculator(movingAverageSize);
     Scale = scale;
     Offset = offset;
 }
示例#2
0
 /// <summary>
 /// Costruttore
 /// </summary>
 /// <param name="res">Nome del canale analogico</param>
 /// <param name="scale">Valore di scalatura del valore letto dal canale analogico</param>
 /// <param name="offset">Offset aggiunto sul valore letto dal canale analogico</param>
 /// <param name="movingAverageSize">Dimensione del buffer per calcolo media</param>
 public AnalogIn(ADC res, double scale, double offset, int movingAverageSize)
     : base((Cpu.AnalogChannel)res)
 {
     _avg   = new MovingAverageCalculator(movingAverageSize);
     Scale  = scale;
     Offset = offset;
 }
        private void Initialize(UIOMode mode, int select, int hwres, int intParam, bool isDigital, double scale, double offset)
        {
            _uioMode = mode;
            SelPort = (UIOSelector)select;

            switch (mode)
            {
                case UIOMode.UIOModeDigitalInput:
                    break;
                case UIOMode.UIOModeDigitalOutput:
                    DigitalOut = new DigitalOutput((Output)hwres);
                    break;
                case UIOMode.UIOModeAnalogInput:
                    _avg = new MovingAverageCalculator(intParam);
                    AnalogIn = new AnalogIn((ADC)hwres, scale, offset, intParam) {Scale = scale, Offset = offset};
                    break;
                case UIOMode.UIOModeSoftPwm:
                    if (intParam < 1 || intParam > 1000)
                        throw new ArgumentOutOfRangeException("Il valore deve essere compreso nel range 1...1000 Hz", "freq");
                    //creo ed avvio il PWM software
                    _softPwm = new SoftPWM(intParam, (Cpu.Pin)hwres);
                    SoftPWM.Start();
                    break;
                case UIOMode.UIOModeRealPwm:
                    if (intParam < 1 || intParam > 1000000)
                        throw new ArgumentOutOfRangeException("Il valore deve essere compreso nel range 1...1 MHz", "freq");
                    //creo ed avvio il PWM hardware
                    _realPwm = new PWM((Cpu.PWMChannel)hwres, intParam, 0, false);
                    _realPwm.Start();
                    break;
                case UIOMode.UIOModeSoftDac:
                    if (intParam < 1 || intParam > 1000)
                        throw new ArgumentOutOfRangeException("Il valore deve essere compreso nel range 1...1000 Hz", "freq");
                    //creo ed avvio il PWM software
                    _softPwm = new SoftPWM(intParam, (Cpu.Pin)hwres);
                    SoftPWM.Start();
                    break;
                case UIOMode.UIOModeRealDac:
                    if (intParam < 1 || intParam > 1000000)
                        throw new ArgumentOutOfRangeException("Il valore deve essere compreso nel range 1...1 MHz", "freq");
                    //creo ed avvio il PWM hardware
                    _realPwm = new PWM((Cpu.PWMChannel)hwres, intParam, 0, false);
                    _realPwm.Start();
                    break;
                default:
                    break;
            }

            //seleziono sul modulo il tipo di uscita DAC/PWM
            _pwmSel = new DigitalOutput((Output)SelPort);
            _pwmSel.Write(isDigital);

        }
        private void Initialize(UIOMode mode, int select, int hwres, int intParam, bool isDigital, double scale, double offset)
        {
            _uioMode = mode;
            SelPort  = (UIOSelector)select;

            switch (mode)
            {
            case UIOMode.UIOModeDigitalInput:
                break;

            case UIOMode.UIOModeDigitalOutput:
                DigitalOut = new DigitalOutput((Output)hwres);
                break;

            case UIOMode.UIOModeAnalogInput:
                _avg     = new MovingAverageCalculator(intParam);
                AnalogIn = new AnalogIn((ADC)hwres, scale, offset, intParam)
                {
                    Scale = scale, Offset = offset
                };
                break;

            case UIOMode.UIOModeSoftPwm:
                if (intParam < 1 || intParam > 1000)
                {
                    throw new ArgumentOutOfRangeException("Il valore deve essere compreso nel range 1...1000 Hz", "freq");
                }
                //creo ed avvio il PWM software
                _softPwm = new SoftPWM(intParam, (Cpu.Pin)hwres);
                SoftPWM.Start();
                break;

            case UIOMode.UIOModeRealPwm:
                if (intParam < 1 || intParam > 1000000)
                {
                    throw new ArgumentOutOfRangeException("Il valore deve essere compreso nel range 1...1 MHz", "freq");
                }
                //creo ed avvio il PWM hardware
                _realPwm = new PWM((Cpu.PWMChannel)hwres, intParam, 0, false);
                _realPwm.Start();
                break;

            case UIOMode.UIOModeSoftDac:
                if (intParam < 1 || intParam > 1000)
                {
                    throw new ArgumentOutOfRangeException("Il valore deve essere compreso nel range 1...1000 Hz", "freq");
                }
                //creo ed avvio il PWM software
                _softPwm = new SoftPWM(intParam, (Cpu.Pin)hwres);
                SoftPWM.Start();
                break;

            case UIOMode.UIOModeRealDac:
                if (intParam < 1 || intParam > 1000000)
                {
                    throw new ArgumentOutOfRangeException("Il valore deve essere compreso nel range 1...1 MHz", "freq");
                }
                //creo ed avvio il PWM hardware
                _realPwm = new PWM((Cpu.PWMChannel)hwres, intParam, 0, false);
                _realPwm.Start();
                break;

            default:
                break;
            }

            //seleziono sul modulo il tipo di uscita DAC/PWM
            _pwmSel = new DigitalOutput((Output)SelPort);
            _pwmSel.Write(isDigital);
        }