forked from PeterWaher/IoTGateway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainPage.xaml.cs
145 lines (121 loc) · 3.55 KB
/
MainPage.xaml.cs
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Devices.Gpio;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Navigation;
using Waher.Events;
using Waher.Mock;
namespace Waher.Service.GPIO
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
private static ListViewSniffer sniffer = null;
private static ListViewEventSink eventSink = null;
private static MainPage instance = null;
public MainPage()
{
this.InitializeComponent();
if (sniffer == null)
sniffer = new ListViewSniffer(this.SnifferListView);
if (eventSink == null)
{
eventSink = new ListViewEventSink("List View Event Sink.", this.EventsListView);
Log.Register(eventSink);
}
if (instance == null)
instance = this;
App.OwnershipChanged += App_OwnershipChanged;
}
private void App_OwnershipChanged(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(App.OwnerJid))
{
this.OwnerLabel.Visibility = Visibility.Collapsed;
this.Owner.Visibility = Visibility.Collapsed;
this.QrCodeLabel.Visibility = Visibility.Visible;
this.QrCode.Source = new BitmapImage(new Uri(App.QrCodeUrl));
this.QrCode.Visibility = Visibility.Visible;
}
else
{
this.OwnerLabel.Visibility = Visibility.Visible;
this.Owner.Text = App.OwnerJid;
this.Owner.Visibility = Visibility.Visible;
this.QrCodeLabel.Visibility = Visibility.Collapsed;
this.QrCode.Visibility = Visibility.Collapsed;
}
}
private void Page_Unloaded(object sender, RoutedEventArgs e)
{
if (sniffer != null && sniffer.ListView == this.SnifferListView)
sniffer = null;
if (eventSink != null && eventSink.ListView == this.EventsListView)
{
Log.Unregister(eventSink);
eventSink.Dispose();
eventSink = null;
}
if (instance == this)
instance = null;
}
public static ListViewSniffer Sniffer
{
get { return sniffer; }
}
public static MainPage Instance
{
get { return instance; }
}
private int currentRow = 0;
public KeyValuePair<TextBlock, TextBlock> AddPin(string PinName, Enum Drive, string Value)
{
TextBlock Cell1 = new TextBlock()
{
TextWrapping = TextWrapping.Wrap,
Margin = new Thickness(0, 0, 0, 5)
};
Cell1.Text = PinName;
Grid.SetColumn(Cell1, 0);
Grid.SetRow(Cell1, ++this.currentRow);
this.GpioGrid.RowDefinitions.Add(new RowDefinition());
this.GpioGrid.Children.Add(Cell1);
TextBlock Cell2 = new TextBlock()
{
TextWrapping = TextWrapping.Wrap,
Margin = new Thickness(0, 0, 0, 5)
};
Cell2.Text = Drive.ToString();
Grid.SetColumn(Cell2, 1);
Grid.SetRow(Cell2, this.currentRow);
this.GpioGrid.Children.Add(Cell2);
TextBlock Cell3 = new TextBlock()
{
TextWrapping = TextWrapping.Wrap,
Margin = new Thickness(0, 0, 0, 5)
};
Cell3.Text = Value;
Grid.SetColumn(Cell3, 2);
Grid.SetRow(Cell3, this.currentRow);
this.GpioGrid.Children.Add(Cell3);
return new KeyValuePair<TextBlock, TextBlock>(Cell2, Cell3);
}
public async void UpdateValue(TextBlock Block, string Value)
{
await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => Block.Text = Value);
}
}
}