예제 #1
0
        private static byte InputGainToByteValue(InputGain gain)
        {
            switch (gain)
            {
            case InputGain.Gain1:
                return(0);

            case InputGain.Gain2:
                return(1);

            case InputGain.Gain4:
                return(2);

            case InputGain.Gain8:
                return(3);

            case InputGain.Gain16:
                return(4);

            case InputGain.Gain32:
                return(5);

            case InputGain.Gain64:
                return(6);

            default:
                throw new ArgumentOutOfRangeException(nameof(gain), gain, null);
            }
        }
예제 #2
0
 public Registers(
     InputGain gain,
     InputDataRate dataRate,
     InputDetectCurrentSources detectCurrentSources,
     bool autoCalibrate,
     bool useInputBuffer)
 {
     Gain                 = gain;
     DataRate             = dataRate;
     DetectCurrentSources = detectCurrentSources;
     AutoCalibrate        = autoCalibrate;
     UseInputBuffer       = useInputBuffer;
     GainFactor           = GetGainFactor();
 }
예제 #3
0
        private Registers ReadRegisters(SpiDevice spiDevice)
        {
            WaitDataReady();

            byte[] readRegResponse = new byte[4]; // Make room for Status, Mux, AdControl & AdDataRate

            byte[] readRegRequest =
            {
                Constants.Command.ReadReg,
                (byte)(readRegResponse.Length - 1)
            };

            spiDevice.Write(readRegRequest);

            _timing.WaitMicroseconds(10);

            spiDevice.Read(readRegResponse);

            byte statusRegister = readRegResponse[Constants.Register.Status];
            //byte muxRegister = readRegResponse[Constants.Register.Mux];  <-- The MUX value is not interesting
            byte adControlRegister  = readRegResponse[Constants.Register.AdControl];
            byte adDataRateRegister = readRegResponse[Constants.Register.AdDataRate];

            bool autoCalibrate  = (statusRegister & (1 << Constants.StatusRegister.AutoCalibrateBit)) != 0;
            bool useInputBuffer = (statusRegister & (1 << Constants.StatusRegister.AnalogInputBufferBit)) != 0;

            InputGain inputGain = ByteValueToInputGain((byte)(adControlRegister & 0x07));                                            // Bit 0-2 of the "AdControl" register holds the input gain value
            InputDetectCurrentSources inputDetectCurrentSources = ByteValueToDetectCurrentSources((byte)(adControlRegister & 0x18)); // Bit 3-4 of the "AdControl" register holds the "Detect Current Sources" value

            InputDataRate inputDataRate = ByteValueToInputDataRate(adDataRateRegister);

            return(new Registers(
                       inputGain,
                       inputDataRate,
                       inputDetectCurrentSources,
                       autoCalibrate,
                       useInputBuffer));
        }