Commit bd4a3e4b authored by Micha's avatar Micha

initial commit

parent 822ead3b
This diff is collapsed.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{04C6ABC2-C041-46DC-9CDE-3FE34E21BFCF}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MarmeLED</RootNamespace>
<AssemblyName>MarmeLED</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="animation.cs" />
<Compile Include="MarmeLED.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("MarmeLED")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Fraunhofer Gesellschaft")]
[assembly: AssemblyProduct("MarmeLED")]
[assembly: AssemblyCopyright("Copyright © Fraunhofer Gesellschaft 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("7bfede52-8176-4561-93ad-c38a40823ca8")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MarmeLED
{
public abstract class animation
{
//public int numberIterations { get; set; }
public MarmeLED_v2 marmeLED { get; set; }
public abstract void Start();
public abstract void Run();
public abstract void Stop();
public int glassesAmount { get; set; }
public int ledsAmount { get; set; }
public void initMarmeLED(MarmeLED_v2 marmeled, int numberOfGlasses, int ledsPerGlass)
{
marmeLED = marmeled;
glassesAmount = numberOfGlasses;
ledsAmount = ledsPerGlass;
}
}
public class waveLight : animation
{
private List<int> values_red;
private List<int> values_green;
private List<int> values_blue;
private byte base_red, base_green, base_blue;
public waveLight(byte red, byte green, byte blue)
//: base(marmeLed)
{
base_red = red;
base_blue = blue;
base_green = green;
values_red = new List<int>();
values_blue = new List<int>();
values_green = new List<int>();
}
public override void Start()
{
for (int i = 0; i < glassesAmount; i++)
{
//values.Add((int)(255 * Math.Sin(Math.PI / glassesAmount * i)));
// scale given color
values_red.Add((int)(base_red * Math.Sin(Math.PI / glassesAmount * i)));
values_green.Add((int)(base_green * Math.Sin(Math.PI / glassesAmount * i)));
values_blue.Add((int)(base_blue * Math.Sin(Math.PI / glassesAmount * i)));
marmeLED.switchAllOff();
}
}
public override void Run()
{
for (int i = 0; i < glassesAmount; i++)
{
marmeLED.setGlass(i, (byte)values_red[i], (byte)values_green[i], (byte)values_blue[i]);
}
marmeLED.update();
rollOne(ref values_red);
rollOne(ref values_green);
rollOne(ref values_blue);
}
public override void Stop()
{
marmeLED.switchAllOff();
}
private void rollOne(ref List<int> vals)
{
// get last element index
int lastIndex = vals.Count - 1;
// get last element
int last = vals[lastIndex];
// remove last element
vals.RemoveAt(lastIndex);
// add last element to front
vals.Insert(0, last);
}
}
public class rotate : animation
{
private List<int> values_red;
private List<int> values_green;
private List<int> values_blue;
private byte base_red, base_green, base_blue;
public rotate(byte red, byte green, byte blue)
//: base(marmeLed)
{
base_red = red;
base_blue = blue;
base_green = green;
values_red = new List<int>();
values_blue = new List<int>();
values_green = new List<int>();
}
public override void Start()
{
for (int i = 0; i < ledsAmount; i++)
{
//values.Add((int)(255 * Math.Sin(Math.PI / glassesAmount * i)));
// scale given color
values_red.Add((int)(base_red * Math.Sin(Math.PI / ledsAmount * i)));
values_green.Add((int)(base_green * Math.Sin(Math.PI / ledsAmount * i)));
values_blue.Add((int)(base_blue * Math.Sin(Math.PI / ledsAmount * i)));
marmeLED.switchAllOff();
}
}
public override void Run()
{
for (int i = 0; i < ledsAmount; i++)
{
for (int j = 0; j < glassesAmount; j++)
{
marmeLED.setLED(j, i, (byte)values_red[i], (byte)values_green[i], (byte)values_blue[i]);
}
}
marmeLED.update();
rollOne(ref values_red);
rollOne(ref values_green);
rollOne(ref values_blue);
}
public override void Stop()
{
marmeLED.switchAllOff();
}
private void rollOne(ref List<int> vals)
{
// get last element index
int lastIndex = vals.Count - 1;
// get last element
int last = vals[lastIndex];
// remove last element
vals.RemoveAt(lastIndex);
// add last element to front
vals.Insert(0, last);
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{E45020EB-A814-46E7-93D4-8318A63455CA}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MarmeLEDRevision</RootNamespace>
<AssemblyName>MarmeLEDRevision</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MarmeLED\MarmeLED.csproj">
<Project>{04c6abc2-c041-46dc-9cde-3fe34e21bfcf}</Project>
<Name>MarmeLED</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MarmeLED;
using System.Threading;
/*
* Hi out there,
* this software is an example on how to use my MarmeLED_v2 library. As you will see, the whole library design has a huge potential for getting better,
* but it doesn't matter, because it is a work in progress state and if I have some spare time, I will improve it, including fundamental design changes.
* On the other hand, all of this is completely free software and you are not just allowed but encouraged to improve this mess!
*/
namespace MarmeLEDRevision
{
class Program
{
static void Main(string[] args)
{
MarmeLED.MarmeLED_v2 sender = new MarmeLED.MarmeLED_v2("127.0.0.1", 8888, 13, 6);
rotate ani = new rotate(125, 200, 250);
sender.setAnimation(ani, 1000, 70);
// you can use any animation derived from animation class. There are a few of them built-in but you can define them by yourself.
// i will write a how to with an example
// minimum thing an animation needs is the MarmeLED_v2 instance to work on, because it is neccessary to set leds directly in this class
// everything else is optional
//waveLight builtinAnimation = new waveLight(sender, 13, 123, 240, 12);
// to use an animation, just hand it over to the MarmeLED_v2's setAnimation method. Additional parameters are numberOfIterations (how often is the
// animation main loop played) and speed in percent, that means how long are the delays between two repetitions
//sender.setAnimation(builtinAnimation, 40, 100);
//Thread.Sleep(100);
// start custom animation, just have a look below
//myAnimation customAnimation = new myAnimation(sender, 13, 6, 125, 200, 250);
//sender.setAnimation(customAnimation, 2, 50);
Console.ReadLine();
}
// this is how to build a custom animation. Just pick a fancy name and make a class out of it, derived from class animation
public class myAnimation : animation
{
private int ledAmount = 0;
private int glassAmount = 0;
private byte _red, _green, _blue;
public myAnimation(int red, int green, int blue)
{
_red = (byte)red;
_green = (byte)green;
_blue = (byte)blue;
}
// then you need to override the methods Start(), Run() and Stop().
// this idea on controlling animations was originally created by Agrigor from Hacksaar in his JAMpyLED controller. All cheers go to him.
public override void Start()
{
marmeLED.switchAllOff(); // initial condition
}
public override void Run()
{
const uint unbelievableBigNumber = 0xBADEAFFE;
uint lastGlass = unbelievableBigNumber, lastLed = unbelievableBigNumber;
for (uint i = 0; i < glassAmount; i++)
{
for(uint j = 0; j < ledAmount; j++) {
marmeLED.setLED((int)i, (int)j, _red, _green, _blue);
if (lastLed < 1000)
{
marmeLED.setLED((int)lastGlass, (int)lastLed, 0, 0, 0);
}
lastGlass = i;
lastLed = j;
marmeLED.update();
}
}
}
public override void Stop()
{
marmeLED.switchAllOff(); // stop conditions
}
}
}
}
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("MarmeLEDRevision")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Fraunhofer Gesellschaft")]
[assembly: AssemblyProduct("MarmeLEDRevision")]
[assembly: AssemblyCopyright("Copyright © Fraunhofer Gesellschaft 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("4f97d6e8-a135-4386-ad89-058d47ac3fb6")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
\ No newline at end of file
This diff is collapsed.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using System.Windows.Forms;
using MarmeLED.UserControls;
namespace MarmeLEDSimu
{
public partial class Form1 : Form
{
private List<light> update = new List<light>();
private int numberOfGlasses = 13;
private int ledsPerGlass = 6;
private bool receiverRunning = false;
byte[] data;
IPEndPoint sender;
UdpClient udpSocket;
Thread listener;
public Form1()
{
InitializeComponent();
data = new byte[1024];
IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 8888);
sender = new IPEndPoint(IPAddress.Any, 8888);
udpSocket = new UdpClient(ipep);
receiverRunning = true;
listener = new Thread(new ThreadStart(listenAndParse));
listener.Start();
}
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < numberOfGlasses * ledsPerGlass; i++)
{
ChangeControlColor(Color.FromArgb(0, 0, 0), (MarmeLED.UserControls.Buttons.RoundButton)this.pnGlasses.Controls["bt_" + i.ToString()]);
}
}
private void listenAndParse()
{
int bytesPerPacket = 4;
while (receiverRunning)
{
try
{
data = udpSocket.Receive(ref sender);
if (data.Length > 0)
{
int dummy = 0;
for (int i = 0; i < data.Length; i++)
{
dummy += data[i];
}
if (dummy / 255 == 24)
{
Console.WriteLine("Flush");
flush();
}
else
{
Console.WriteLine("Data block, parse!");
int numOfBlocks = data.Length / bytesPerPacket;
for (int i = 0; i < numOfBlocks; i++)
{
light temp = new light();
temp.adr = data[bytesPerPacket * i];
temp.red = data[bytesPerPacket * i + 1];
temp.green = data[bytesPerPacket * i + 2];
temp.blue = data[bytesPerPacket * i + 3];
update.Add(temp);
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
delegate void SetColorCallBack(Color c, MarmeLED.UserControls.Buttons.RoundButton b);
public static void ChangeControlColor(Color c, MarmeLED.UserControls.Buttons.RoundButton b)
{
if (b.InvokeRequired)
{
SetColorCallBack d = new SetColorCallBack(ChangeControlColor);
b.Invoke(d, new object[] { c, b });
}
else
{
b.BackColor = c;
b.BringToFront();
b.Refresh();
}
}
private void flush()
{
// paint
for (int i = 0; i < update.Count; i++)
{
ChangeControlColor(Color.FromArgb(update[i].red,update[i].green,update[i].blue), (MarmeLED.UserControls.Buttons.RoundButton)this.pnGlasses.Controls["bt_" + update[i].adr.ToString()]);
}
update.Clear();
}
private void btTest_Click(object sender, EventArgs e)
{
for (int i = 0; i < numberOfGlasses; i++)
{
for (int j = 0; j < ledsPerGlass; j++)
{
light temp = new light();
light temp2 = new light();
temp.adr = i * ledsPerGlass + j;
temp.red = 255;
temp.green = 0;
temp.blue = 0;
update.Add(temp);
if (temp.adr - 1 >= 0)
{
temp2.adr = temp.adr - 1;
temp2.red = 0;
temp2.green = 0;
temp2.blue = 0;
update.Add(temp2);
}
flush();
Thread.Sleep(500);
}
}
//light temp = new light();
//light temp2 = new light();
//for (int i = 0; i < numberOfGlasses * ledsPerGlass; i++)
//{
// temp.adr = i;
// temp.red = 255;
// temp.green = 0;
// temp.blue = 0;
// update.Add(temp);
// if (i - 1 >= 0)
// {
// temp2.adr = i - 1;
// temp2.red = 0;
// temp2.green = 0;
// temp2.blue = 0;
// update.Add(temp2);
// }
// flush();
// Thread.Sleep(500);
//}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
receiverRunning = false;
udpSocket.Close();
}
}
public class light
{
public int red { get; set; }
public int green { get; set; }
public int blue { get; set; }
public int adr { get; set; }
public light()
{
red = 0;
green = 0;
blue = 0;
adr = 0;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example: