'Interesting/Wii'에 해당되는 글 5

  1. 2008.07.17 Wiimote Library 분석 (1)
  2. 2008.07.17 [wiimote] Wiiimote 분해사진
  3. 2008.07.15 [wiimote] whiteboard 프로그램 분석 (1)
Interesting/Wii | Posted by hyena0 2008. 7. 17. 00:37

Wiimote Library 분석 (1)




Wiimote Library

Wiimote Library 내용을 알아야 응용프로그램을 만들 수 있기 때문에 라이브러리 내용을 살펴보도록 하겠다.

위모트 라이브러리는 C#으로 작성되어 있고, Wiimote.cs, HIDImports.cs, Events.cs, DataTypes.cs 네가지 파일로 구성된다.

Wiimote.cs는 wiimote class가 있고 위모트를 연결하고 동작하기 위한 Method 들을 포함하고 있어서 , 윈도우프로그램에서 초기화와 데이터입출력을 처리하는 부분이 된다.
HIDImports.cs는 인식된 위모트를 연결해주는 역할을 하고, Events.cs는 이벤트 처리에 해당하는 부분이고, DataTypes.cs는 데이터처리에 필요한 구조체들을 정의하고 있다.  

각 해당 파일에 대한 클래스와 메소드를 정리해 보았다.

------------------------
*Wiimote.cs

namespace WiimoteLib
{
public class Wiimote : IDisposable
{
public Wiimote();
public void Connect();
public void Disconnect();
private void BeginAsyncRead();
private void OnReadData(IAsyncResult ar);
private bool ParseInput(byte[] buff);
private void InitializeExtension();
private byte[] DecryptBuffer(byte[] buff);
private void ParseButtons(byte[] buff);
private void ParseAccel(byte[] buff);
private void ParseIR(byte[] buff);
private void ParseExtension(byte[] buff, int offset);
private void ParseReadData(byte[] buff);
private byte GetRumbleBit();
public void SetReportType(InputReport type, bool continuous);
public void SetLEDs(bool led1, bool led2, bool led3, bool led4);
public void SetLEDs(int leds);
public void SetRumble(bool on);
public void GetStatus();
private void EnableIR(IRMode mode);
private void DisableIR();
private void ClearReport();
private void WriteReport();
public byte[] ReadData(int address, short size);
public void WriteData(int address, byte data);
public void WriteData(int address, byte size, byte[] buff);
}
}
---------------------------
* HIDImports.cs

