Exemplo n.º 1
0
        void UpdateTemp()
        {
            AtmosphericConditions            oldConditions;
            AtmosphericConditionChangeResult result;

            while (true)
            {
                if (!IsSampling)
                {
                    break;
                }
                // capture history
                oldConditions = AtmosphericConditions.From(Conditions);

                // read
                Update();

                // build a new result with the old and new conditions
                result = new AtmosphericConditionChangeResult(oldConditions, Conditions);

                // let everyone know
                RaiseChangedAndNotify(result);

                // sleep for the appropriate interval
                Thread.Sleep(UpdateData.standbyDuration);
            }
        }
Exemplo n.º 2
0
        void UpdateTemp()
        {
            //SamplingTokenSource = new CancellationTokenSource();
            //CancellationToken ct = SamplingTokenSource.Token;

            AtmosphericConditions            oldConditions;
            AtmosphericConditionChangeResult result;


            while (true)
            {
                // cleanup
                if (!IsSampling)
                {
                    // do task clean up here
                    //_observers.ForEach(x => x.OnCompleted());
                    break;
                }
                // capture history
                oldConditions = AtmosphericConditions.From(Conditions);

                // read
                Update();

                // build a new result with the old and new conditions
                result = new AtmosphericConditionChangeResult(oldConditions, Conditions);

                // let everyone know
                RaiseChangedAndNotify(result);

                // sleep for the appropriate interval
                Thread.Sleep(UpdateData.standbyDuration);
            }
        }
Exemplo n.º 3
0
 private void Mcp9808TemperatureUpdated(AtmosphericConditionChangeResult e)
 {
     lock (this.updateLock)
     {
         this.Display9808Temperature(e.New);
     }
 }
Exemplo n.º 4
0
 private void AnalogTemperatureUpdated(object sender, AtmosphericConditionChangeResult e)
 {
     lock (this.updateLock)
     {
         this.DisplayAnalogTemperature(new AtmosphericConditions
         {
             Humidity    = e.New.Humidity,
             Pressure    = e.New.Pressure,
             Temperature = e.New.Temperature / 1000
         });
     }
 }
Exemplo n.º 5
0
        private void AnalogTemperatureUpdated(object sender, AtmosphericConditionChangeResult e)
        {
            float oldTemp = e.Old.Temperature.Value / 1000;
            float newTemp = e.New.Temperature.Value / 1000;

            this.graphics.DrawText(
                x: 48, y: 160,
                text: $"{oldTemp.ToString("##.#")}°C",
                color: this.colors[this.colors.Length - 1],
                scaleFactor: GraphicsLibrary.ScaleFactor.X2);
            this.graphics.DrawText(
                x: 48, y: 160,
                text: $"{newTemp.ToString("##.#")}°C",
                color: Color.White,
                scaleFactor: GraphicsLibrary.ScaleFactor.X2);

            this.graphics.Show();
        }
Exemplo n.º 6
0
        void AnalogTemperatureUpdated(object sender, AtmosphericConditionChangeResult e)
        {
            graphics.DrawRectangle(
                x: 48,
                y: 160,
                width: 144,
                height: 40,
                color: colors[colors.Length - 1],
                filled: true);

            graphics.DrawText(
                x: 48, y: 160,
                text: $"{e.New.Temperature.Value.ToString("00.0")}°C",
                color: Color.White,
                scaleFactor: GraphicsLibrary.ScaleFactor.X2);

            graphics.Show();
        }
Exemplo n.º 7
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;

                AtmosphericConditions            oldConditions;
                AtmosphericConditionChangeResult result;
                var task1 = new Thread(new ThreadStart(() => {
                    while (true)
                    {
                        if (!IsSampling)
                        {
                            // do task clean up here
                            //_observers.ForEach(x => x.OnCompleted());
                            break;
                        }
                        // capture history
                        oldConditions = AtmosphericConditions.From(Conditions);

                        // read
                        Update(); //syncrhnous for this driver

                        // build a new result with the old and new conditions
                        result = new AtmosphericConditionChangeResult(oldConditions, Conditions);

                        // let everyone know
                        RaiseChangedAndNotify(result);

                        // sleep for the appropriate interval
                        Thread.Sleep(standbyDuration);
                    }
                }));
            }
        }
Exemplo n.º 8
0
        void AnalogTemperatureUpdated(object sender, AtmosphericConditionChangeResult e)
        {
            bool displayF = this.displayFarenheit;

            float newTemp = (float)(e.New.Temperature / 1000);

            string temperatureString;

            if (displayF)
            {
                float newTempF = (newTemp * 9 / 5) + 32;
                temperatureString = string.Format("{0}°F", newTempF.ToString("##.#"));
            }
            else
            {
                temperatureString = string.Format("{0}°C", newTemp.ToString("##.#"));
            }

            int temperatureX = (int)((this.displayWidth - (temperatureString.Length * 24)) / 2);

            // erase the old value
            this.graphics.DrawText(
                x: this.oldTemperatureX, y: 160,
                text: oldTemperatureString,
                color: colors[colors.Length - 1],
                scaleFactor: GraphicsLibrary.ScaleFactor.X2);

            // display the new value
            this.graphics.DrawText(
                x: temperatureX, y: 160,
                text: temperatureString,
                color: Color.White,
                scaleFactor: GraphicsLibrary.ScaleFactor.X2);

            graphics.Show();

            this.oldTemperatureString = temperatureString;
            this.oldTemperatureX      = temperatureX;
        }
Exemplo n.º 9
0
 protected void RaiseChangedAndNotify(AtmosphericConditionChangeResult changeResult)
 {
     Updated?.Invoke(this, changeResult);
     //base.NotifyObservers(changeResult);
 }
Exemplo n.º 10
0
 private void AtmosphericConditionsChangedHandler(object _, AtmosphericConditionChangeResult e)
 {
     this.OutputConditions(e.New);
 }