Browse Source

Initial Commit of LED Changer Source

master
Teknikode 3 years ago
parent
commit
adc6cbe24f

+ 25
- 0
LED Backlight Changer.sln View File

@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.20827.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LED Backlight Changer", "LED Backlight Changer\LED Backlight Changer.csproj", "{22DD6C60-D2A8-4386-9555-54775B64DAA9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{22DD6C60-D2A8-4386-9555-54775B64DAA9}.Debug|x86.ActiveCfg = Debug|x86
{22DD6C60-D2A8-4386-9555-54775B64DAA9}.Debug|x86.Build.0 = Debug|x86
{22DD6C60-D2A8-4386-9555-54775B64DAA9}.Release|x86.ActiveCfg = Release|x86
{22DD6C60-D2A8-4386-9555-54775B64DAA9}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
EndGlobalSection
EndGlobal

+ 164
- 0
LED Backlight Changer/LED Backlight Changer.csproj View File

@@ -0,0 +1,164 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{22DD6C60-D2A8-4386-9555-54775B64DAA9}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ledbacklightchanger</RootNamespace>
<AssemblyName>LED Backlight Changer</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>A:\My Documents\Coding\LED Backlight Changer\Install\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<UpdateUrl>http://www.codefiendz.co.cc/led_backlight_changer/</UpdateUrl>
<TargetCulture>en</TargetCulture>
<ProductName>LED Backlight Changer</ProductName>
<PublisherName>CodeFiendz</PublisherName>
<SuiteName>LED Backlight Changer</SuiteName>
<WebPage>publish.htm</WebPage>
<ApplicationRevision>3</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<ManifestCertificateThumbprint>FFA91FF7B2FBC7716B2F9EC83A92F1B1D0181551</ManifestCertificateThumbprint>
</PropertyGroup>
<PropertyGroup>
<ManifestKeyFile>WindowsFormsApplication1_TemporaryKey.pfx</ManifestKeyFile>
</PropertyGroup>
<PropertyGroup>
<GenerateManifests>true</GenerateManifests>
</PropertyGroup>
<PropertyGroup>
<TargetZone>LocalIntranet</TargetZone>
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>Properties\app.manifest</ApplicationManifest>
</PropertyGroup>
<PropertyGroup>
<SignManifests>true</SignManifests>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>Lightbulb.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="SlimDX, Version=4.0.13.43, Culture=neutral, PublicKeyToken=b1b0c32fd1ffe4f9, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
<HintPath>Resources\SlimDX.dll</HintPath>
</Reference>
<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.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="backlight_changer.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="backlight_changer.Designer.cs">
<DependentUpon>backlight_changer.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="backlight_changer.resx">
<DependentUpon>backlight_changer.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="app.config" />
<None Include="Properties\app.manifest" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<None Include="WindowsFormsApplication1_TemporaryKey.pfx" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.0,Profile=Client">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4 Client Profile %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Content Include="Lightbulb.ico" />
</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>

BIN
LED Backlight Changer/Lightbulb.ico View File


+ 21
- 0
LED Backlight Changer/Program.cs View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Backlight_Changer());
}
}
}

+ 36
- 0
LED Backlight Changer/Properties/AssemblyInfo.cs View File

@@ -0,0 +1,36 @@
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("LED Backlight Changer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("CodeFiendz")]
[assembly: AssemblyProduct("LED Backlight Changer")]
[assembly: AssemblyCopyright("Copyright © CodeFiendz 2011")]
[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("edea1c66-2b88-457e-a9b7-25589abe8448")]

// 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")]

+ 63
- 0
LED Backlight Changer/Properties/Resources.Designer.cs View File

@@ -0,0 +1,63 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.237
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace ledbacklightchanger.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ledbacklightchanger.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}

+ 117
- 0
LED Backlight Changer/Properties/Resources.resx View File

@@ -0,0 +1,117 @@
<?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:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

+ 26
- 0
LED Backlight Changer/Properties/Settings.Designer.cs View File

@@ -0,0 +1,26 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.237
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace ledbacklightchanger.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
}
}

+ 7
- 0
LED Backlight Changer/Properties/Settings.settings View File

