コード例 #1
0
 internal AdcBackgroundWorkerArgs(AdcMode mode, MCP3424.AdcChannel channel, MCP3424.AdcSize size, MCP3424.AdcPga pga)
 {
     this._mode    = mode;
     this._channel = channel;
     this._size    = size;
     this._pga     = pga;
 }
コード例 #2
0
 internal ReportAdcProgressWithStatus(AdcMode mode, uint reading, double voltage, double current, UsbI2CInterface.UsbI2C.StatusResults statusResults)
 {
     _mode          = mode;
     _reading       = reading;
     _voltage       = voltage;
     _current       = current;
     _statusResults = statusResults;
 }
コード例 #3
0
        private void checkBoxReadVoltage_CheckedChanged(object sender, EventArgs e)
        {
            if (_usbI2C.IsOpen())
            {
                if (checkBoxReadVoltage.Checked)
                {
                    checkBoxReadVoltage.Text = "Stop";
                    comboBoxAdcMode.Enabled  = false;
                    comboBoxChannel.Enabled  = false;
                    comboBoxSize.Enabled     = false;
                    comboBoxGain.Enabled     = false;

                    _backgroundWorkerAdc                            = new BackgroundWorker();
                    _backgroundWorkerAdc.DoWork                    += BackgroundWorkerAdcDoWork;
                    _backgroundWorkerAdc.ProgressChanged           += BackgroundWorkerAdcProgressChanged;
                    _backgroundWorkerAdc.WorkerReportsProgress      = true;
                    _backgroundWorkerAdc.WorkerSupportsCancellation = true;

                    AdcMode            mode    = AdcMode.Raw;
                    MCP3424.AdcChannel channel = MCP3424.AdcChannel.Channel0;
                    MCP3424.AdcSize    size    = MCP3424.AdcSize.Size12Bit;
                    MCP3424.AdcPga     pga     = MCP3424.AdcPga.Gain1;
                    try
                    {
                        Enum.TryParse <AdcMode>(comboBoxAdcMode.SelectedValue.ToString(), out mode);
                        Enum.TryParse <MCP3424.AdcChannel>(comboBoxChannel.SelectedValue.ToString(), out channel);
                        Enum.TryParse <MCP3424.AdcSize>(comboBoxSize.SelectedValue.ToString(), out size);
                        Enum.TryParse <MCP3424.AdcPga>(comboBoxGain.SelectedValue.ToString(), out pga);
                    }
                    catch (Exception ex)
                    {
                        string error = ex.Message;
                    }

                    AdcBackgroundWorkerArgs args = new AdcBackgroundWorkerArgs(mode, channel, size, pga);
                    _backgroundWorkerAdc.RunWorkerAsync(args);
                }
                else
                {
                    checkBoxReadVoltage.Text = "Start";
                    comboBoxAdcMode.Enabled  = true;
                    comboBoxChannel.Enabled  = true;
                    comboBoxSize.Enabled     = true;
                    comboBoxGain.Enabled     = true;

                    if (_backgroundWorkerAdc != null && _backgroundWorkerAdc.IsBusy)
                    {
                        _backgroundWorkerAdc.CancelAsync();
                    }

                    Thread.Sleep(1000);
                }
            }
        }
コード例 #4
0
ファイル: Mcp3427.cs プロジェクト: microestc/dotnet-iot
 /// <summary>
 /// Constructs Mcp3427 instance
 /// </summary>
 /// <param name="i2CDevice">I2C device used to communicate with the device</param>
 /// <param name="mode">ADC operation mode</param>
 /// <param name="resolution">ADC resolution</param>
 /// <param name="pgaGain">PGA gain</param>
 public Mcp3427(I2cDevice i2CDevice, AdcMode mode = AdcMode.Continuous, AdcResolution resolution = AdcResolution.Bit12, AdcGain pgaGain = AdcGain.X1)
     : this(i2CDevice)
 {
     SetConfig(0, mode: mode, resolution: resolution, pgaGain: pgaGain);
 }
コード例 #5
0
ファイル: Helpers.cs プロジェクト: gitter-badger/iot-1
 public static byte SetModeBit(byte configByte, AdcMode mode)
 {
     return((byte)((configByte & ~Helpers.Masks.ModeMask) | (byte)mode));
 }