Example #1
0
        private void ConfigureGenerator(TemperatureTwin twin)
        {
            lock (_sync)
            {
                if (twin == null ||
                    twin.SamplingHz <= 0 ||
                    twin.Amplitude <= 0 ||
                    twin.Frequency <= 0)
                {
                    return;
                }

                _samplingRateHz = twin.SamplingHz;
                var waveConfiguration = new[]
                {
                    new WaveConfig
                    {
                        Amplitude            = twin.Amplitude,
                        FrequencyInKilohertz = twin.Frequency / 1000,
                        WaveType             = (WaveType)(int)twin.WaveType,
                        Offset = twin.Offset
                    }
                };

                _dataGenerator = new WaveGenerator.WaveGenerator(waveConfiguration);
            }
        }
        public TemperatureSensor()
        {
            _dataGenerator = new WaveGenerator.WaveGenerator(_waveConfiguration);

            Twin.Subscribe(async twin =>
            {
                lock (_sync)
                {
                    _minimum           = twin.DesiredMaximum;
                    _maximum           = twin.DesiredMaximum;
                    _sampleRateHz      = twin.SampleRateHz;
                    _waveConfiguration = new WaveConfig[] {
                        twin.WaveConfig
                    };
                }
                await Twin.ReportAsync(twin);
                return(TwinResult.Ok);
            });
        }
Example #3
0
        static void Main(string[] args)
        {
            var comps = new WaveConfig[1];

            comps[0] = new WaveConfig()
            {
                Amplitude            = 10,
                FrequencyInKilohertz = 0.002,
                WaveType             = WaveType.Sine,
                Offset = 60
            };

            var g  = new WaveGenerator.WaveGenerator(comps);
            var sw = new Stopwatch();

            sw.Start();

            while (true)
            {
                var text = new string('-', 60 + (int)g.Read());
                Console.WriteLine(sw.Elapsed.ToString() + text);
                Thread.Sleep(10);
            }
        }