@@ -0,0 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>

+ 47
- 0
LED Backlight Changer/Properties/app.manifest View File

@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC Manifest Options
If you want to change the Windows User Account Control level replace the
requestedExecutionLevel node with one of the following.

<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />

Specifying requestedExecutionLevel node will disable file and registry virtualization.
If you want to utilize File and Registry Virtualization for backward
compatibility then delete the requestedExecutionLevel node.
-->
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
<applicationRequestMinimum>
<PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true" ID="Custom" SameSite="site" />
<defaultAssemblyRequest permissionSetReference="Custom" />
</applicationRequestMinimum>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of all Windows versions that this application is designed to work with. Windows will automatically select the most compatible environment.-->
<!-- If your application is designed to work with Windows 7, uncomment the following supportedOS node-->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>-->
</application>
</compatibility>
<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
<!-- <dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>-->
</asmv1:assembly>

BIN
LED Backlight Changer/Resources/SlimDX.dll View File


+ 3
- 0
LED Backlight Changer/app.config View File

@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
</configuration>

+ 365
- 0
LED Backlight Changer/backlight_changer.Designer.cs View File

@@ -0,0 +1,365 @@
namespace WindowsFormsApplication1
{
partial class Backlight_Changer
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Backlight_Changer));
this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
this.start_stop = new System.Windows.Forms.Button();
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.label1 = new System.Windows.Forms.Label();
this.com_port = new System.Windows.Forms.ComboBox();
this.connect_button = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.pattern_select = new System.Windows.Forms.ComboBox();
this.color_mode = new System.Windows.Forms.ComboBox();
this.colorDialog1 = new System.Windows.Forms.ColorDialog();
this.custom_color = new System.Windows.Forms.TextBox();
this.button2 = new System.Windows.Forms.Button();
this.label4 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.custom_color_2 = new System.Windows.Forms.TextBox();
this.screen_select = new System.Windows.Forms.ComboBox();
this.speed_track = new System.Windows.Forms.TrackBar();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.color_delay_track = new System.Windows.Forms.TrackBar();
this.contextMenuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.speed_track)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.color_delay_track)).BeginInit();
this.SuspendLayout();
//
// backgroundWorker1
//
this.backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker1_DoWork);
//
// start_stop
//
this.start_stop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.start_stop.Location = new System.Drawing.Point(100, 41);
this.start_stop.Name = "start_stop";
this.start_stop.Size = new System.Drawing.Size(75, 23);
this.start_stop.TabIndex = 0;
this.start_stop.UseVisualStyleBackColor = true;
this.start_stop.Click += new System.EventHandler(this.start_stop_Click);
//
// notifyIcon1
//
this.notifyIcon1.ContextMenuStrip = this.contextMenuStrip1;
this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
this.notifyIcon1.Text = "Background LED Changer ";
this.notifyIcon1.Visible = true;
this.notifyIcon1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.notifyIcon1_MouseDoubleClick);
//
// contextMenuStrip1
//
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.exitToolStripMenuItem});
this.contextMenuStrip1.Name = "contextMenuStrip1";
this.contextMenuStrip1.Size = new System.Drawing.Size(93, 26);
//
// exitToolStripMenuItem
//
this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
this.exitToolStripMenuItem.Size = new System.Drawing.Size(92, 22);
this.exitToolStripMenuItem.Text = "Exit";
this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
//
// pictureBox1
//
this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.pictureBox1.Location = new System.Drawing.Point(12, 411);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(163, 60);
this.pictureBox1.TabIndex = 1;
this.pictureBox1.TabStop = false;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(9, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(53, 13);
this.label1.TabIndex = 2;
this.label1.Text = "COM Port";
//
// com_port
//
this.com_port.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.com_port.FormattingEnabled = true;
this.com_port.Location = new System.Drawing.Point(12, 25);
this.com_port.Name = "com_port";
this.com_port.Size = new System.Drawing.Size(64, 21);
this.com_port.Sorted = true;
this.com_port.TabIndex = 3;
//
// connect_button
//
this.connect_button.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.connect_button.Location = new System.Drawing.Point(100, 12);
this.connect_button.Name = "connect_button";
this.connect_button.Size = new System.Drawing.Size(75, 23);
this.connect_button.TabIndex = 4;
this.connect_button.Text = "Connect";
this.connect_button.UseVisualStyleBackColor = true;
this.connect_button.Click += new System.EventHandler(this.connect_button_Click);
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(9, 103);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(61, 13);
this.label2.TabIndex = 5;
this.label2.Text = "Color Mode";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(9, 208);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(41, 13);
this.label3.TabIndex = 6;
this.label3.Text = "Pattern";
//
// pattern_select
//
this.pattern_select.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.pattern_select.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.pattern_select.FormattingEnabled = true;
this.pattern_select.Items.AddRange(new object[] {
"Solid",
"Blink",
"Pulse"});
this.pattern_select.Location = new System.Drawing.Point(12, 224);
this.pattern_select.Name = "pattern_select";
this.pattern_select.Size = new System.Drawing.Size(163, 21);
this.pattern_select.TabIndex = 7;
//
// color_mode
//
this.color_mode.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.color_mode.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.color_mode.FormattingEnabled = true;
this.color_mode.Items.AddRange(new object[] {
"Average",
"Custom"});
this.color_mode.Location = new System.Drawing.Point(12, 119);
this.color_mode.Name = "color_mode";
this.color_mode.Size = new System.Drawing.Size(163, 21);
this.color_mode.TabIndex = 8;
//
// custom_color
//
this.custom_color.Enabled = false;
this.custom_color.Location = new System.Drawing.Point(12, 149);
this.custom_color.Name = "custom_color";
this.custom_color.Size = new System.Drawing.Size(61, 20);
this.custom_color.TabIndex = 9;
this.custom_color.Text = "#000000";
//
// button2
//
this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button2.Location = new System.Drawing.Point(79, 146);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(96, 23);
this.button2.TabIndex = 10;
this.button2.Text = "Select Color";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// label4
//
this.label4.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label4.Location = new System.Drawing.Point(12, 388);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(163, 20);
this.label4.TabIndex = 11;
this.label4.Text = "Current LED Color";
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// button1
//
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button1.Location = new System.Drawing.Point(79, 175);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(96, 23);
this.button1.TabIndex = 13;
this.button1.Text = "Select Color";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// custom_color_2
//
this.custom_color_2.Enabled = false;
this.custom_color_2.Location = new System.Drawing.Point(12, 175);
this.custom_color_2.Name = "custom_color_2";
this.custom_color_2.Size = new System.Drawing.Size(61, 20);
this.custom_color_2.TabIndex = 12;
this.custom_color_2.Text = "#000000";
this.custom_color_2.TextChanged += new System.EventHandler(this.custom_color_2_TextChanged);
//
// screen_select
//
this.screen_select.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.screen_select.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.screen_select.FormattingEnabled = true;
this.screen_select.Location = new System.Drawing.Point(12, 70);
this.screen_select.Name = "screen_select";
this.screen_select.Size = new System.Drawing.Size(163, 21);
this.screen_select.TabIndex = 14;
//
// speed_track
//
this.speed_track.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.speed_track.Location = new System.Drawing.Point(12, 274);
this.speed_track.Maximum = 100;
this.speed_track.Minimum = 1;
this.speed_track.Name = "speed_track";
this.speed_track.Size = new System.Drawing.Size(163, 45);
this.speed_track.TabIndex = 15;
this.speed_track.TickFrequency = 5;
this.speed_track.Value = 50;
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(9, 258);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(81, 13);
this.label5.TabIndex = 16;
this.label5.Text = "Gradiant Speed";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(9, 322);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(61, 13);
this.label6.TabIndex = 18;
this.label6.Text = "Color Delay";
//
// color_delay_track
//
this.color_delay_track.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.color_delay_track.Location = new System.Drawing.Point(12, 338);
this.color_delay_track.Maximum = 100;
this.color_delay_track.Minimum = 1;
this.color_delay_track.Name = "color_delay_track";
this.color_delay_track.Size = new System.Drawing.Size(163, 45);
this.color_delay_track.TabIndex = 17;
this.color_delay_track.TickFrequency = 5;
this.color_delay_track.Value = 50;
this.color_delay_track.Scroll += new System.EventHandler(this.color_delay_track_Scroll);
//
// Backlight_Changer
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(187, 483);
this.Controls.Add(this.label6);
this.Controls.Add(this.color_delay_track);
this.Controls.Add(this.label5);
this.Controls.Add(this.speed_track);
this.Controls.Add(this.screen_select);
this.Controls.Add(this.button1);
this.Controls.Add(this.custom_color_2);
this.Controls.Add(this.label4);
this.Controls.Add(this.button2);
this.Controls.Add(this.custom_color);
this.Controls.Add(this.color_mode);
this.Controls.Add(this.pattern_select);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.connect_button);
this.Controls.Add(this.com_port);
this.Controls.Add(this.label1);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.start_stop);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MinimumSize = new System.Drawing.Size(203, 521);
this.Name = "Backlight_Changer";
this.Text = "Backlight Control Panel";
this.Load += new System.EventHandler(this.Backlight_Changer_Load);
this.Shown += new System.EventHandler(this.Backlight_Changer_Shown);
this.ResizeEnd += new System.EventHandler(this.Backlight_Changer_ResizeEnd);
this.Resize += new System.EventHandler(this.Backlight_Changer_Resize);
this.contextMenuStrip1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.speed_track)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.color_delay_track)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private System.ComponentModel.BackgroundWorker backgroundWorker1;
private System.Windows.Forms.Button start_stop;
private System.Windows.Forms.NotifyIcon notifyIcon1;
private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ComboBox com_port;
private System.Windows.Forms.Button connect_button;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.ComboBox pattern_select;
private System.Windows.Forms.ComboBox color_mode;
private System.Windows.Forms.ColorDialog colorDialog1;
private System.Windows.Forms.TextBox custom_color;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox custom_color_2;
private System.Windows.Forms.ComboBox screen_select;
private System.Windows.Forms.TrackBar speed_track;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.TrackBar color_delay_track;
}
}


