aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/FSE/Modules/Tango.FSE.Diagnostics/Project/Widgets/Input/InputWidget.cs
blob: 41fb9953c4098a5936d4f7e41c4b7aa2afa6d930 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Tango.BL.Entities;
using Tango.BL.Enumerations;
using Tango.FSE.Common.Diagnostics;

namespace Tango.FSE.Diagnostics.Project.Widgets.Input
{
    [Description("Digital Input LED")]
    public class InputWidget : DiagnosticsWidget, ISupportsComponentSelection<TechIos>
    {
        public TechIos IO { get; set; } = TechIos.LS_DH_CLEAN_DOWN;

        private TechIo _techIO;
        [JsonIgnore]
        public TechIo TechIo
        {
            get { return _techIO; }
            set { _techIO = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(DisplayName)); }
        }

        [JsonIgnore]
        public override string DisplayName
        {
            get
            {
                return this.TechIo != null ? this.TechIo.InterfaceName : String.Empty;
            }
        }

        private bool _value;
        [JsonIgnore]
        public bool Value
        {
            get { return _value; }
            set
            {
                if (_value != value)
                {
                    _value = value;
                    RaisePropertyChangedAuto();
                }
            }
        }

        public override async Task Init()
        {
            int io = (int)IO;
            TechIo = await Services.TechComponentsService.IOs.FindOne(x => x.Code == io);
        }

        public override void OnDiagnosticsData(DiagnosticsPackage package)
        {
            var state = package.GetDigitalInterfaceState(IO);

            if (state != null)
            {
                Value = state.Value;
            }
        }

        public override FrameworkElement GetView()
        {
            return new InputWidgetView();
        }

        #region Component Selection

        public List<DiagnosticsWidgetComponent<TechIos>> Components
        {
            get
            {
                return Services.TechComponentsService.IOs.FindAll().Result.Where(x => x.Type == (int)IOType.DigitalInput).Select(x => new DiagnosticsWidgetComponent<TechIos>()
                {
                    DisplayName = x.InterfaceName,
                    Object = (TechIos)x.Code,
                }).OrderByAlphaNumeric(x => x.DisplayName).ToList();
            }
        }

        public TechIos SelectedComponent
        {
            get
            {
                return IO;
            }
            set
            {
                if (IO != value)
                {
                    IO = value;
                    InitAsync();
                }
            }
        }

        public bool EnableComponentSelection { get; set; }

        #endregion
    }
}