Ejemplo n.º 1
0
        public override void ParseData(string command)
        {
            var jObject = JObject.Parse(command);

            if (jObject["alarm"] != null && bool.TryParse(jObject["alarm"].ToString(), out bool alarm))
            {
                if (alarm)
                {
                    OnAlarm?.Invoke(this, new EventArgs());
                }
                else
                {
                    OnAlarmStopped?.Invoke(this, new EventArgs());
                }

                Alarm = alarm;
            }

            if (jObject["density"] != null && float.TryParse(jObject["density"].ToString(), out float h))
            {
                var newDensity = h / 100;

                if (Density != null && Math.Abs(newDensity - Density.Value) > 0.01)
                {
                    OnDensityChange?.Invoke(this, new DensityEventArgs(newDensity));
                }

                Density = newDensity;
            }

            if (jObject["voltage"] != null && float.TryParse(jObject["voltage"].ToString(), out float v))
            {
                Voltage = v / 1000;
            }
        }
Ejemplo n.º 2
0
 void m_Timer_Elapsed(object sender, ElapsedEventArgs e)
 {
     if (Active && OnAlarm != null)
     {
         OnAlarm.Invoke(this, EventArgs.Empty);
     }
 }
Ejemplo n.º 3
0
        public override void ParseData(string command)
        {
            var jObject = JObject.Parse(command);

            if (jObject.ParseInt("alarm", out int alarm))
            {
                Alarm = alarm == 1;

                if (Alarm)
                {
                    OnAlarm?.Invoke(this, new EventArgs());
                }
                else
                {
                    OnAlarmStopped?.Invoke(this, new EventArgs());
                }
            }

            if (jObject.ParseFloat("density", out float h))
            {
                var newDensity = h / 100;

                if (Density != null && Math.Abs(newDensity - Density.Value) > 0.01)
                {
                    OnDensityChange?.Invoke(this, new DensityEventArgs(newDensity));
                }

                Density = newDensity;
            }

            Voltage = jObject.ParseVoltage();
        }
Ejemplo n.º 4
0
        private void Counter()
        {
            Task.Factory.StartNew(() =>
            {
                ShowAlarmTime();

                do
                {
                    ShowCurrentTime();
                    //Sleep for one second
                    Thread.Sleep(1000);
                    //And increment our inner counter
                    _currentTime += 1;

                    if (_alarmTime == _currentTime)
                    {
                        OnAlarm?.Invoke();
                    }
                } while (true);
            });
        }
Ejemplo n.º 5
0
 void Alarm()
 {
     OnAlarm?.Invoke(this, new EventArgs());
 }
Ejemplo n.º 6
0
 public void AddSleeper(OnAlarm a)
 {
     alarmer = new OnAlarm(a);
 }