+ 752
- 0
LED Backlight Changer/backlight_changer.cs View File

@@ -0,0 +1,752 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
using System.Threading;
using System.Drawing.Imaging;
using System.Windows;
using System.Web;
using SlimDX.Direct3D9;
using SlimDX;

namespace WindowsFormsApplication1
{
public partial class Backlight_Changer : Form
{
SerialPort _serialPort = new SerialPort();
Thread _thread;
DxScreenCapture sc = new DxScreenCapture();

int Bpp = Screen.PrimaryScreen.BitsPerPixel / 8;
private string selected_color_mode = "Average";
private string cur_custom_color = "#000000";
private string cur_custom_color_2 = "#000000";
private string selected_pattern = "Solid";
private Screen selected_screen = Screen.PrimaryScreen;
private int cur_speed = 50;
private int cur_delay = 50;
private bool connected = false;

private List<Color> rainbow_colors = new List<Color>()
{
Color.Red,
Color.Orange,
Color.Yellow,
Color.Green,
Color.Blue,
Color.Indigo,
Color.Violet
};

public Backlight_Changer()
{
InitializeComponent();
if (Bpp != 4)
{
throw new Exception("Screen must be 32 bit color depth");
}
}

private void Backlight_Changer_Load(object sender, EventArgs e)
{
start_stop.Text = "Start";
start_stop.Enabled = false;
string[] ports = SerialPort.GetPortNames();
com_port.Items.AddRange(ports);
com_port.SelectedIndex = 0;
color_mode.SelectedIndex = 0;
pattern_select.SelectedIndex = 0;
pictureBox1.BackColor = Color.Black;

screen_select.ValueMember = null;
screen_select.DisplayMember = "DeviceName";
screen_select.DataSource = Screen.AllScreens;

_thread = new Thread(new ThreadStart(set_color));
_serialPort.ErrorReceived += _serialPort_ErrorReceived;

pattern_select.SelectedIndexChanged += new System.EventHandler(this.pattern_select_SelectedIndexChanged);
color_mode.SelectedIndexChanged += new System.EventHandler(this.color_mode_SelectedIndexChanged);
custom_color.TextChanged += new System.EventHandler(this.custom_color_TextChanged);
screen_select.SelectedIndexChanged += new System.EventHandler(this.screen_select_SelectedIndexChanged);
speed_track.Scroll += new System.EventHandler(this.speed_track_Scroll);
//this.WindowState = FormWindowState.Minimized;
}

Color CalculateAverageColor(DataStream gs)
{
int nBytes = Screen.PrimaryScreen.Bounds.Width * Screen.PrimaryScreen.Bounds.Height * 4;
byte[] bu = new byte[nBytes];
int r = 0;
int g = 0;
int b = 0;
int i = 0;
gs.Position = 0;
gs.Read(bu, 0, nBytes);
while (i < nBytes)
{
// Note: pixel format is BGR
b += bu[i];
g += bu[i + 1];
r += bu[i + 2];

i += 4;
}

int nPixels = i / 4;
return Color.FromArgb(r / nPixels, g / nPixels, b / nPixels);
}

private Color get_avg()
{
Surface s = sc.CaptureScreen(selected_screen);
DataRectangle dr = s.LockRectangle(LockFlags.None);
DataStream gs = dr.Data;

Color avg = CalculateAverageColor(gs);
s.UnlockRectangle();
s.Dispose();
return avg;
}
private void set_color()
{
Color color = new Color();
Color color_1 = new Color();
Color color_2 = new Color();
switch (selected_color_mode)
{
case "Custom":
color_1 = ColorTranslator.FromHtml(cur_custom_color);
color_2 = ColorTranslator.FromHtml(cur_custom_color_2);
break;
default:
color_1 = Color.Black;
color_2 = Color.Black;
break;
}
bool up = true;
int index = 0;
int delay_index = 0;
int color_index = 0;
int log_delay = 0;
float percentage = 1;
float h = color_1.GetHue();
float s = color_1.GetSaturation();
float v = color_1.GetBrightness();
IEnumerable<double> logs = logspace(0.1, 1000, 100);
while (true)
{
/*
Solid
Pulse
Blink
Gradiant
Rainbow
*/
log_delay = (int)logs.ElementAt(cur_delay - 1);
switch (selected_color_mode)
{
case "Average":
color_1 = get_avg();
break;
default:
break;
}
byte Red = new byte();
byte Green = new byte();
byte Blue = new byte();
switch(selected_pattern)
{
case "Solid":
System.Threading.Thread.Sleep(10);
Red = (byte)color_1.R;
Green = (byte)color_1.G;
Blue = (byte)color_1.B;
break;
case "Pulse":
if (index >= cur_speed)
{
if (percentage == 1)
{
up = false;
}
if (percentage == 0)
{
if (delay_index >= log_delay)
{
up = true;
delay_index = 0;
}
else
{
delay_index++;
}
}
if (up)
{
percentage += (float)(0.01 * (speed_track.Maximum / cur_speed));
if (percentage > 1)
{
percentage = 1;
}

color = LerpColor(color_1, Color.Black, percentage);
}
else
{
percentage -= (float)(0.01 * (speed_track.Maximum / cur_speed));

if (percentage < 0)
{
percentage = 0;
}

color = LerpColor(color_1, Color.Black, percentage);
}
index = 0;
}
else
{
index++;
}
Red = (byte)color.R;
Green = (byte)color.G;
Blue = (byte)color.B;
break;
case "Blink":
if (index >= cur_speed)
{
if (up)
{
color = color_1;
}
else
{
if (delay_index >= log_delay)
{
color = Color.Black;
delay_index = 0;
}
else
{
delay_index++;
}
}
index = 0;
up = !up;
}
else
{
index++;
}
Red = (byte)color.R;
Green = (byte)color.G;
Blue = (byte)color.B;
break;
case "Gradiant":
if (index >= cur_speed)
{
if (percentage == 1)
{
up = false;
}
if (percentage == 0)
{
up = true;
}
if (up)
{
if (delay_index >= log_delay)
{
percentage += (float)(0.01 * (speed_track.Maximum / cur_speed));
if (percentage > 1)
{
percentage = 1;
}
color = LerpColor(color_1, color_2, percentage);
delay_index = 0;
}
else
{
delay_index++;
}
}
else
{
if (delay_index >= cur_delay)
{
percentage -= (float)(0.01 * (speed_track.Maximum / cur_speed));

if (percentage < 0)
{
percentage = 0;
}
color = LerpColor(color_1, color_2, percentage);
delay_index = 0;
}
else
{
delay_index++;
}
}
index = 0;
}
else
{
index++;
}
Red = (byte)color.R;
Green = (byte)color.G;
Blue = (byte)color.B;
break;
case "Rainbow":
if (index >= cur_speed)
{
if (percentage == 1)
{
color_1 = color_2;
if (delay_index >= log_delay)
{
if (rainbow_colors.Count > color_index)
{
color_2 = rainbow_colors[color_index];
}
else
{
color_2 = rainbow_colors[0];
color_index = 0;
}
color_index++;
percentage = 0;
delay_index = 0;
}
else
{
delay_index++;
}
}
percentage += (float)(0.01 * (speed_track.Maximum / cur_speed));
if (percentage > 1)
{
percentage = 1;
}
color = LerpColor(color_1, color_2, percentage);
index = 0;
}
else
{
index++;
}
Red = (byte)color.R;
Green = (byte)color.G;
Blue = (byte)color.B;
break;
case "Random":
if (index >= cur_speed)
{
if (percentage == 1)
{
color_1 = color_2;
if (delay_index >= log_delay)
{
Random rand = new Random();
int rand_R = rand.Next(255);
int rand_G = rand.Next(255);
int rand_B = rand.Next(255);
color_2 = Color.FromArgb(0, rand_R, rand_G, rand_B);
percentage = 0;
}
else
{
delay_index++;
}
}
percentage += (float)(0.01 * (speed_track.Maximum / cur_speed));
if (percentage > 1)
{
percentage = 1;
}
color = LerpColor(color_1, color_2, percentage);
index = 0;
}
else
{
index++;
}
Red = (byte)color.R;
Green = (byte)color.G;
Blue = (byte)color.B;
break;
default:
System.Threading.Thread.Sleep(10);
Red = (byte)color_1.R;
Green = (byte)color_1.G;
Blue = (byte)color_1.B;
break;
}
_serialPort.Write(new byte[] { 0xFF, Red, Green, Blue }, 0, 4);

string htmlHexColorValueTwo = ColorTranslator.ToHtml(Color.FromArgb(0, Red, Green, Blue));
pictureBox1.BackColor = ColorTranslator.FromHtml(htmlHexColorValueTwo);
AppDomain.CurrentDomain.ProcessExit += new EventHandler (OnProcessExit);
}
}

public IEnumerable<double> logspace(double start, double end, int count)
{
double d = (double)count, p = end / start;
return Enumerable.Range(0, count).Select(i => start * Math.Pow(p, i / d));
}

private Color LerpColor(Color a, Color b, float percentage)
{
byte A = new byte();
byte R = new byte();
byte G = new byte();
byte B = new byte();
A = (byte)(a.A + (b.A - a.A) * percentage);
R = (byte)(a.R + (b.R - a.R) * percentage);
G = (byte)(a.G + (b.G - a.G) * percentage);
B = (byte)(a.B + (b.B - a.B) * percentage);
return Color.FromArgb(A, R, G, B);
}

private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
set_color();
}

private void start_stop_Click(object sender, EventArgs e)
{
if (_thread.IsAlive)
{
_thread.Abort();
_serialPort.Write(new byte[] { 0xFF, 0, 0, 0 }, 0, 4);
string htmlHexColorValueTwo = ColorTranslator.ToHtml(Color.FromArgb(0, 0, 0,0));
pictureBox1.BackColor = ColorTranslator.FromHtml(htmlHexColorValueTwo);
start_stop.Text = "Start";
}
else
{
_thread = new Thread(new ThreadStart(set_color));
_thread.IsBackground = true;
_thread.Start();
start_stop.Text = "Stop";
}
}

private void start(object sender, EventArgs e)
{
if (!_thread.IsAlive)
{
_thread = new Thread(new ThreadStart(set_color));
_thread.IsBackground = true;
_thread.Start();
start_stop.Text = "Stop";
}
}

private void stop(object sender, EventArgs e)
{
if (_thread.IsAlive)
{
_thread.Abort();
start_stop.Text = "Start";
}
}

private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
this.Show();
this.WindowState = FormWindowState.Normal;
}

