-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUpdateDisplayUnit.cs
More file actions
151 lines (134 loc) · 5.22 KB
/
UpdateDisplayUnit.cs
File metadata and controls
151 lines (134 loc) · 5.22 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
// Visual Pinball Engine
// Copyright (C) 2022 freezy and VPE Team
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
using System;
using System.Text;
using Unity.VisualScripting;
namespace VisualPinball.Unity.VisualScripting
{
[UnitTitle("Update Display")]
[UnitSurtitle("Gamelogic Engine")]
[UnitCategory("Pinball")]
public class UpdateDisplayUnit : GleUnit
{
[Serialize, Inspectable, UnitHeaderInspectable("ID")]
public DisplayDefinition Display { get; private set; }
[DoNotSerialize]
[PortLabelHidden]
public ControlInput InputTrigger;
[DoNotSerialize]
[PortLabelHidden]
public ControlOutput OutputTrigger;
[DoNotSerialize]
[PortLabel("Numeric")]
public ValueInput NumericInput { get; private set; }
[DoNotSerialize]
[PortLabel("Text")]
public ValueInput TextInput { get; private set; }
[DoNotSerialize]
[PortLabel("Segment Data")]
public ValueInput SegmentInput { get; private set; }
[DoNotSerialize]
[PortLabel("DMD (2-bit)")]
public ValueInput Dmd2Input { get; private set; }
[DoNotSerialize]
[PortLabel("DMD (4-bit)")]
public ValueInput Dmd4Input { get; private set; }
[DoNotSerialize]
[PortLabel("DMD (8-bit)")]
public ValueInput Dmd8Input { get; private set; }
[DoNotSerialize]
[PortLabel("DMD (RGB24)")]
public ValueInput Dmd24Input { get; private set; }
protected override void Definition()
{
InputTrigger = ControlInput(nameof(InputTrigger), Process);
OutputTrigger = ControlOutput(nameof(OutputTrigger));
if (Display != null) {
if (Display.Supports(DisplayFrameFormat.Numeric)) {
NumericInput = ValueInput<float>(nameof(NumericInput));
}
if (Display.Supports(DisplayFrameFormat.AlphaNumeric)) {
TextInput = ValueInput<string>(nameof(TextInput));
}
if (Display.Supports(DisplayFrameFormat.Segment)) {
SegmentInput = ValueInput<byte[]>(nameof(SegmentInput));
}
if (Display.Supports(DisplayFrameFormat.Dmd2)) {
Dmd2Input = ValueInput<byte[]>(nameof(Dmd2Input));
}
if (Display.Supports(DisplayFrameFormat.Dmd4)) {
Dmd4Input = ValueInput<byte[]>(nameof(Dmd4Input));
}
if (Display.Supports(DisplayFrameFormat.Dmd8)) {
Dmd8Input = ValueInput<byte[]>(nameof(Dmd8Input));
}
if (Display.Supports(DisplayFrameFormat.Dmd24)) {
Dmd24Input = ValueInput<byte[]>(nameof(Dmd24Input));
}
}
Succession(InputTrigger, OutputTrigger);
}
private ControlOutput Process(Flow flow)
{
if (!AssertVsGle(flow)) {
throw new InvalidOperationException("Cannot retrieve GLE from unit.");
}
if (Display != null) {
if (Display.Supports(DisplayFrameFormat.Numeric) && NumericInput.hasValidConnection) {
var numValue = flow.GetValue<float>(NumericInput);
VsGle.DisplayUpdateFrame(new DisplayFrameData(Display.Id, DisplayFrameFormat.Numeric, BitConverter.GetBytes(numValue)));
}
if (Display.Supports(DisplayFrameFormat.AlphaNumeric) && flow.IsLocal(TextInput)) {
var strValue = flow.GetValue<string>(TextInput);
if (!string.IsNullOrEmpty(strValue)) {
VsGle.DisplayUpdateFrame(new DisplayFrameData(Display.Id, DisplayFrameFormat.AlphaNumeric, Encoding.UTF8.GetBytes(strValue)));
}
}
if (Display.Supports(DisplayFrameFormat.Segment) && SegmentInput.hasValidConnection) {
var byteValue = flow.GetValue<byte[]>(SegmentInput);
if (byteValue is { Length: > 0 }) {
VsGle.DisplayUpdateFrame(new DisplayFrameData(Display.Id, DisplayFrameFormat.Segment, byteValue));
}
}
if (Display.Supports(DisplayFrameFormat.Dmd2) && Dmd2Input.hasValidConnection) {
var byteValue = flow.GetValue<byte[]>(Dmd2Input);
if (byteValue is { Length: > 0 }) {
VsGle.DisplayUpdateFrame(new DisplayFrameData(Display.Id, DisplayFrameFormat.Dmd2, byteValue));
}
}
if (Display.Supports(DisplayFrameFormat.Dmd4) && Dmd4Input.hasValidConnection) {
var byteValue = flow.GetValue<byte[]>(Dmd4Input);
if (byteValue is { Length: > 0 }) {
VsGle.DisplayUpdateFrame(new DisplayFrameData(Display.Id, DisplayFrameFormat.Dmd4, byteValue));
}
}
if (Display.Supports(DisplayFrameFormat.Dmd8) && Dmd8Input.hasValidConnection) {
var byteValue = flow.GetValue<byte[]>(Dmd8Input);
if (byteValue is { Length: > 0 }) {
VsGle.DisplayUpdateFrame(new DisplayFrameData(Display.Id, DisplayFrameFormat.Dmd8, byteValue));
}
}
if (Display.Supports(DisplayFrameFormat.Dmd24) && Dmd24Input.hasValidConnection) {
var byteValue = flow.GetValue<byte[]>(Dmd24Input);
if (byteValue is { Length: > 0 }) {
VsGle.DisplayUpdateFrame(new DisplayFrameData(Display.Id, DisplayFrameFormat.Dmd24, byteValue));
}
}
}
return OutputTrigger;
}
}
}