-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClass1.cs
More file actions
173 lines (146 loc) · 4.75 KB
/
Class1.cs
File metadata and controls
173 lines (146 loc) · 4.75 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using SimpleLed;
namespace Source.ImageScroller
{
public class ImageScroller : ISimpleLed
{
private int scrollPos = 0;
private LEDColor[,] imageAsGrid;
private ControlDevice dev;
public void Dispose()
{
}
public void Configure(DriverDetails driverDetails)
{
}
public List<ControlDevice> GetDevices()
{
dev = new ControlDevice
{
LEDs = new ControlDevice.LedUnit[23 * 6],
DeviceType = DeviceTypes.Effect,
Driver = this,
GridHeight = 6,
GridWidth = 23,
Has2DSupport = true,
Name = "Scroll Source"
};
int ct = 0;
for (int y = 0; y < 6; y++)
{
for (int x = 0; x < 23; x++)
{
var led= new ControlDevice.LedUnit
{
Color = new LEDColor(0, 0, 0),
Data = new ControlDevice.PositionalLEDData
{
LEDNumber = ct,
X=x,
Y=y
},
LEDName = "POS " + ct
};
dev.LEDs[ct] = led;
ct++;
}
}
return new List<ControlDevice>
{
dev
};
}
public void Push(ControlDevice controlDevice)
{
}
private int scrollPosOffset = 0;
public void Pull(ControlDevice controlDevice)
{
if (imageAsGrid == null)
{
imageAsGrid = GetImage("rainbowtext");
scrollPos = 26;
}
for (int y = 0; y < 6; y++)
{
for (int x = 0; x < imageAsGrid.GetLength(0); x++)
{
if (x + scrollPos < 23 && x + scrollPos >= 0)
{
dev.SetGridLED(x+scrollPos, y,imageAsGrid[x,y]);
}
}
}
scrollPosOffset++;
// if (scrollPosOffset > 10)
{
scrollPosOffset = 0;
scrollPos--;
if (scrollPos < -imageAsGrid.GetLength(0))
{
scrollPos = 26;
}
}
}
private void Clear()
{
for (int y = 0; y < 6; y++)
{
for (int x = 0; x < 23; x++)
{
dev.SetGridLED(x,y,new LEDColor(0,0,0));
}
}
}
public DriverProperties GetProperties()
{
return new DriverProperties
{
SupportsPull = true,
SupportsPush = false,
IsSource = false,
Id = Guid.Parse("a9440d02-bba3-4e35-a9a3-28194acc0e2d"),
Author = "mad ninja",
Blurb = "Scroll images across your 2D devices",
CurrentVersion = new ReleaseNumber(1, 0, 0, 1),
GitHubLink = "https://github.com/SimpleLed/Source.ImageScroller",
IsPublicRelease = true,
SupportsCustomConfig = false
};
}
public T GetConfig<T>() where T : SLSConfigData
{
return null;
}
public void PutConfig<T>(T config) where T : SLSConfigData
{
}
public string Name()
{
return "Image Scroller";
}
private LEDColor[,] GetImage(string path)
{
Bitmap image = Assembly.GetExecutingAssembly().GetEmbeddedImage("Source.ImageScroller." + path + ".png");
float ratio = image.Height / 6f;
int width = (int) (image.Width * ratio);
Bitmap bm2 = new Bitmap(image, new Size(width, 6));
LEDColor[,] result = new LEDColor[width,6];
for (int y = 0; y < 6; y++)
{
for (var x = 0; x < width; x++)
{
var cl = bm2.GetPixel(x, y);
result[x, y] = new LEDColor(cl.R,cl.G,cl.B);
}
}
return result;
}
}
}