-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.xaml.cs
182 lines (167 loc) · 5.89 KB
/
MainWindow.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Text.RegularExpressions;
using System.Drawing;
namespace NanoPanel
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
Serial serial;
AnalogPinState analogPinState;
DigitalPinState digitalPinState;
ImageSource redIcon;
ImageSource greenIcon;
public MainWindow()
{
InitializeComponent();
redIcon = Icon;
greenIcon = BitmapFrame.Create(new Uri("pack://application:,,,/icons/green.ico", UriKind.RelativeOrAbsolute));
serial = new();
analogPinState = new(serial);
digitalPinState = new(serial);
serial.Open();
analogPinState.AnalogPinChanged += AnalogPinState_AnalogPinChanged;
digitalPinState.DigitalPinChanged += DigitalPinState_DigitalPinChanged;
serial.SerialOpenChanged += Serial_SerialOpenChanged;
WebSocketService webSocketService = new()
{
AnalogPinState = analogPinState,
DigitalPinState = digitalPinState
};
}
private void Serial_SerialOpenChanged(object sender, SerialOpenChangedArgs e)
{
Dispatcher.BeginInvoke(new Action(() =>
{
if (e.IsSerialOpen)
{
this.Icon = greenIcon;
TaskbarIcon.IconSource = greenIcon;
}
else
{
this.Icon = redIcon;
TaskbarIcon.IconSource = redIcon;
}
}));
}
private void setDigitalPinControl(Ellipse e, bool pinState)
{
Dispatcher.BeginInvoke(new Action(() =>
{
if (pinState)
{
e.Fill = System.Windows.Media.Brushes.LimeGreen;
}
else
{
e.Fill = System.Windows.Media.Brushes.Tomato;
}
}));
}
private void DigitalPinState_DigitalPinChanged(object sender, DigitalPinChangedArgs e)
{
switch (e.pin)
{
case 2: D2_status.State = e.next; break;
case 3: D3_status.State = e.next; break;
case 4: D4_status.State = e.next; break;
case 5: D5_status.State = e.next; break;
case 6: D6_status.State = e.next; break;
case 7: D7_status.State = e.next; break;
case 8: D8_status.State = e.next; break;
case 9: D9_status.State = e.next; break;
case 10: D10_status.State = e.next; break;
case 11: D11_status.State = e.next; break;
case 12: D12_status.State = e.next; break;
case 13: D13_status.State = e.next; break;
}
}
private void AnalogPinState_AnalogPinChanged(object sender, AnalogPinChangedArgs e)
{
switch (e.pin)
{
case 0:
Dispatcher.BeginInvoke(new Action(() =>
{
A0_bar.Value = e.next;
A0_number.Text = e.next.ToString();
}));
break;
case 1:
Dispatcher.BeginInvoke(new Action(() =>
{
A1_bar.Value = e.next;
A1_number.Text = e.next.ToString();
}));
break;
case 2:
Dispatcher.BeginInvoke(new Action(() =>
{
A2_bar.Value = e.next;
A2_number.Text = e.next.ToString();
}));
break;
case 3:
Dispatcher.BeginInvoke(new Action(() =>
{
A3_bar.Value = e.next;
A3_number.Text = e.next.ToString();
}));
break;
case 4:
Dispatcher.BeginInvoke(new Action(() =>
{
A4_bar.Value = e.next;
A4_number.Text = e.next.ToString();
}));
break;
case 5:
Dispatcher.BeginInvoke(new Action(() =>
{
A5_bar.Value = e.next;
A5_number.Text = e.next.ToString();
}));
break;
case 6:
Dispatcher.BeginInvoke(new Action(() =>
{
A6_bar.Value = e.next;
A6_number.Text = e.next.ToString();
}));
break;
case 7:
Dispatcher.BeginInvoke(new Action(() =>
{
A7_bar.Value = e.next;
A7_number.Text = e.next.ToString();
}));
break;
}
}
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
}
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
//clean up notifyicon (would otherwise stay open until application finishes)
TaskbarIcon.Dispose();
base.OnClosing(e);
}
}
}