Last update: 2009-05-09 (土) 14:45:29
Mobileメモ:バイブ制御
WindowsMobileでバイブ制御
Windows Mobileでバイブを制御する方法です。
バイブはLEDと同様の通知デバイスとして制御するようです。
関数
ずばり、以下の関数を使います。
(参考: Windows Embedded Developer Center)
BOOL WINAPI NLedSetDevice( UINT nDeviceId, void* pInput );
引数は以下の通り。
- nDeviceId [in] Integer that specifies what information to set. You can set it to NLED_SETTINGS_INFO_ID to indicate that the pInput buffer contains information about the current settings for the notification LED.
- pInput [out] Pointer to the buffer that contains the NLED_SETTINGS_INFO structure. This structure contains the new settings for the notification LED.
要するに、nDeviceIdは固定値NLED_COUNT_INFO_IDを指定、pInputには制御情報を格納した構造体NLED_SETTINGS_INFOへのポインタを指定します。
構造体NLED_SETTINGS_INFOの型は以下の通り。
(参考: Windows Embedded Developer Center)
struct NLED_SETTINGS_INFO {
UINT LedNum;
INT OffOnBlink;
LONG TotalCycleTime;
LONG OnTime;
LONG OffTime;
INT MetaCycleOn;
INT MetaCycleOff;
};
各メンバは以下の通り。
- LedNum LED number. The first LED is zero (0).
- OffOnBlink Current setting. The following table shows the defined values.
- 0 Off
- 1 On
- 2 Blink
- TotalCycleTime Total cycle time of a blink, in microseconds.
- OnTime On time of the cycle, in microseconds.
- OffTime Off time of the cycle, in microseconds.
- MetaCycleOn Number of on blink cycles.
- MetaCycleOff Number of off blink cycles.
今、試している機種(hTc Z)ではバイブはLedNumは1になるようです。
これは機種ごとに違う可能性が高いです。
OffOnBlinkは指定されている値から選択します。
バイブをオンにする場合は1 On、オフにする場合は0 Offを指定します。
Off/Onだけの場合は他の値を無視しても問題なさそうです。
OffOnBlinkを2 Blinkにした場合は設定すると思われ。
でも使ってないので調べていません。
具体例
具体的に関数として作るとしたら以下のようになります。
void VIB_On( void )
{
struct NLED_SETTINGS_INFO info = { 0 };
info.LedNum = (UINT)1; info.OffOnBlink = (INT)1;
NLedSetDevice( NLED_SETTINGS_INFO_ID, (void*)( &info ) ); }
void VIB_Off( void )
{
struct NLED_SETTINGS_INFO info = { 0 };
info.LedNum = (UINT)1; info.OffOnBlink = (INT)0;
NLedSetDevice( NLED_SETTINGS_INFO_ID, (void*)( &info ) ); }
もっとちゃんと作るとしたらNLedSetDevice()の戻り値をチェックしてFALSEの時はエラー処理をしましょう。
(多分、エラー表示だけになると思いますけど。)
補足
LedNumに0を指定したら充電ランプが点滅しました。
OffOnBlinkは1 Onにしたのに何故2 Blinkみたいな動作をしたのかは謎。