optimize - use pointer to wpad data

This commit is contained in:
dborth 2009-10-13 00:49:08 +00:00
parent bcf39c640c
commit e35145ec94
11 changed files with 104 additions and 87 deletions

View File

@ -216,7 +216,8 @@ class GuiTrigger
u8 type; //!< trigger type (TRIGGER_SIMPLE, TRIGGER_HELD, TRIGGER_BUTTON_ONLY, TRIGGER_BUTTON_ONLY_IN_FOCUS)
s32 chan; //!< Trigger controller channel (0-3, -1 for all)
WPADData wpad; //!< Wii controller trigger data
WPADData * wpad; //!< Wii controller trigger
WPADData wpaddata; //!< Wii controller trigger data
PADData pad; //!< GameCube controller trigger data
};

View File

@ -161,9 +161,9 @@ void GuiButton::Update(GuiTrigger * t)
#ifdef HW_RVL
// cursor
if(t->wpad.ir.valid && t->chan >= 0)
if(t->wpad->ir.valid && t->chan >= 0)
{
if(this->IsInside(t->wpad.ir.x, t->wpad.ir.y))
if(this->IsInside(t->wpad->ir.x, t->wpad->ir.y))
{
if(state == STATE_DEFAULT) // we weren't on the button before!
{
@ -209,24 +209,24 @@ void GuiButton::Update(GuiTrigger * t)
if(trigger[i] && (trigger[i]->chan == -1 || trigger[i]->chan == t->chan))
{
// higher 16 bits only (wiimote)
wm_btns = t->wpad.btns_d << 16;
wm_btns_trig = trigger[i]->wpad.btns_d << 16;
wm_btns = t->wpad->btns_d << 16;
wm_btns_trig = trigger[i]->wpad->btns_d << 16;
// lower 16 bits only (classic controller)
cc_btns = t->wpad.btns_d >> 16;
cc_btns_trig = trigger[i]->wpad.btns_d >> 16;
cc_btns = t->wpad->btns_d >> 16;
cc_btns_trig = trigger[i]->wpad->btns_d >> 16;
if(
(t->wpad.btns_d > 0 &&
(t->wpad->btns_d > 0 &&
(wm_btns == wm_btns_trig ||
(cc_btns == cc_btns_trig && t->wpad.exp.type == EXP_CLASSIC))) ||
(cc_btns == cc_btns_trig && t->wpad->exp.type == EXP_CLASSIC))) ||
(t->pad.btns_d == trigger[i]->pad.btns_d && t->pad.btns_d > 0))
{
if(t->chan == stateChan || stateChan == -1)
{
if(state == STATE_SELECTED)
{
if(!t->wpad.ir.valid || this->IsInside(t->wpad.ir.x, t->wpad.ir.y))
if(!t->wpad->ir.valid || this->IsInside(t->wpad->ir.x, t->wpad->ir.y))
{
this->SetState(STATE_CLICKED, t->chan);
@ -259,19 +259,19 @@ void GuiButton::Update(GuiTrigger * t)
if(trigger[i] && (trigger[i]->chan == -1 || trigger[i]->chan == t->chan))
{
// higher 16 bits only (wiimote)
wm_btns = t->wpad.btns_d << 16;
wm_btns_h = t->wpad.btns_h << 16;
wm_btns_trig = trigger[i]->wpad.btns_h << 16;
wm_btns = t->wpad->btns_d << 16;
wm_btns_h = t->wpad->btns_h << 16;
wm_btns_trig = trigger[i]->wpad->btns_h << 16;
// lower 16 bits only (classic controller)
cc_btns = t->wpad.btns_d >> 16;
cc_btns_h = t->wpad.btns_h >> 16;
cc_btns_trig = trigger[i]->wpad.btns_h >> 16;
cc_btns = t->wpad->btns_d >> 16;
cc_btns_h = t->wpad->btns_h >> 16;
cc_btns_trig = trigger[i]->wpad->btns_h >> 16;
if(
(t->wpad.btns_d > 0 &&
(t->wpad->btns_d > 0 &&
(wm_btns == wm_btns_trig ||
(cc_btns == cc_btns_trig && t->wpad.exp.type == EXP_CLASSIC))) ||
(cc_btns == cc_btns_trig && t->wpad->exp.type == EXP_CLASSIC))) ||
(t->pad.btns_d == trigger[i]->pad.btns_h && t->pad.btns_d > 0))
{
if(trigger[i]->type == TRIGGER_HELD && state == STATE_SELECTED &&
@ -280,9 +280,9 @@ void GuiButton::Update(GuiTrigger * t)
}
if(
(t->wpad.btns_h > 0 &&
(t->wpad->btns_h > 0 &&
(wm_btns_h == wm_btns_trig ||
(cc_btns_h == cc_btns_trig && t->wpad.exp.type == EXP_CLASSIC))) ||
(cc_btns_h == cc_btns_trig && t->wpad->exp.type == EXP_CLASSIC))) ||
(t->pad.btns_h == trigger[i]->pad.btns_h && t->pad.btns_h > 0))
{
if(trigger[i]->type == TRIGGER_HELD)

View File

@ -239,12 +239,12 @@ void GuiFileBrowser::Update(GuiTrigger * t)
// move the file listing to respond to wiimote cursor movement
if(scrollbarBoxBtn->GetState() == STATE_HELD &&
scrollbarBoxBtn->GetStateChan() == t->chan &&
t->wpad.ir.valid &&
t->wpad->ir.valid &&
browser.numEntries > FILE_PAGESIZE
)
{
scrollbarBoxBtn->SetPosition(0,0);
positionWiimote = t->wpad.ir.y - 60 - scrollbarBoxBtn->GetTop();
positionWiimote = t->wpad->ir.y - 60 - scrollbarBoxBtn->GetTop();
if(positionWiimote < scrollbarBoxBtn->GetMinY())
positionWiimote = scrollbarBoxBtn->GetMinY();
@ -267,13 +267,13 @@ void GuiFileBrowser::Update(GuiTrigger * t)
if(arrowDownBtn->GetState() == STATE_HELD && arrowDownBtn->GetStateChan() == t->chan)
{
t->wpad.btns_h |= WPAD_BUTTON_DOWN;
t->wpad->btns_h |= WPAD_BUTTON_DOWN;
if(!this->IsFocused())
((GuiWindow *)this->GetParent())->ChangeFocus(this);
}
else if(arrowUpBtn->GetState() == STATE_HELD && arrowUpBtn->GetStateChan() == t->chan)
{
t->wpad.btns_h |= WPAD_BUTTON_UP;
t->wpad->btns_h |= WPAD_BUTTON_UP;
if(!this->IsFocused())
((GuiWindow *)this->GetParent())->ChangeFocus(this);
}
@ -395,7 +395,7 @@ void GuiFileBrowser::Update(GuiTrigger * t)
int currChan = t->chan;
if(t->wpad.ir.valid && !fileList[i]->IsInside(t->wpad.ir.x, t->wpad.ir.y))
if(t->wpad->ir.valid && !fileList[i]->IsInside(t->wpad->ir.x, t->wpad->ir.y))
t->chan = -1;
fileList[i]->Update(t);

View File

@ -281,7 +281,7 @@ void GuiOptionBrowser::Update(GuiTrigger * t)
int currChan = t->chan;
if(t->wpad.ir.valid && !optionBtn[i]->IsInside(t->wpad.ir.x, t->wpad.ir.y))
if(t->wpad->ir.valid && !optionBtn[i]->IsInside(t->wpad->ir.x, t->wpad->ir.y))
t->chan = -1;
optionBtn[i]->Update(t);

View File

@ -389,11 +389,11 @@ void GuiSaveBrowser::Update(GuiTrigger * t)
else if(focus && i == selectedItem && saveBtn[i]->GetState() == STATE_DEFAULT)
saveBtn[selectedItem]->SetState(STATE_SELECTED, t->chan);
if(t->wpad.ir.valid)
if(t->wpad->ir.valid)
{
if(!saveBtnLastOver[i] && saveBtn[i]->IsInside(t->wpad.ir.x, t->wpad.ir.y))
if(!saveBtnLastOver[i] && saveBtn[i]->IsInside(t->wpad->ir.x, t->wpad->ir.y))
saveBtn[i]->ResetState();
saveBtnLastOver[i] = saveBtn[i]->IsInside(t->wpad.ir.x, t->wpad.ir.y);
saveBtnLastOver[i] = saveBtn[i]->IsInside(t->wpad->ir.x, t->wpad->ir.y);
}
saveBtn[i]->Update(t);

View File

@ -18,8 +18,9 @@ static int scrollDelay = 0;
GuiTrigger::GuiTrigger()
{
chan = -1;
memset(&wpad, 0, sizeof(WPADData));
memset(&wpaddata, 0, sizeof(WPADData));
memset(&pad, 0, sizeof(PADData));
wpad = &wpaddata;
}
/**
@ -38,7 +39,7 @@ void GuiTrigger::SetSimpleTrigger(s32 ch, u32 wiibtns, u16 gcbtns)
{
type = TRIGGER_SIMPLE;
chan = ch;
wpad.btns_d = wiibtns;
wpaddata.btns_d = wiibtns;
pad.btns_d = gcbtns;
}
@ -51,7 +52,7 @@ void GuiTrigger::SetHeldTrigger(s32 ch, u32 wiibtns, u16 gcbtns)
{
type = TRIGGER_HELD;
chan = ch;
wpad.btns_h = wiibtns;
wpaddata.btns_h = wiibtns;
pad.btns_h = gcbtns;
}
@ -63,7 +64,7 @@ void GuiTrigger::SetButtonOnlyTrigger(s32 ch, u32 wiibtns, u16 gcbtns)
{
type = TRIGGER_BUTTON_ONLY;
chan = ch;
wpad.btns_d = wiibtns;
wpaddata.btns_d = wiibtns;
pad.btns_d = gcbtns;
}
@ -76,7 +77,7 @@ void GuiTrigger::SetButtonOnlyInFocusTrigger(s32 ch, u32 wiibtns, u16 gcbtns)
{
type = TRIGGER_BUTTON_ONLY_IN_FOCUS;
chan = ch;
wpad.btns_d = wiibtns;
wpaddata.btns_d = wiibtns;
pad.btns_d = gcbtns;
}
@ -93,27 +94,27 @@ s8 GuiTrigger::WPAD_Stick(u8 right, int axis)
float mag = 0.0;
float ang = 0.0;
switch (wpad.exp.type)
switch (wpad->exp.type)
{
case WPAD_EXP_NUNCHUK:
case WPAD_EXP_GUITARHERO3:
if (right == 0)
{
mag = wpad.exp.nunchuk.js.mag;
ang = wpad.exp.nunchuk.js.ang;
mag = wpad->exp.nunchuk.js.mag;
ang = wpad->exp.nunchuk.js.ang;
}
break;
case WPAD_EXP_CLASSIC:
if (right == 0)
{
mag = wpad.exp.classic.ljs.mag;
ang = wpad.exp.classic.ljs.ang;
mag = wpad->exp.classic.ljs.mag;
ang = wpad->exp.classic.ljs.ang;
}
else
{
mag = wpad.exp.classic.rjs.mag;
ang = wpad.exp.classic.rjs.ang;
mag = wpad->exp.classic.rjs.mag;
ang = wpad->exp.classic.rjs.ang;
}
break;
@ -142,12 +143,12 @@ bool GuiTrigger::Left()
{
u32 wiibtn = GCSettings.WiimoteOrientation ? WPAD_BUTTON_UP : WPAD_BUTTON_LEFT;
if((wpad.btns_d | wpad.btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_LEFT)
if((wpad->btns_d | wpad->btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_LEFT)
|| (pad.btns_d | pad.btns_h) & PAD_BUTTON_LEFT
|| pad.stickX < -PADCAL
|| WPAD_Stick(0,0) < -PADCAL)
{
if(wpad.btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_LEFT)
if(wpad->btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_LEFT)
|| pad.btns_d & PAD_BUTTON_LEFT)
{
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.
@ -171,12 +172,12 @@ bool GuiTrigger::Right()
{
u32 wiibtn = GCSettings.WiimoteOrientation ? WPAD_BUTTON_DOWN : WPAD_BUTTON_RIGHT;
if((wpad.btns_d | wpad.btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_RIGHT)
if((wpad->btns_d | wpad->btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_RIGHT)
|| (pad.btns_d | pad.btns_h) & PAD_BUTTON_RIGHT
|| pad.stickX > PADCAL
|| WPAD_Stick(0,0) > PADCAL)
{
if(wpad.btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_RIGHT)
if(wpad->btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_RIGHT)
|| pad.btns_d & PAD_BUTTON_RIGHT)
{
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.
@ -200,12 +201,12 @@ bool GuiTrigger::Up()
{
u32 wiibtn = GCSettings.WiimoteOrientation ? WPAD_BUTTON_RIGHT : WPAD_BUTTON_UP;
if((wpad.btns_d | wpad.btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_UP)
if((wpad->btns_d | wpad->btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_UP)
|| (pad.btns_d | pad.btns_h) & PAD_BUTTON_UP
|| pad.stickY > PADCAL
|| WPAD_Stick(0,1) > PADCAL)
{
if(wpad.btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_UP)
if(wpad->btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_UP)
|| pad.btns_d & PAD_BUTTON_UP)
{
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.
@ -229,12 +230,12 @@ bool GuiTrigger::Down()
{
u32 wiibtn = GCSettings.WiimoteOrientation ? WPAD_BUTTON_LEFT : WPAD_BUTTON_DOWN;
if((wpad.btns_d | wpad.btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_DOWN)
if((wpad->btns_d | wpad->btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_DOWN)
|| (pad.btns_d | pad.btns_h) & PAD_BUTTON_DOWN
|| pad.stickY < -PADCAL
|| WPAD_Stick(0,1) < -PADCAL)
{
if(wpad.btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_DOWN)
if(wpad->btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_DOWN)
|| pad.btns_d & PAD_BUTTON_DOWN)
{
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.

View File

@ -195,7 +195,7 @@ void GuiWindow::ToggleFocus(GuiTrigger * t)
}
}
// change focus
else if(t->wpad.btns_d & (WPAD_BUTTON_1 | WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B)
else if(t->wpad->btns_d & (WPAD_BUTTON_1 | WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B)
|| t->pad.btns_d & PAD_BUTTON_B)
{
for (i = found; i < _elements.size(); i++)

View File

@ -145,7 +145,7 @@ void ResetControls(int wiiCtrl)
/****************************************************************************
* UpdatePads
*
* called by PostRetraceCallback in InitGCVideo - scans pad and wpad
* Scans pad and wpad
***************************************************************************/
void
UpdatePads()
@ -157,11 +157,6 @@ UpdatePads()
for(int i=3; i >= 0; i--)
{
#ifdef HW_RVL
memcpy(&userInput[i].wpad, WPAD_Data(i), sizeof(WPADData));
#endif
userInput[i].chan = i;
userInput[i].pad.btns_d = PAD_ButtonsDown(i);
userInput[i].pad.btns_u = PAD_ButtonsUp(i);
userInput[i].pad.btns_h = PAD_ButtonsHeld(i);
@ -174,6 +169,33 @@ UpdatePads()
}
}
/****************************************************************************
* SetupPads
*
* Sets up userInput triggers for use
***************************************************************************/
void
SetupPads()
{
PAD_Init();
#ifdef HW_RVL
WPAD_Init();
// read wiimote accelerometer and IR data
WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR);
WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight);
#endif
for(int i=0; i < 4; i++)
{
userInput[i].chan = i;
#ifdef HW_RVL
userInput[i].wpad = WPAD_Data(i);
#endif
}
}
#ifdef HW_RVL
/****************************************************************************
@ -770,9 +792,9 @@ static u32 DecodeJoy(unsigned short pad)
CursorVisible = false;
#ifdef HW_RVL
CursorX = userInput[pad].wpad.ir.x;
CursorY = userInput[pad].wpad.ir.y;
CursorValid = userInput[pad].wpad.ir.valid;
CursorX = userInput[pad].wpad->ir.x;
CursorY = userInput[pad].wpad->ir.y;
CursorValid = userInput[pad].wpad->ir.valid;
#else
CursorX = CursorY = CursorValid = 0;
#endif
@ -973,9 +995,9 @@ static u32 DecodeJoy(unsigned short pad)
{
if ((userInput[pad].pad.btns_h & btnmap[CTRLR_GCPAD][i]) // gamecube controller
#ifdef HW_RVL
|| ( (userInput[pad].wpad.exp.type == WPAD_EXP_NONE) && (userInput[pad].wpad.btns_h & btnmap[CTRLR_WIIMOTE][i]) ) // wiimote
|| ( (userInput[pad].wpad.exp.type == WPAD_EXP_CLASSIC) && (userInput[pad].wpad.btns_h & btnmap[CTRLR_CLASSIC][i]) ) // classic controller
|| ( (userInput[pad].wpad.exp.type == WPAD_EXP_NUNCHUK) && (userInput[pad].wpad.btns_h & btnmap[CTRLR_NUNCHUK][i]) ) // nunchuk + wiimote
|| ( (userInput[pad].wpad->exp.type == WPAD_EXP_NONE) && (userInput[pad].wpad->btns_h & btnmap[CTRLR_WIIMOTE][i]) ) // wiimote
|| ( (userInput[pad].wpad->exp.type == WPAD_EXP_CLASSIC) && (userInput[pad].wpad->btns_h & btnmap[CTRLR_CLASSIC][i]) ) // classic controller
|| ( (userInput[pad].wpad->exp.type == WPAD_EXP_NUNCHUK) && (userInput[pad].wpad->btns_h & btnmap[CTRLR_NUNCHUK][i]) ) // nunchuk + wiimote
|| ( (DownUsbKeys[btnmap[CTRLR_KEYBOARD][i]]) ) // keyboard
#endif
)
@ -991,8 +1013,8 @@ bool MenuRequested()
{
if (
(userInput[i].pad.substickX < -70) ||
(userInput[i].wpad.btns_h & WPAD_BUTTON_HOME) ||
(userInput[i].wpad.btns_h & WPAD_CLASSIC_BUTTON_HOME) ||
(userInput[i].wpad->btns_h & WPAD_BUTTON_HOME) ||
(userInput[i].wpad->btns_h & WPAD_CLASSIC_BUTTON_HOME) ||
(DownUsbKeys[KS_Escape])
)
{

View File

@ -43,6 +43,7 @@ void updateRumbleFrame();
s8 WPAD_Stick(u8 chan,u8 right, int axis);
u32 GetJoy(int which);
bool MenuRequested();
void SetupPads();
void UpdatePads();
#endif

View File

@ -258,9 +258,9 @@ UpdateGUI (void *arg)
#ifdef HW_RVL
for(i=3; i >= 0; i--) // so that player 1's cursor appears on top!
{
if(userInput[i].wpad.ir.valid)
Menu_DrawImg(userInput[i].wpad.ir.x-48, userInput[i].wpad.ir.y-48,
96, 96, pointer[i]->GetImage(), userInput[i].wpad.ir.angle, 1, 1, 255);
if(userInput[i].wpad->ir.valid)
Menu_DrawImg(userInput[i].wpad->ir.x-48, userInput[i].wpad->ir.y-48,
96, 96, pointer[i]->GetImage(), userInput[i].wpad->ir.angle, 1, 1, 255);
DoRumble(i);
}
#endif
@ -813,9 +813,9 @@ static void WindowCredits(void * ptr)
for(i=3; i >= 0; i--)
{
#ifdef HW_RVL
if(userInput[i].wpad.ir.valid)
Menu_DrawImg(userInput[i].wpad.ir.x-48, userInput[i].wpad.ir.y-48,
96, 96, pointer[i]->GetImage(), userInput[i].wpad.ir.angle, 1, 1, 255);
if(userInput[i].wpad->ir.valid)
Menu_DrawImg(userInput[i].wpad->ir.x-48, userInput[i].wpad->ir.y-48,
96, 96, pointer[i]->GetImage(), userInput[i].wpad->ir.angle, 1, 1, 255);
DoRumble(i);
#endif
}
@ -824,7 +824,7 @@ static void WindowCredits(void * ptr)
for(i=0; i < 4; i++)
{
if(userInput[i].wpad.btns_d || userInput[i].pad.btns_d)
if(userInput[i].wpad->btns_d || userInput[i].pad.btns_d)
exit = true;
}
usleep(THREAD_SLEEP);
@ -833,7 +833,7 @@ static void WindowCredits(void * ptr)
// clear buttons pressed
for(i=0; i < 4; i++)
{
userInput[i].wpad.btns_d = 0;
userInput[i].wpad->btns_d = 0;
userInput[i].pad.btns_d = 0;
}
@ -1289,7 +1289,7 @@ static int MenuGame()
if(WPAD_Probe(i, NULL) == WPAD_ERR_NONE)
{
newStatus = true;
newLevel = (userInput[i].wpad.battery_level / 100.0) * 4;
newLevel = (userInput[i].wpad->battery_level / 100.0) * 4;
if(newLevel > 4) newLevel = 4;
}
else
@ -2224,7 +2224,7 @@ ButtonMappingWindow()
userInput[0].pad.substickY > 70)
pressed = WPAD_BUTTON_HOME;
if(userInput[0].wpad.btns_d == WPAD_BUTTON_HOME)
if(userInput[0].wpad->btns_d == WPAD_BUTTON_HOME)
pressed = WPAD_BUTTON_HOME;
}
else if(mapMenuCtrl == CTRLR_KEYBOARD)
@ -2236,12 +2236,12 @@ ButtonMappingWindow()
break;
}
}
if(userInput[0].wpad.btns_d == WPAD_BUTTON_HOME)
if(userInput[0].wpad->btns_d == WPAD_BUTTON_HOME)
pressed = KS_Escape;
}
else
{
pressed = userInput[0].wpad.btns_d;
pressed = userInput[0].wpad->btns_d;
// always allow Home button to be pressed to cancel
if(pressed != WPAD_BUTTON_HOME)
@ -2254,14 +2254,14 @@ ButtonMappingWindow()
break;
case CTRLR_CLASSIC:
if(userInput[0].wpad.exp.type != WPAD_EXP_CLASSIC)
if(userInput[0].wpad->exp.type != WPAD_EXP_CLASSIC)
pressed = 0; // not a valid input
else if(pressed <= 0x1000)
pressed = 0;
break;
case CTRLR_NUNCHUK:
if(userInput[0].wpad.exp.type != WPAD_EXP_NUNCHUK)
if(userInput[0].wpad->exp.type != WPAD_EXP_NUNCHUK)
pressed = 0; // not a valid input
break;
}

View File

@ -250,20 +250,12 @@ int main(int argc, char *argv[])
InitDeviceThread();
VIDEO_Init();
PAD_Init();
#ifdef HW_RVL
WPAD_Init();
#endif
SetupPads();
InitializeVideo();
ResetVideo_Menu (); // change to menu video mode
#ifdef HW_RVL
// read wiimote accelerometer and IR data
WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR);
WPAD_SetVRes(WPAD_CHAN_ALL,screenwidth,screenheight);
// Wii Power/Reset buttons
WPAD_SetPowerButtonCallback((WPADShutdownCallback)ShutdownCB);
SYS_SetPowerCallback(ShutdownCB);