Index: /trunk/MacFaceFloat/IOptimusMini.cs
===================================================================
--- /trunk/MacFaceFloat/IOptimusMini.cs	(revision 117)
+++ /trunk/MacFaceFloat/IOptimusMini.cs	(revision 117)
@@ -0,0 +1,105 @@
+﻿using System;
+using System.Runtime.InteropServices;
+using System.Threading;
+using System.Drawing;
+using System.Drawing.Imaging;
+using System.Runtime.InteropServices;
+
+/// <summary>
+/// Class1 の概要の説明です
+/// </summary>
+class IOptimusMini :IDisposable
+{
+    protected class Driver
+    {
+        const string DRIVER = "OptimusMini.dll";
+
+        public const int SCREEN_SIZE = 96;
+        public const int SCREEN_BUFFER_SIZE = SCREEN_SIZE * SCREEN_SIZE * 3;
+
+        public delegate void OnKeyDownCallbackDelegate(int key);
+        public delegate void OnDeviceStateChangedCallbackDelegate(int state);
+
+        [DllImport(DRIVER)]
+        public static extern void Init();
+
+        [DllImport(DRIVER)]
+        public static extern void Close();
+
+        [DllImport(DRIVER)]
+        public static extern int IsAlive();
+
+        [DllImport(DRIVER)]
+        public static extern int SendCommand(byte c1, byte c2);
+
+        [DllImport(DRIVER)]
+        public static extern int SendCommandBlocking(byte c1, byte c2);
+
+        [DllImport(DRIVER)]
+        public static extern int ShowPicture(int p_nButton, byte[] p_lpData);
+
+        [DllImport(DRIVER)]
+        public static extern int ShowPictureBlocking(int p_nButton, byte[] p_lpData);
+
+        [DllImport(DRIVER)]
+        public static extern int RegisterEventHandler(OnKeyDownCallbackDelegate dk, OnDeviceStateChangedCallbackDelegate ds);
+    }
+
+    public IOptimusMini()
+    {
+        Driver.Init();
+    }
+
+    public void Dispose()
+    {
+        DisplayOff();
+        Driver.Close();
+    }
+
+    public enum BrightnessLevel
+    {
+        Normal = 0,
+    }
+
+    public bool IsAlive
+    {
+        get { return (Driver.IsAlive() != 0); }
+    }
+
+    public BrightnessLevel Brightness
+    {
+        set { Driver.SendCommand(9, 60); }
+    }
+
+    public void DisplayOn()
+    {
+        Driver.SendCommand(2, 0);
+    }
+
+    public void DisplayOff()
+    {
+        Driver.SendCommand(3, 0);
+    }
+
+    public void ShowPicture(int num, Bitmap image)
+    {
+        BitmapData bData = image.LockBits(new Rectangle(new Point(0, 0), new Size(Driver.SCREEN_SIZE, Driver.SCREEN_SIZE)), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
+        byte[] bmpBytes = null;
+
+        try
+        {
+            // number of bytes in the bitmap
+            int byteCount = bData.Stride * image.Height;
+            bmpBytes = new byte[byteCount];
+
+            // Copy the locked bytes from memory
+            Marshal.Copy(bData.Scan0, bmpBytes, 0, byteCount);
+        }
+        // don't forget to unlock the bitmap!!
+        finally
+        {
+            image.UnlockBits(bData);
+        }
+        Driver.ShowPictureBlocking(num, bmpBytes);
+    }
+}
Index: /trunk/MacFaceFloat/MacFaceApp.cs
===================================================================
--- /trunk/MacFaceFloat/MacFaceApp.cs	(revision 116)
+++ /trunk/MacFaceFloat/MacFaceApp.cs	(revision 117)
@@ -13,4 +13,6 @@
 using System.IO;
 using System.Reflection;
+using System.Drawing.Imaging;
+using System.Runtime.InteropServices;
 
 namespace MacFace.FloatApp
@@ -41,5 +43,7 @@
 		private MacFace.FaceDef curFaceDef;
 
-		[STAThread]
+        private IOptimusMini optimusMini;
+
+        [STAThread]
 		public static void Main(string[] args)
 		{
@@ -126,8 +130,15 @@
 			}
 
+            //IOptimusMini.OnKeyDownCallbackDelegate oKD = new IOptimusMini.OnKeyDownCallbackDelegate(OnKeyDownCallbackHandler);
+            //IOptimusMini.OnDeviceStateChangedCallbackDelegate oDSC = new IOptimusMini.OnDeviceStateChangedCallbackDelegate(OnDeviceStateChangedCallbackHandler);
+            //IOptimusMini.RegisterEventHandler(oKD, oDSC);
+
             patternWindow = null;
             statusWindow = null;
 
             InitializeComponent();
+
+            optimusMini = new IOptimusMini();
+            optimusMini.DisplayOn();
 
             CountProcessorUsage(null, null);
@@ -138,4 +149,14 @@
 			updateTimer.Tick += new EventHandler(this.CountProcessorUsage);
 		}
+
+        void OnKeyDownCallbackHandler(int key)
+        {
+            Console.Write("Keydown {0}\n", key);
+        }
+
+        void OnDeviceStateChangedCallbackHandler(int state)
+        {
+            //useOptimusMini = (state > 0);
+        }
 
 		void InitializeComponent() 
@@ -232,7 +253,7 @@
 		{
 			notifyIcon.Visible = false;
-
 			config.Save();
-		}
+            optimusMini.Dispose();
+        }
 
 		public bool LoadFaceDefine(string path)
