// Now let's wait for either there is an update on registry, or
// there is user action on the device, or there is activity on
// AC power supply.
dwResult = WaitForMultipleObjects(NUM_EVENTS, &g_evtSignal[0], FALSE, dwTimeout);
// If we are signaled by registry event
if(WAIT_OBJECT_0 == dwResult) {
// All we need to do is to read from registry and update the tick count
BL_ReadRegistry(&g_BLInfo);
// Always turn on the Backlight after a change to registry
BL_On(TRUE);
}
else if(dwResult == WAIT_OBJECT_0+1) {
// User activity, depending on the situation, we may / may not update
// the tick count
if(IsACOn()) {
if(g_BLInfo.m_bACAuto) {
// Turn on backlight
BL_On(TRUE);
}
}
else {
if(g_BLInfo.m_bBatteryAuto) {
BL_On(TRUE);
}
}
}
else if(dwResult == WAIT_OBJECT_0+2) {
// When AC is plugged or un-plugged, we don't really need to do anything
// We continue the loop. The correct timeout value will be assigned at
// the top of the while loop.
RETAILMSG(1, (TEXT("BackLight Thread: power changed!\r\n")));
}
else if(dwResult == WAIT_TIMEOUT) {
// Time out, let's turn the device off
RETAILMSG(1, (TEXT("Timeout, turn off the backlight!\r\n")));
BL_On(FALSE);
}