private void Backlight_Changer_ResizeEnd(object sender, EventArgs e)
{

}

private void Backlight_Changer_Resize(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
this.Hide();
}

private void Backlight_Changer_Shown(object sender, EventArgs e)
{
//this.Hide();
}

private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
_thread.Abort();
if (_serialPort.IsOpen == false)
{
_serialPort = new SerialPort();
_serialPort.PortName = com_port.SelectedItem.ToString();
_serialPort.BaudRate = 9600;

_serialPort.ReadTimeout = 500;
_serialPort.WriteTimeout = 500;
_serialPort.Open();
}
_serialPort.Write(new byte[] { 0xFF, 0, 0, 0 }, 0, 4);
_serialPort.Close();
Application.Exit();
}
private void OnProcessExit(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{
if (colorDialog1.ShowDialog() == DialogResult.OK)
{
custom_color_2.Text = ColorTranslator.ToHtml(colorDialog1.Color);
}
}

private void button2_Click(object sender, EventArgs e)
{
if (colorDialog1.ShowDialog() == DialogResult.OK)
{
custom_color.Text = ColorTranslator.ToHtml(colorDialog1.Color);
}
}

private void connect_button_Click(object sender, EventArgs e)
{
if (_serialPort.IsOpen == false)
{
try
{
_serialPort.PortName = com_port.SelectedItem.ToString();
_serialPort.BaudRate = 9600;

_serialPort.ReadTimeout = 500;
_serialPort.WriteTimeout = 500;

_serialPort.Open();
start_stop.Enabled = true;
connect_button.Text = "Disconnect";
com_port.Enabled = false;
connected = true;
}
catch
{
start_stop.Enabled = false;
}
}
else
{
stop(sender, e);
start_stop.Enabled = false;
connect_button.Text = "Connect";
com_port.Enabled = true;
connected = false;
try
{
_serialPort.Close();
}
catch { }
}
}

void _serialPort_ErrorReceived(object sender, SerialErrorReceivedEventArgs e)
{
stop(sender, e);
start_stop.Enabled = false;
connect_button.Text = "Connect";
com_port.Enabled = true;
connected = false;
try
{
_serialPort.Close();
}
catch { }
}

private void color_mode_SelectedIndexChanged(object sender, EventArgs e)
{
bool stopped = false;
if (connected && _thread.IsAlive)
{
stop(sender, e);
stopped = true;
}
selected_color_mode = color_mode.SelectedItem.ToString();
if(color_mode.SelectedItem.ToString().Equals("Custom"))
{
screen_select.Enabled = false;
custom_color.Enabled = true;
button2.Enabled = true;
if (selected_pattern.Equals("Gradiant"))
{
button1.Enabled = true;
custom_color_2.Enabled = true;
}
if (pattern_select.Items.Count <= 2)
{
pattern_select.Items.Add("Gradiant");
pattern_select.Items.Add("Rainbow");
pattern_select.Items.Add("Random");
}
}
else
{
screen_select.Enabled = true;
custom_color.Enabled = false;
button2.Enabled = false;
custom_color_2.Enabled = false;
button1.Enabled = false;
if (selected_pattern.Equals("Gradiant") || selected_pattern.Equals("Rainbow") || selected_pattern.Equals("Random"))
{
pattern_select.SelectedIndex = 0;
}
if (pattern_select.Items.Count > 3)
{
pattern_select.Items.RemoveAt(5);
pattern_select.Items.RemoveAt(4);
pattern_select.Items.RemoveAt(3);
}
}
if (connected && stopped)
{
start(sender, e);
}
}

private void custom_color_TextChanged(object sender, EventArgs e)
{
bool stopped = false;
if (connected && _thread.IsAlive)
{
stop(sender, e);
stopped = true;
}
cur_custom_color = custom_color.Text;
if (connected && stopped)
{
start(sender, e);
}
}

private void custom_color_2_TextChanged(object sender, EventArgs e)
{
bool stopped = false;
if (connected && _thread.IsAlive)
{
stop(sender, e);
stopped = true;
}
cur_custom_color_2 = custom_color_2.Text;
if (connected && stopped)
{
start(sender, e);
}
}

private void pattern_select_SelectedIndexChanged(object sender, EventArgs e)
{
bool stopped = false;
if (connected && _thread.IsAlive)
{
stop(sender, e);
stopped = true;
}
selected_pattern = pattern_select.SelectedItem.ToString();
if (selected_pattern.Equals("Gradiant"))
{
if (selected_color_mode.Equals("Custom"))
{
button2.Enabled = true;
custom_color.Enabled = true;
button1.Enabled = true;
custom_color_2.Enabled = true;
}
}
else if(selected_pattern.Equals("Rainbow"))
{
button2.Enabled = false;
custom_color.Enabled = false;
button1.Enabled = false;
custom_color_2.Enabled = false;
}
else if (selected_pattern.Equals("Random"))
{
button2.Enabled = false;
custom_color.Enabled = false;
button1.Enabled = false;
custom_color_2.Enabled = false;
}
else
{
if (selected_color_mode.Equals("Custom"))
{
button2.Enabled = true;
custom_color.Enabled = true;
button1.Enabled = false;
custom_color_2.Enabled = false;
}
}
if (connected && stopped)
{
start(sender, e);
}
}

private void screen_select_SelectedIndexChanged(object sender, EventArgs e)
{
bool stopped = false;
if (connected && _thread.IsAlive)
{
stop(sender, e);
stopped = true;
}
selected_screen = (Screen)screen_select.SelectedValue;
if (connected && stopped)
{
start(sender, e);
}
}

private void speed_track_Scroll(object sender, EventArgs e)
{
cur_speed = speed_track.Value;
}

private void color_delay_track_Scroll(object sender, EventArgs e)
{
cur_delay = color_delay_track.Value;
}
}

