#ifdef LOOK_FOR_ADDITIONAL_WIIMOTES
// try to connect any additional wiimotes (just to show the code)
_tprintf(_T("\n\n")); // [1]
wiimote *extra_motes [7] = { NULL }; // 7 should cover it [2]
unsigned detected = 0;
while(detected < 7)
{
wiimote *next = new wiimote; // [3]
if(!next->Connect(wiimote::FIRST_AVAILABLE)) // [4]
break;
extra_motes[detected++] = next; // [5]
WHITE ; _tprintf(_T(" also found wiimote ")); // [6]
BRIGHT_GREEN; _tprintf(_T("%u"), detected+1); // [7]
if(next->IsBalanceBoard()) { // [8]
WHITE; _tprintf(_T(" (Balance Board)"));
}
_tprintf(_T("\n\n"));
# ifdef USE_BEEPS_AND_DELAYS
Beep(1000 + (detected*100), 100); // [9]
Sleep(500);
# endif
}
WHITE; _tprintf( ((detected == 7)? _T(" (can't detect any more).") :
_T(" (no more found).")) );
# ifdef USE_BEEPS_AND_DELAYS
Sleep(2000);
# endif
// clean up
for(unsigned index=0; index<detected; index++)
delete extra_motes[index];
SetConsoleCursorPosition(console, cursor_pos);
#endif // LOOK_FOR_ADDITIONAL_WIIMOTES
[1] 即printf
[2] class wiimote : public wiimote_state , 7表示最多可能裝置數量
[3] wiimote *next = new wiimote; 創建一個wiimote物件叫做 next
[4] next->Connect(wiimote::FIRST_AVAILABLE) 連線失敗回傳false
[5] 表示[4]連線成功, 並將之存入extra_motes陣列內
[6] (白色字)列印" also found wiimote "
[7] (亮綠字)列印 發現裝置編號
[8] next->IsBalanceBoard() 判斷是否為 Balance Board, 若是則(白色字)列印"(Balance Board)"
[9] Beep(1000 + (detected*100), 100): 根據裝置編號決定Beep頻率
-----------------------------------------------------------------------------------------------------
搜尋下列關鍵字 case wiimote_state::BALANCE_BOARD:
case wiimote_state::BALANCE_BOARD:
{
BRIGHT_WHITE; _tprintf(_T("Balance Board"));
// Weights:
CYAN ; _tprintf(_T(" Weight: "));
WHITE; _tprintf(_T("TL "));
_tprintf(_T("%6.2f"), remote.BalanceBoard.Kg.TopL); [1]
CYAN ; _tprintf(_T(" kg")); WHITE; ;_tprintf(_T(" TR "));
_tprintf(_T("%6.2f"), remote.BalanceBoard.Kg.TopR); [2]
CYAN; _tprintf(_T(" kg\n")); WHITE;
_tprintf(_T(" BL "));
_tprintf(_T("%6.2f"), remote.BalanceBoard.Kg.BottomL); [3]
CYAN; _tprintf(_T(" kg")); WHITE; _tprintf(_T(" BR "));
_tprintf(_T("%6.2f"), remote.BalanceBoard.Kg.BottomR); [4]
CYAN; _tprintf(_T(" kg \n")); WHITE;
_tprintf(_T(" Total "));
_tprintf(_T("%6.2f"), remote.BalanceBoard.Kg.Total); [5]
CYAN; _tprintf(_T(" kg"));
}
break;
[1] remote.BalanceBoard.Kg.TopL 左上角區域重量
[2] remote.BalanceBoard.Kg.TopR 右上角區域重量
[3] remote.BalanceBoard.Kg.BottomL 左下角區域重量
[4] remote.BalanceBoard.Kg.BottomR 右下角區域重量
[5] remote.BalanceBoard.Kg.Total 全部重量
int _tmain ()
{
SetConsoleTitle(_T("- WiiYourself! - Demo: "));
HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
// write the title
PrintTitle(console);
// let's load a couple of samples:
wiimote_sample sine_sample, daisy_sample;
// one .raw (just to demonstrate it)
if(!wiimote::Load16BitMonoSampleRAW(_T("1kSine16 (3130).raw"),
true, FREQ_3130HZ, sine_sample)) {
_tprintf(_T("\r ** can't find 'Sine16 (3130).raw' - (sample won't work!) **"));
Beep(100, 1000);
Sleep(3000);
_tprintf(_T("\r") BLANK_LINE);
}
// and one (more convenient) .wav
if(!wiimote::Load16bitMonoSampleWAV(_T("Daisy16 (3130).wav"), daisy_sample)) {
_tprintf(_T("\r ** can't find 'Daisy16 (3130).wav' - (sample won't work!) **"));
Beep(100, 1000);
Sleep(3000);
_tprintf(_T("\r") BLANK_LINE);
}
// create a wiimote object
wiimote remote;
// in this demo we use a state-change callback to get notified of
// extension-related events, and polling for everything else
// (note you don't have to use both, use whatever suits your app):
remote.ChangedCallback = on_state_change;
// notify us only when the wiimote connected sucessfully, or something
// related to extensions changes
remote.CallbackTriggerFlags = (state_change_flags)(CONNECTED |
EXTENSION_CHANGED |
MOTIONPLUS_CHANGED);
// ------------------------------------------------------------------------------------
// state-change callback example (we use polling for everything else):
// ------------------------------------------------------------------------------------
void on_state_change (wiimote &remote,
state_change_flags changed,
const wiimote_state &new_state)
{
// we use this callback to set report types etc. to respond to key events
// (like the wiimote connecting or extensions (dis)connecting).
...........
}
留言列表