-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMadLedConfigPage.xaml.cs
More file actions
158 lines (132 loc) · 4.67 KB
/
MadLedConfigPage.xaml.cs
File metadata and controls
158 lines (132 loc) · 4.67 KB
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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
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 SimpleLed;
namespace Driver.MadLed
{
/// <summary>
/// Interaction logic for MadLedConfigPage.xaml
/// </summary>
public partial class MadLedConfigPage : UserControl
{
private MadLed MadLed;
public MadLedConfigPage(MadLed madled)
{
MadLed = madled;
InitializeComponent();
DevicesDropDown.Items.Clear();
foreach (string connectedMadLedUnit in MadLed.ConnectedMadLedUnits)
{
DevicesDropDown.Items.Add(connectedMadLedUnit);
}
}
private MadLed.MadLedDevice madLedDevice = null;
private void DevicesDropDown_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
string device = DevicesDropDown.SelectedItem as string;
madLedDevice = MadLed.MadLedDevices.First(x => x.Serial == device);
PinsView.Items.Clear();
var sp = madLedDevice.SupportedPins.Select((value, i) => (value, i));
foreach (var (t, i) in sp)
{
PinViewModel mdl = null;
var pp = madLedDevice.ControlDevices.FirstOrDefault(x => x.Pin == t);
if (pp == null)
{
mdl = new PinViewModel
{
Pin = t,
DeviceClass = -1,
LedCount = 0,
Name = ""
};
}
else
{
mdl = new PinViewModel
{
Pin = t,
DeviceClass = Array.IndexOf(MadLed.deviceTypes, pp.DeviceType),
LedCount = pp.LEDs.Length,
Name = pp.Name
};
}
PinsView.Items.Add(mdl);
}
}
public class PinViewModel
{
public int Pin { get; set; }
public string Name { get; set; }
public int DeviceClass { get; set; }
public int LedCount { get; set; }
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Button button = sender as Button;
PinViewModel mdl = button.DataContext as PinViewModel;
SetUp(mdl, false);
}
private void SetUp(PinViewModel mdl, bool isPermo)
{
MadLed.MadLedDevice.PinConfig pc = new MadLed.MadLedDevice.PinConfig
{
Name = mdl.Name+"\r",
DeviceClass = mdl.DeviceClass,
Pin = mdl.Pin,
LedCount = mdl.LedCount
};
var pcfg = madLedDevice.SetConfigCmd(mdl.Pin, pc);
if (isPermo)
{
pcfg[1] = 2;
}
//madLedDevice.stream.Write(pcfg,0,pcfg.Length);
madLedDevice.SendPacket(madLedDevice.stream,pcfg);
//madLedDevice.ReadReturnReport(madLedDevice.stream);
if (mdl.LedCount > 0 && pc.DeviceClass > -1)
{
MadLed.MadLedControlDevice mlcd = new MadLed.MadLedControlDevice
{
DeviceType = MadLed.deviceTypes[pc.DeviceClass],
Name = pc.Name,
MadLedDevice = madLedDevice,
LEDs = new ControlDevice.LedUnit[pc.LedCount],
Driver = MadLed,
Pin = mdl.Pin
};
for (int p = 0; p < pc.LedCount; p++)
{
mlcd.LEDs[p] = new ControlDevice.LedUnit
{
Data = new ControlDevice.LEDData
{
LEDNumber = p
},
LEDName = "LED " + (p + 1),
Color = new LEDColor(0, 0, 0)
};
}
MadLed.InvokeAdded(mlcd);
}
//DeviceAdded?.Invoke(this, new Events.DeviceChangeEventArgs(mlcd));
}
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
Button button = sender as Button;
PinViewModel mdl = button.DataContext as PinViewModel;
SetUp(mdl, true);
}
}
}