Commit a955265e authored by Micha's avatar Micha

cleaned up old version

parent bd4a3e4b
......@@ -9,191 +9,6 @@ using System.Net;
namespace MarmeLED
{
public class MarmeLED
{
private string host = "";
private int port = 0;
private Socket socket;
private IPEndPoint endpoint;
private int numberGlasses = 0;
private int LedPerGlass = 0;
public MarmeLED(string hostName, int portNumber, int numberOfGlasses, int numberOfLedsPerGlass)
{
host = hostName;
port = portNumber;
numberGlasses = numberOfGlasses;
LedPerGlass = numberOfLedsPerGlass;
socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
IPAddress serverAddr = IPAddress.Parse(host);
endpoint = new IPEndPoint(serverAddr, port);
}
private byte[] AddFront(byte[] arr, byte value)
{
byte[] temp = new byte[arr.Length + 1];
temp[0] = value;
Array.Copy(arr, 0, temp, 1, arr.Length);
return temp;
}
private byte[] concat(byte[] arr1, byte[] arr2)
{
byte[] temp = new byte[arr1.Length + arr2.Length];
Array.Copy(arr1, 0, temp, 0, arr1.Length);
Array.Copy(arr2, 0, temp, arr1.Length, arr2.Length);
return temp;
}
private void udpSend(byte[] data) {
socket.SendTo(data, endpoint);
}
public void flush() {
byte[] flushBytes = {255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255};
udpSend(flushBytes);
Thread.Sleep(15);
}
private void setLED(byte adr, byte red, byte green, byte blue)
{
byte[] temp = { adr, red, green, blue };
udpSend(temp);
Thread.Sleep(1);
}
public void setLamp(int index, byte[] led1, byte[] led2, byte[] led3, byte[] led4, byte[] led5, byte[] led6)
{
int baseVal = index * LedPerGlass;
led1 = AddFront(led1, (byte)(baseVal));
led2 = AddFront(led2, (byte)(baseVal+1));
led3 = AddFront(led3, (byte)(baseVal+2));
led4 = AddFront(led4, (byte)(baseVal+3));
led5 = AddFront(led5, (byte)(baseVal+4));
led6 = AddFront(led6, (byte)(baseVal+5));
byte[] temp = concat(led1, concat(led2, concat(led3, concat(led4, concat(led5, led6)))));
var lalelu = (led1.Concat<byte>(led2)).ToArray();
udpSend(temp);
Thread.Sleep(1);
}
public void switchAllOff() {
byte[] temp = {0x0, 0x0, 0x0};
for(int i = 0; i < numberGlasses; i++) {
setLamp(i, temp, temp, temp, temp, temp, temp);
}
flush();
}
public void switchAllOn(byte red, byte green, byte blue)
{
byte[] temp = { red, green, blue };
for (int i = 0; i < numberGlasses; i++)
{
setLamp(i, temp, temp, temp, temp, temp, temp);
}
flush();
}
public void switchLampOff(int index)
{
int baseIndex = index * LedPerGlass;
for (int i = 0; i < LedPerGlass; i++)
{
setLED((byte)(baseIndex + i), 0x0, 0x0, 0x0);
}
flush();
}
private void setSingleLED(int lampIndex, int ledIndex, byte red, byte green, byte blue)
{
for (int i = 0; i < LedPerGlass; i++)
{
if (i == ledIndex)
setLED((byte)(lampIndex * LedPerGlass + i), red, green, blue);
else
setLED((byte)(lampIndex * LedPerGlass + i), 0x0, 0x0, 0x0);
}
}
public void rotateRight(int lampIndex, byte red, byte green, byte blue)
{
for (int i = 0; i < LedPerGlass; i++)
{
int temp1 = (i - 1 < 0) ? (LedPerGlass - 1) : (i - 1);
int temp2 = (i + 1 > LedPerGlass-1) ? (0) : (i + 1);
setSingleLED(lampIndex, temp1, (byte)(red / 2), (byte)(green / 2), (byte)(blue / 2));
setSingleLED(lampIndex, temp2, (byte)(red / 2), (byte)(green / 2), (byte)(blue / 2));
setSingleLED(lampIndex, i, red, green, blue);
flush();
Thread.Sleep(20);
}
}
public void rotateLeft(int lampIndex, byte red, byte green, byte blue)
{
for (int i = 0; i < LedPerGlass; i++)
{
setSingleLED(lampIndex, LedPerGlass - 1 - i, red, green, blue);
flush();
}
}
// def disco(lampIndex, red, green, blue)
// baseIndex = lampIndex*6
// for i in 0..5
// setLED([baseIndex+i, red, green, blue])
// flush()
// end
// for i in 0..5
// setLED([baseIndex+i, 0, 0, 0])
// flush()
// end
// end
// def discoAllRandom()
// for i in 0..5
// for j in 0..12
// setLED([j*6 + i, rand(255), rand(255), rand(255)])
// end
// flush()
// sleep(1.0/500)
// end
// for i in 0..5
// for j in 0..12
// setLED([j*6 + i, 0, 0, 0])
// end
// flush()
// sleep(1.0/500)
// end
// end
// def rotateRight(red, green, blue)
// for i in 0..5
// for j in 0..12
// setSingleLED(j, i, red, green, blue)
// end
// flush()
// end
// end
// def rotateAllLeft(red, green, blue)
// for i in 0..5
// for j in 0..12
// setSingleLED(j, 5-i, red, green, blue)
// end
// flush()
// end
// end
}
public class led
{
public byte adress { get; set; }
......@@ -335,7 +150,7 @@ namespace MarmeLED
sendBuffer[i * 4 + 2] = data[i].green;
sendBuffer[i * 4 + 3] = data[i].blue;
}
// only send 24 bytes at once (for testing purposes only)
// only send 24 bytes at once
int bytesSent = 0;
int maxBytes = 24;
while (bytesSent < sendBuffer.Length)
......@@ -376,52 +191,5 @@ namespace MarmeLED
}
update();
}
//public void rotateRight(int lampIndex, byte red, byte green, byte blue)
//{
// int Neighbour1 = 0;
// int Neighbour2 = 0;
// int Neighbour3 = 0;
// int Neighbour4 = 0;
// int Neighbour5 = 0;
// for (int k = 0; k < LedPerGlass; k++)
// {
// int i = k % LedPerGlass;
// Neighbour1 = (i - 1 >= 0) ? (i - 1) : LedPerGlass - 1;
// Neighbour2 = (i - 2 >= 0) ? (i - 2) : LedPerGlass - 2;
// Neighbour3 = (i - 3 >= 0) ? (i - 3) : LedPerGlass - 3;
// setLED(lampIndex, Neighbour1, (byte)((int)(red / 2)), (byte)((int)(green / 2)), (byte)((int)(blue / 2)));
// setLED(lampIndex, Neighbour2, (byte)((int)(red / 3)), (byte)((int)(green / 3)), (byte)((int)(blue / 3)));
// setLED(lampIndex, Neighbour3, (byte)((int)(red / 4)), (byte)((int)(green / 4)), (byte)((int)(blue / 4)));
// setLED(lampIndex, Neighbour4, (byte)((int)(red / 5)), (byte)((int)(green / 5)), (byte)((int)(blue / 5)));
// setLED(lampIndex, Neighbour5, 0, 0, 0);
// //setLED(lampIndex, Neighbour6, (byte)((int)(red / 7)), (byte)((int)(green / 7)), (byte)((int)(blue / 7)));
// setLED(lampIndex, i, red, green, blue);
// update();
// Thread.Sleep(60);
// //switchAllOff();
// }
//}
//public void test()
//{
// int lastGlass = 1000, lastLed = 1000;
// for (int i = 0; i < numberGlasses; i++)
// {
// for (int j = 0; j < LedPerGlass; j++)
// {
// setLED(i, j, 255, 255, 255);
// if (lastLed < 1000)
// {
// setLED(lastGlass, lastLed, 0, 0, 0);
// }
// lastGlass = i;
// lastLed = j;
// update();
// Thread.Sleep(50);
// }
// }
//}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment