示例#1
0
        public void StartUpdating(int standbyDuration = 1000)
        {
            // thread safety
            lock (_lock) {
                if (IsSampling)
                {
                    return;
                }

                // state muh-cheen
                IsSampling = true;

                //SamplingTokenSource = new CancellationTokenSource();
                //CancellationToken ct = SamplingTokenSource.Token;


                if (UpdateData == null)
                {
                    UpdateData = new TempUpdateData();
                }

                UpdateData.standbyDuration = standbyDuration;
                Thread task1 = new Thread(new ThreadStart(UpdateTemp));
                task1.Start();
            }
        }
示例#2
0
        public void StartUpdating(
            Oversample temperatureSampleCount = Oversample.OversampleX8,
            Oversample pressureSampleCount    = Oversample.OversampleX8,
            Oversample humiditySampleCount    = Oversample.OversampleX1,
            int standbyDuration = 1000)
        {
            // TODO: for standby durations of 1,000ms and less, the sensor
            // will actually handle the reading loop. you put it into `Normal`
            // mode and set it to one of the known `StandbyDuration`s.
            //
            // So perhaps this should be an option. From a method signature
            // standpoint, i think that we would add an overload that took
            // a known `StandbyDuration` instead of an int.
            //
            // With that said, however, as far as I can tell, the sensor won't
            // send an interrupt when a new reading is taken, so i'm not sure
            // how we would synchronize with it, since the time that each read
            // takes is determined by the samples, filter, etc. -b
            //
            // TODO: for longer standby durations, we should put the sensor into
            // Modes.Sleep to save power. Need to figure out what the stanby
            // duration threshold is for that. i'm guessing 5 seconds might be a
            // good value.


            // thread safety
            lock (_lock) {
                if (IsSampling)
                {
                    return;
                }

                // state muh-cheen
                IsSampling = true;

                //SamplingTokenSource = new CancellationTokenSource();
                //CancellationToken ct = SamplingTokenSource.Token;
                if (UpdateData == null)
                {
                    UpdateData = new TempUpdateData();
                }
                UpdateData.humiditySampleCount    = humiditySampleCount;
                UpdateData.temperatureSampleCount = temperatureSampleCount;
                UpdateData.pressureSampleCount    = pressureSampleCount;
                UpdateData.standbyDuration        = standbyDuration;
                Thread task1 = new Thread(new ThreadStart(UpdateTemp));
                task1.Start();
            }
        }