public class DxScreenCapture
{
Device d;

public DxScreenCapture()
{
PresentParameters present_params = new PresentParameters();
present_params.Windowed = true;
present_params.SwapEffect = SwapEffect.Discard;
d = new Device(new Direct3D(), 0, DeviceType.Hardware, IntPtr.Zero, CreateFlags.SoftwareVertexProcessing, present_params);
}

public Surface CaptureScreen(Screen selected_screen)
{
Surface s = Surface.CreateOffscreenPlain(d, selected_screen.Bounds.Width, selected_screen.Bounds.Height, Format.A8R8G8B8, Pool.Scratch);
d.GetFrontBufferData(0, s);
return s;
}
}
}

+ 1013
- 0
LED Backlight Changer/backlight_changer.resx
File diff suppressed because it is too large
View File


+ 8
- 2
README.md View File

@@ -1,3 +1,9 @@
# LED_Changer
LED_Changer
===========

Background LED changer program for interfacing via Serial to a RGB device.

You must have SlimDX on your machine to run it: http://slimdx.org/download.php

This is just a simple little app for controlling an LED strip or other RGB device from your computer.

Background LED changer program for interfacing via Serial to a RGB device.

+ 34
- 0
arduino_LED_interface/arduino_LED_interface.ino View File

@@ -0,0 +1,34 @@
//Developed by Rajarshi Roy
int red, green, blue; //red, green and blue values
int RedPin = 10; //Red: PWM pin 10
int GreenPin = 9; //Green: PWM pin 11
int BluePin = 11; //Blue: PWM pin 9
void setup()
{
Serial.begin(9600);
//initial values (no significance)
int red = 255;
int blue = 255;
int green = 255;
}

void loop()
{
//protocol expects data in format of 4 bytes
//(xff) as a marker to ensure proper synchronization always
//followed by red, green, blue bytes
if (Serial.available()>=4)
{
if(Serial.read() == 0xff)
{
red = Serial.read();
green= Serial.read();
blue = Serial.read();
}
}
//finally control led brightness through pulse-width modulation
analogWrite (RedPin, red);
analogWrite (GreenPin, green);
analogWrite (BluePin, blue);
delay(10); //just to be safe
}

Loading…
Cancel
Save