'닌텐도wii'에 해당되는 글 3

  1. 2008.07.17 Wiimote Library 분석 (1)
  2. 2008.06.30 [Wiimote project] Johny lee 따라하기_2
  3. 2008.02.26 쟈니리의 닌텐도 Wii project
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. 6. 30. 22:54

[Wiimote project] Johny lee 따라하기_2



Johny lee 따라하기 2단계

닌텐도 위모트를 PC에 연결하고 나서 그의 동영상에서 처럼 화이트보드 기능을 시험해 보려고 한다.
IR LED를 가지고 펜에다가 삽입한 후 닌텐도 위모트에 쏘면 펜의 위치가 인식되는 방식이다.

펜은 아래와 같은 방식으로 제작했다. 쟈니리와 약간 다른 것은 그냥 일반 리모컨에서 LED를 얻었고,
그러다 보니 특성값을 알 수 없어서 저항값을 정확히 알지 못해 가변저항을 이용하였다.

사용자 삽입 이미지

전원의 경우 USB를 이용하고 싶었으나, IR LED의 용량을 정확히 알지 못해서 PC에 무리가 갈까봐 DC adapter를 이용하였다.

쟈니리의 홈페이지에서 화이트보드 프로그램을 다운로드 받고 펜을 가지고 실험해 보면 동영상과 같은 기능을 확인할 수 있다. 단, 위모트가 45도 각도로 IR 신호를 입력받기 때문에 펜에서 나가는 IR 신호의 범위를 찾기가 좀 어려운 부분이 있다.



 특히나 와이드 모니터의 경우는 각도를 찾기 어려워서 상당히 뒤에 위치시켜서 동작을 시켜야 했다.

여기부터는 프로그램을 어떻게 동작시켜야 하는지 분석을 해보고, 자체적인 프로그램을 작성해서 더 나은 Human Interface를 만들 수 있을지 고민해 봐야 겠다.

To be continue...
Interesting | Posted by hyena0 2008. 2. 26. 22:48

쟈니리의 닌텐도 Wii project

Wii Remote Project

 Johnny Chung Lee 라는 카네미 멜론대 학생이 Nitendo wii 리모컨을 가지고 가상현실에 적용한 내용과 멀티터치를 구현할 수 있도록 한 것이다.
 
 닌텐도 Wii remote 를 가지고 쟈니리가 제공하는 프로그램을 가지고 테스트 해볼 수 있을 것이다.
 http://www.wiimoteproject.com

* 가상현실

* 멀티터치