class HIDImports
{
[DllImport("hid.dll")]
public static extern void HidD_GetHidGuid(out Guid gHid);
public static extern Boolean HidD_GetAttributes(IntPtr HidDeviceObject, ref HIDD_ATTRIBUTES Attributes);
internal extern static bool HidD_SetOutputReport(
   IntPtr HidDeviceObject,
   byte[] lpReportBuffer,
   uint ReportBufferLength);
[DllImport(@"setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern IntPtr SetupDiGetClassDevs(
   ref Guid ClassGuid,
   [MarshalAs(UnmanagedType.LPTStr)] string Enumerator,
   IntPtr hwndParent,
   UInt32 Flags
   );
public static extern Boolean SetupDiEnumDeviceInterfaces(
   IntPtr hDevInfo,
   //ref SP_DEVINFO_DATA devInfo,
   IntPtr devInvo,
   ref Guid interfaceClassGuid,
   Int32 memberIndex,
   ref SP_DEVICE_INTERFACE_DATA deviceInterfaceData
  );
public static extern UInt16 SetupDiDestroyDeviceInfoList( IntPtr hDevInfo );

[DllImport(@"setupapi.dll", SetLastError = true)]
public static extern Boolean SetupDiGetDeviceInterfaceDetail(
   IntPtr hDevInfo,
   ref SP_DEVICE_INTERFACE_DATA deviceInterfaceData,
   IntPtr deviceInterfaceDetailData,
   UInt32 deviceInterfaceDetailDataSize,
   out UInt32 requiredSize,
   IntPtr deviceInfoData
  );
public static extern Boolean SetupDiGetDeviceInterfaceDetail(
   IntPtr hDevInfo,
   ref SP_DEVICE_INTERFACE_DATA deviceInterfaceData,
   ref SP_DEVICE_INTERFACE_DETAIL_DATA deviceInterfaceDetailData,
   UInt32 deviceInterfaceDetailDataSize,
   out UInt32 requiredSize,
   IntPtr deviceInfoData
  );

[DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern SafeFileHandle CreateFile(
   string fileName,
   [MarshalAs(UnmanagedType.U4)] FileAccess fileAccess,
   [MarshalAs(UnmanagedType.U4)] FileShare fileShare,
   IntPtr securityAttributes,
   [MarshalAs(UnmanagedType.U4)] FileMode creationDisposition,
   [MarshalAs(UnmanagedType.U4)] EFileAttributes flags,
   IntPtr template);

[DllImport("kernel32.dll", SetLastError=true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CloseHandle(IntPtr hObject);
}
---------------------------
* Events.cs

public delegate void WiimoteChangedEventHandler(object sender, WiimoteChangedEventArgs args);
public delegate void WiimoteExtensionChangedEventHandler(object sender, WiimoteExtensionChangedEventArgs args);
public class WiimoteExtensionChangedEventArgs: EventArgs
public class WiimoteChangedEventArgs: EventArgs
{
public WiimoteExtensionChangedEventArgs(ExtensionType type, bool inserted);
}
public class WiimoteChangedEventArgs: EventArgs
{
public WiimoteChangedEventArgs(WiimoteState ws);
}
---------------------------
*DataTypes.cs

public class WiimoteState
public struct LEDState
public struct NunchukCalibrationInfo
public struct ClassicControllerCalibrationInfo
public struct NunchukState
public struct ClassicControllerButtonState
public struct ClassicControllerState
public struct IRState
public struct AccelState
public struct AccelCalibrationInfo
public struct ButtonState
public enum ExtensionType : byte
public enum IRMode : byte
---------------------------

Interesting/Wii | Posted by hyena0 2008. 7. 17. 00:00

[wiimote] Wiiimote 분해사진




Wiiimote 분해사진

Wiimote의 분해사진은 일본의 Tech-on 이라는 사이트에서 가져왔다.

사진에서 보듯이 붉은 색 화살표 부분이 3차원 센서이고 아날로그 디바이스 사의 제품이다.

그리고 우측 끝에는 IR 수신부가 있다.

각 H/W의 기능은 WiimoteLib 파일에서 어떤 기능이 정의되어 있는지 확인할 수 있다.


사용자 삽입 이미지
Interesting/Wii | Posted by hyena0 2008. 7. 15. 23:43

[wiimote] whiteboard 프로그램 분석 (1)



Whiteboard Program 분석(1)

쟈니리의 화이트보드 프로그램을 다운로드 받아보면, C#으로 작성된 것을 알 수 있다.

프로젝트를 Visual Studio 에서 열어보면 아래의 구조로 구성되어 있다.


WiimoteWhiteboard
--------------------------
Properties
 app.manifest
 AssemblyInfo.cs
 Resources.resx
  Resources.Designer.cs
 Settings.settings
  Settings.Designer.cs
--------------------------
References
 System
 System.Data
 System.Drawing
 System.Windows.Forms
 System.Xml
--------------------------
WiimoteLib
-docs
  -APIHelp
   -AdditionalContent
   -Help
  - Properties
 DataTypes.cs
 Events.cs
 HIDImports.cs
 WiimoteLib.csproj
 WiimoteLib.csproj.user
--------------------------
CalibrationForm.cs
 CalibrationForm.Designer.cs
 CalibrationForm.resx
Form1.cs
 Form1.Designer.cs
 Form1.resx
Program.cs
Warper.cs

주요한 프로그램은 Form1.cs와 CalibrationForm.cs 이지만, WiimoteLib 속에 위모트를 불러들이고 처리하는 부분이 들어 있어서 향후에 위모트로 응용프로그램을 작성하자면 분석해야할 첫대상이 될 것이다.

 WiimoteLib는 DataTypes.cs, Events.cs, HIDImports.cs 세가지 파일로 구성된다.