@@ -302,27 +323,27 @@
 			if (pageio_count < 0) pageio_count = 0;
 
+			int pattern = cpuUsage.Active / 10;
+			pattern += memUsage.Pageout / 15;
+			pattern += memUsage.Pagein / 30;
+			if (pattern > 10) pattern = 10;
+
+			FaceDef.PatternSuite suite = FaceDef.PatternSuite.Normal;
+
+			UInt64 avilable = (UInt64)memStats.TotalVisibleMemorySize * 1024 - memUsage.Used;
+            if (pageio_count > 100) 
+			{
+				suite = FaceDef.PatternSuite.MemoryInsufficient;
+			}
+            else if (avilable < 0) 
+			{
+				suite = FaceDef.PatternSuite.MemoryDecline;
+			}
+
+			int markers = FaceDef.MarkerNone;
+			if (memUsage.Pagein > 0) markers += FaceDef.MarkerPageIn;
+			if (memUsage.Pageout > 0) markers += FaceDef.MarkerPageOut;
+
 			if (patternWindow != null) 
 			{
-				int pattern = cpuUsage.Active / 10;
-				pattern += memUsage.Pageout / 15;
-				pattern += memUsage.Pagein / 30;
-				if (pattern > 10) pattern = 10;
-
-				FaceDef.PatternSuite suite = FaceDef.PatternSuite.Normal;
-
-				UInt64 avilable = (UInt64)memStats.TotalVisibleMemorySize * 1024 - memUsage.Used;
-                if (pageio_count > 100) 
-				{
-					suite = FaceDef.PatternSuite.MemoryInsufficient;
-				}
-                else if (avilable < 0) 
-				{
-					suite = FaceDef.PatternSuite.MemoryDecline;
-				}
-
-				int markers = FaceDef.MarkerNone;
-				if (memUsage.Pagein > 0) markers += FaceDef.MarkerPageIn;
-				if (memUsage.Pageout > 0) markers += FaceDef.MarkerPageOut;
-
 				patternWindow.UpdatePattern(suite, pattern, markers);
 			}
@@ -332,4 +353,15 @@
 				statusWindow.UpdateGraph();
 			}
+
+            if (optimusMini.IsAlive && curFaceDef != null)
+            {
+                Bitmap image = new Bitmap(96, 96);
+                Graphics g = Graphics.FromImage(image);
+                g.FillRectangle(new SolidBrush(Color.White), 0, 0, image.Width, image.Height);
+                curFaceDef.DrawPatternImage(g, suite, pattern, markers, 96F / 128F);
+                g.Dispose();
+
+                optimusMini.ShowPicture(1, image);
+            }
 		}
 
@@ -414,15 +446,15 @@
 		private void configForm_ConfigChanged()
 		{
-			if (patternWindow.FaceDef.Path != config.FaceDefPath) 
-			{
-				bool result = LoadFaceDefine(config.FaceDefPath);
-				// p^[ÏXÉ¸sµ½çÝèð³Éß·
-				if (!result) 
-				{
-					config.FaceDefPath = patternWindow.FaceDef.Path;
-				}
-			}
-
-			if (patternWindow != null) 
+            if (curFaceDef.Path != config.FaceDefPath)
+            {
+                bool result = LoadFaceDefine(config.FaceDefPath);
+                // p^[ÏXÉ¸sµ½çÝèð³Éß·
+                if (!result)
+                {
+                    config.FaceDefPath = patternWindow.FaceDef.Path;
+                }
+            }
+
+            if (patternWindow != null) 
 			{
 				patternWindow.Opacity = (float)config.Opacity / 100;
Index: /trunk/MacFaceFloat/MacFaceFloat.csproj
===================================================================
--- /trunk/MacFaceFloat/MacFaceFloat.csproj	(revision 116)
+++ /trunk/MacFaceFloat/MacFaceFloat.csproj	(revision 117)
@@ -2,5 +2,5 @@
   <PropertyGroup>
     <ProjectType>Local</ProjectType>
-    <ProductVersion>9.0.30729</ProductVersion>
+    <ProductVersion>9.0.21022</ProductVersion>
     <SchemaVersion>2.0</SchemaVersion>
     <ProjectGuid>{60DE0E19-7B98-41E8-8001-A8C7A75AF08E}</ProjectGuid>
@@ -150,4 +150,7 @@
       <SubType>Form</SubType>
     </Compile>
+    <Compile Include="IOptimusMini.cs">
+      <SubType>Code</SubType>
+    </Compile>
     <Compile Include="MacFaceApp.cs">
       <SubType>Code</SubType>
@@ -252,9 +255,12 @@
     <Content Include="kikiki-rin.mcface\note.tiff" />
     <Content Include="kikiki-rin.mcface\shock.tiff" />
+    <Content Include="OptimusMini.dll" />
   </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
   <PropertyGroup>
     <PreBuildEvent>"$(ProjectDir)PreBuild_GenerateAssemblyInfoVersionPart.cmd" &gt; "$(ProjectDir)AssemblyInfoVersionPart.cs"</PreBuildEvent>
-    <PostBuildEvent>xcopy /Y /I "$(ProjectDir)default.mcface" "$(TargetDir)default.mcface"</PostBuildEvent>
+    <PostBuildEvent>xcopy /Y /I "$(ProjectDir)default.mcface" "$(TargetDir)default.mcface"
+copy "$(ProjectDir)OptimusMini.dll" "$(TargetDir)OptimusMini.dll"
+</PostBuildEvent>
   </PropertyGroup>
 </Project>
