lllogitechlcd.cpp

Go to the documentation of this file.
00001 
00032 #include "llpreprocessor.h"
00033 
00034 #if LL_LCD_COMPILE
00035 
00036 #include "linden_common.h"
00037 #include "../win_crash_logger/StdAfx.h"
00038 
00039 #include "EZ_LCD.h"
00040 #include "../newview/res/resource.h"
00041 #include "llcontrol.h"
00042 extern LLControlGroup gSavedSettings;
00043 
00044 #ifndef LL_LOGITECH_LCD_H
00045 #include "lllogitechlcd.h"
00046 #endif
00047 
00048 #define WAIT_DURATION 7
00049 #define DEBOUNCE_DURATION 0.3f
00050 
00051 llLCDPageGroup::llLCDPageGroup(CEzLcd *LCD, int type, HICON SLIcon):
00052 mType(type),
00053 mSLIcon(SLIcon),
00054 mDisplayPage(false),
00055 mLCD(LCD)
00056 {
00057         mPageArray.clear();     
00058 }
00059 
00060 llLCDPageGroup::~llLCDPageGroup()
00061 {
00062         mPageArray.clear();
00063 }
00064 
00065 void llDefaultPageGroup::UpdateDetails()
00066 {
00067         mLCD->ModifyControlsOnPage(mPageArray[0].mPageIndex);
00068 }
00069 
00070 void llDefaultPageGroup::GetDisplayable()
00071 {
00072 
00073 }
00074 
00075 llDefaultPageGroup::llDefaultPageGroup(CEzLcd *LCD, int type, HICON SLIcon)
00076 :llLCDPageGroup(LCD, type, SLIcon)
00077 {
00078         // create a new specific page
00079         llLCDSpecificPage newPage;
00080         newPage.mPageIndex = mLCD->AddNewPage() - 1;
00081         mLCD->ModifyControlsOnPage(newPage.mPageIndex);
00082 
00083         // add in all the display parts for this specific page
00084 
00085         // add in the icon - all pages have this - we don't need to track this because we never update it
00086         HANDLE m_rightIcon = mLCD->AddIcon(mSLIcon, 32, 32);
00087         mLCD->SetOrigin(m_rightIcon, 0, 0);
00088 
00089         // add Title
00090         HANDLE title = mLCD->AddText(LG_STATIC_TEXT, LG_MEDIUM, DT_CENTER, 128);
00091         mLCD->SetOrigin(title, 32, 20);
00092         mLCD->SetText(title, _T("Second Life Display"));
00093         newPage.mDisplayItemArray.push_back(title);
00094 
00095         // and then insert it
00096         mPageArray.push_back(newPage);
00097 }
00098 
00099 llLCD::llLCD(HINSTANCE instance):
00100 mInited(false),
00101 mDisplayTimer(),
00102 mDebounceTimer(),
00103 mPageToShow(-1),
00104 mInstance(instance),
00105 mDestinationLCD(-1),
00106 mFirstTimeThru(true)
00107 {
00108         HRESULT     res_ = S_OK;
00109 
00110         // Create instance of EzLcd.
00111         mLCD = new CEzLcd();
00112 
00113         // Have it initialize itself
00114         res_ = mLCD->InitYourself(_T("Second Life"));
00115 
00116         if (res_ != S_OK)
00117         {
00118                 // Something went wrong, when connecting to the LCD Manager software. We need to get out now
00119                 delete mLCD;
00120                 return;
00121         }
00122         mInited = true;
00123 
00124         // preload the Second Life Icon
00125         mSLIcon = static_cast<HICON>(LoadImage(mInstance,
00126                 MAKEINTRESOURCE(IDI_LCD_LL_ICON),
00127                 IMAGE_ICON, 
00128                 32, 
00129                 32, 
00130                 LR_MONOCHROME));
00131 
00132         // have to do this first so screens are added to the list and updateDisplay actually does something.
00133         mLCD->Update();
00134 }
00135 
00136 llLCD::~llLCD()
00137 {
00138         // remove the instance of the LCD controller
00139         if (mInited == true)
00140         {
00141                 delete mLCD;
00142 
00143                 // free up the used pages
00144                 int loopSize = mPageGroupArray.size();
00145                 for(int i= 0; i<loopSize; i++)
00146                 {
00147                         free (mPageGroupArray[i]);
00148                 }
00149         }
00150 }
00151 
00152 llLCDPageGroup *llLCD::GetNextPageToDisplay()
00153 {
00154         // find group with current page in it.
00155 
00156         int groupSize = mPageGroupArray.size();
00157         for(int x=1; x< groupSize; x++)
00158         {
00159                 if (mPageGroupArray[x]->mDisplayPage)
00160                 {
00161                         // now walk all the pages in the page group we are looking at
00162                         int numPages = mPageGroupArray[x]->mPageArray.size();
00163                         for (int zx = 0; zx< numPages; zx++)
00164                         {
00165                                 // found it.
00166                                 if (mPageToShow == mPageGroupArray[x]->mPageArray[zx].mPageIndex)
00167                                 {
00168                                         // move to the next one
00169                                         if (zx < numPages-1)
00170                                         {
00171                                                 mPageToShow = mPageGroupArray[x]->mPageArray[zx+1].mPageIndex;
00172                                                 return mPageGroupArray[x];
00173                                         }
00174                                         else
00175                                         {
00176                                                 for(int y=x+1; y< groupSize; y++)
00177                                                 {
00178                                                         if (mPageGroupArray[y]->mDisplayPage)
00179                                                         {
00180                                                                 mPageToShow = mPageGroupArray[y]->mPageArray[0].mPageIndex;
00181                                                                 return mPageGroupArray[y];
00182                                                         }
00183                                                 }
00184                                         }
00185                                 }
00186                         }
00187                 }
00188         }
00189 
00190         // ok, didn't find it. Start again at the beginning and find the first group that's enabled
00191         for(int x=1; x< groupSize; x++)
00192         {
00193                 if (mPageGroupArray[x]->mDisplayPage)
00194                 {
00195                         mPageToShow = mPageGroupArray[x]->mPageArray[0].mPageIndex;
00196                         return mPageGroupArray[x];
00197                 }
00198         }
00199         // if we got this far, we should display the default screen
00200         mPageToShow = mPageGroupArray[0]->mPageArray[0].mPageIndex;
00201         return mPageGroupArray[0];
00202 }
00203 
00204 void llLCD::SetUpDisplayPages()
00205 {
00206         // work out if destination has changed
00207         int destinationLCD = gSavedSettings.getS32("LCDDestination");
00208         switch(destinationLCD)
00209         {
00210         case 0:
00211                 destinationLCD = LGLCD_DEVICE_FAMILY_KEYBOARD_G15;
00212                 break;
00213         case 1:
00214                 destinationLCD = LGLCD_DEVICE_FAMILY_SPEAKERS_Z10;
00215                 break;
00216         }
00217         // set destination if it's changed
00218         if (mDestinationLCD != destinationLCD)
00219         {
00220                 mDestinationLCD = destinationLCD;
00221                 mLCD->SetDeviceFamilyToUse(destinationLCD);
00222         }
00223         int loopSize = mPageGroupArray.size();
00224         for(int i= 0; i<loopSize; i++)
00225         {
00226                 mPageGroupArray[i]->GetDisplayable();
00227         }
00228 }
00229 
00230 void llLCD::UpdateDisplay()
00231 {
00232         if (mInited)
00233         {
00234                 // reset pages if anything has changed
00235                 SetUpDisplayPages();
00236                 if (mLCD->IsConnected())
00237                 {               
00238                         // Switching back and forth between the pages that we've created
00239                         if (mDisplayTimer.getElapsedTimeF32() > WAIT_DURATION || mFirstTimeThru)
00240                         {
00241                                 mCurrentGroupBeingShown = GetNextPageToDisplay();
00242                                 mDisplayTimer.reset();
00243                                 mFirstTimeThru = false;
00244                         }
00245 
00246                         // Check if button 1 triggered
00247                         if ((mLCD->ButtonIsPressed(LG_BUTTON_1)
00248                                 || mLCD->ButtonIsPressed(LG_BUTTON_2)
00249                                 || mLCD->ButtonIsPressed(LG_BUTTON_3)
00250                                 || mLCD->ButtonIsPressed(LG_BUTTON_4)
00251                                 ) && mDebounceTimer.getElapsedTimeF32() > DEBOUNCE_DURATION)
00252                         {
00253                                 // if so, move us on a page
00254                                 mCurrentGroupBeingShown = GetNextPageToDisplay();
00255                                 mDisplayTimer.reset();
00256                                 mDebounceTimer.reset();
00257                         }
00258 
00259                         // update that which is being show
00260                         mCurrentGroupBeingShown->UpdateDetails();
00261                         
00262                         // set which page is shown
00263                         mLCD->ShowPage(mPageToShow);
00264 
00265                         // Must run the following every loop.
00266                         mLCD->Update();
00267                 }
00268         }
00269 }
00270 
00271 
00272 // accessor functions
00273 bool llLCD::Enabled()
00274 {
00275         return mInited;
00276 }
00277 
00278 BOOL llLCD::AreZ10Available()
00279 {
00280         if (mInited == true)
00281         {
00282                 return mLCD->AnyDeviceOfThisFamilyPresent(LGLCD_DEVICE_FAMILY_SPEAKERS_Z10);
00283         }
00284         return false;
00285 }
00286 
00287 BOOL llLCD::IsG15Available()
00288 {
00289         if (mInited == true)
00290         {
00291                 return mLCD->AnyDeviceOfThisFamilyPresent(LGLCD_DEVICE_FAMILY_KEYBOARD_G15);
00292         }
00293         return false;
00294 }
00295 
00296 #endif

Generated on Thu Jul 1 06:08:49 2010 for Second Life Viewer by  doxygen 1.4.7