Nokia N97 SDK
Example Applications Guide

HWRMTestAppAppUi.cpp

00001 /*
00002 * ==============================================================================
00003 *  Name        : HWRMTestAppAppUi.cpp
00004 *  Part of     : HWRMTestApp
00005 *  Interface   : 
00006 *  Description : HWRM Test application UI implementation
00007 *  Version     : 
00008 *
00009 *  Copyright (c) 2002-2006 Nokia Corporation.
00010 *  This material, including documentation and any related 
00011 *  computer programs, is protected by copyright controlled by 
00012 *  Nokia Corporation. 
00013 * ==============================================================================
00014 */
00015 
00016 // INCLUDE FILES
00017 #include <aknNoteWrappers.h>
00018 #include <eikmenup.h>
00019 #include <avkon.hrh>
00020 #include <aknselectionlist.h>
00021 #include <HWRMPowerStateSDKPSKeys.h>
00022 #include <HWRMTestApp.rsg>
00023 #include "HWRMTestAppPropertyObserver.h"
00024 #include "HWRMTestAppAppUi.h"
00025 #include "HWRMTestAppContainer.h" 
00026 #include "HWRMTestApp.hrh"
00027 
00028 
00029 // ============================ MEMBER FUNCTIONS ===============================
00030 
00031 
00032 // -----------------------------------------------------------------------------
00033 // CHWRMTestAppAppUi::ConstructL
00034 // Symbian 2nd phase constructor can leave.
00035 // -----------------------------------------------------------------------------
00036 //
00037 void CHWRMTestAppAppUi::ConstructL()
00038     {
00039     BaseConstructL(CAknAppUi::EAknEnableSkin);
00040     iAppContainer = new (ELeave) CHWRMTestAppContainer;
00041     iAppContainer->SetMopParent(this);
00042     iAppContainer->ConstructL( ClientRect() );
00043     AddToStackL( iAppContainer );
00044     
00045     // We can ignore this error, simply dim the menus if 
00046     // pointer is null with the DynInitMenuPaneL method
00047     TRAPD( err, iLight = CHWRMLight::NewL(this) );
00048     if( err == KErrNotSupported )
00049         {
00050         _LIT( KLightNotSupported, "Light API Not Supported!" );
00051         iAppContainer->AddMessageL( KLightNotSupported );
00052         }
00053     else
00054         {
00055         PrintLightTargetsL();    
00056         }
00057     TRAP( err, iVibra = CHWRMVibra::NewL(this) );
00058     if( err == KErrNotSupported )
00059         {
00060         _LIT( KVibraNotSupported, "Vibra API Not Supported!" );
00061         iAppContainer->AddMessageL( KVibraNotSupported );
00062         }
00063 
00064     // Create the observers
00065     iBatteryStatusObserver = CHWRMTestAppPropertyObserver::NewL(
00066                     KPSUidHWRMPowerState,KHWRMBatteryStatus, iAppContainer );
00067     iBatteryLevelObserver = CHWRMTestAppPropertyObserver::NewL(
00068                     KPSUidHWRMPowerState,KHWRMBatteryLevel, iAppContainer );
00069     iChargingStatusObserver = CHWRMTestAppPropertyObserver::NewL(
00070                     KPSUidHWRMPowerState,KHWRMChargingStatus, iAppContainer );
00071     }
00072 
00073 // -----------------------------------------------------------------------------
00074 // CHWRMTestAppAppUi::~CHWRMTestAppAppUi
00075 // Destructor
00076 // Frees reserved resources
00077 // -----------------------------------------------------------------------------
00078 //
00079 CHWRMTestAppAppUi::~CHWRMTestAppAppUi()
00080     {
00081     // Delete the observers
00082     delete iBatteryStatusObserver;
00083     delete iBatteryLevelObserver;
00084     delete iChargingStatusObserver;
00085 
00086     delete iLight; // kill light
00087     delete iVibra; // kill vibra
00088 
00089     if(iAppContainer)
00090         {
00091         RemoveFromStack( iAppContainer );
00092         delete iAppContainer;
00093         }
00094     }
00095 
00096 // -----------------------------------------------------------------------------
00097 // CHWRMTestAppAppUi::::DynInitMenuPaneL
00098 //  This function is called by the EIKON framework just before it displays
00099 //  a menu pane. Its default implementation is empty, and by overriding it,
00100 //  the application can set the state of menu items dynamically according
00101 //  to the state of application data.
00102 // -----------------------------------------------------------------------------
00103 //
00104 void CHWRMTestAppAppUi::DynInitMenuPaneL(
00105     TInt aResourceId,CEikMenuPane* aMenuPane)
00106     {
00107     if( aResourceId==R_HWRMTESTAPP_MENU )
00108         {
00109         //the main application menu
00110         if( iLight )
00111             {
00112             //enable everything for lights
00113             aMenuPane->SetItemDimmed(EHWRMTestAppCmdLights,EFalse);
00114             }
00115         else
00116             {
00117             //dim everything for lights
00118             aMenuPane->SetItemDimmed(EHWRMTestAppCmdLights,ETrue);
00119             }
00120         if( iVibra )
00121             {
00122             //enable everything for vibra
00123             aMenuPane->SetItemDimmed(EHWRMTestAppCmdVibra,EFalse);
00124             }
00125         else
00126             {
00127             //dim everything for vibra
00128             aMenuPane->SetItemDimmed(EHWRMTestAppCmdVibra,ETrue);
00129             }
00130         }
00131         }
00132 
00133 // -----------------------------------------------------------------------------
00134 // CHWRMTestAppAppUi::HandleKeyEventL
00135 // Pass key event to app container
00136 // -----------------------------------------------------------------------------
00137 //
00138 TKeyResponse CHWRMTestAppAppUi::HandleKeyEventL(
00139     const TKeyEvent& aKeyEvent,TEventCode aType)
00140     {
00141     return iAppContainer->OfferKeyEventL( aKeyEvent, aType );
00142     }
00143 
00144 // -----------------------------------------------------------------------------
00145 // CHWRMTestAppAppUi::HandleCommandL
00146 // Handle command entered by user
00147 // -----------------------------------------------------------------------------
00148 //
00149 void CHWRMTestAppAppUi::HandleCommandL(TInt aCommand)
00150     {
00151     TInt err(KErrNone);
00152     
00153     switch ( aCommand )
00154         {
00155         case EAknSoftkeyBack:
00156         case EEikCmdExit:
00157             {
00158             Exit();
00159             break;
00160             }
00161         case EHWRMTestAppCmdVibraReserve:
00162             {
00163             _LIT(KReserveVibra, "Reserve vibra");
00164             iAppContainer->AddMessageL( KReserveVibra );
00165             TRAP( err, VibraReserveL() );
00166             break;
00167             }
00168         case EHWRMTestAppCmdVibraRelease:
00169             {
00170             _LIT(KReleaseVibra, "Release vibra");
00171             iAppContainer->AddMessageL( KReleaseVibra );
00172             TRAP( err, VibraReleaseL() );
00173             break;
00174             }
00175         case EHWRMTestAppCmdVibraStart:
00176             {
00177             _LIT(KStartVibra, "Start vibra");
00178             iAppContainer->AddMessageL( KStartVibra );
00179             TRAP( err, VibraStartL() );
00180             break;
00181             }
00182         case EHWRMTestAppCmdVibraStop:
00183             {
00184             _LIT(KStopVibra, "Stop vibra");
00185             iAppContainer->AddMessageL( KStopVibra );
00186             TRAP( err, VibraStopL() );
00187             break;
00188             }
00189         case EHWRMTestAppCmdVibraSettings:
00190                 {
00191                 _LIT(KVibraSettings, "Vibra settings");
00192                 iAppContainer->AddMessageL( KVibraSettings );
00193             VibraSettings();
00194             break;
00195                 }
00196         case EHWRMTestAppCmdVibraStatus:
00197                 {
00198                 _LIT(KVibraStatus, "Vibra status");
00199                 iAppContainer->AddMessageL( KVibraStatus );
00200             VibraStatus();
00201             break;
00202                 }
00203         case EHWRMTestAppCmdLightsReserve:
00204             {
00205             _LIT(KReserveLights, "Reserve lights");
00206             iAppContainer->AddMessageL( KReserveLights );
00207             TRAP( err, LightsReserveL() );
00208             break;
00209             }
00210         case EHWRMTestAppCmdLightsRelease:
00211             {
00212             _LIT(KReleaseLights, "Release lights");
00213             iAppContainer->AddMessageL( KReleaseLights );
00214             TRAP( err, LightsReleaseL() );
00215             break;
00216             }
00217         case EHWRMTestAppCmdLightsOn:
00218                 {
00219                 _LIT(KLightsOn, "Lights on");
00220                 iAppContainer->AddMessageL( KLightsOn );
00221             TRAP( err, LightsOnL() );
00222             break;
00223                 }
00224         case EHWRMTestAppCmdLightsBlink:
00225                 {
00226                 _LIT(KBlinkLights, "Blink lights");
00227                 iAppContainer->AddMessageL( KBlinkLights );
00228             TRAP( err, LightsBlinkL() );
00229             break;
00230                 }
00231         case EHWRMTestAppCmdLightsOff:
00232                 {
00233                 _LIT(KLightsOff, "Lights off");
00234                 iAppContainer->AddMessageL( KLightsOff );
00235             TRAP( err, LightsOffL() );
00236             break;
00237                 }
00238         case EHWRMTestAppCmdLightsStatus:
00239                 {
00240                 _LIT(KLightsStatus, "Lights status");
00241                 iAppContainer->AddMessageL( KLightsStatus );
00242             TRAP( err, LightsStatusL() );
00243             break;
00244                 }
00245         default:
00246             break;      
00247         }
00248     if( err != KErrNone )
00249         {
00250         TBuf<100> buf;
00251         _LIT(KErrorTrapped, "Error Trapped = %d!!!");
00252         buf.Format( KErrorTrapped, err );
00253         iAppContainer->AddMessageL( buf );
00254         }
00255     }
00256 
00257 // -----------------------------------------------------------------------------
00258 // CHWRMTestAppAppUi::HandleForegroundEventL
00259 // Handle situation when app is sent to the foreground or background
00260 // -----------------------------------------------------------------------------
00261 //
00262 void CHWRMTestAppAppUi::HandleForegroundEventL(TBool aForeground)
00263     {
00264     // first call base implementation
00265     CEikAppUi::HandleForegroundEventL( aForeground );
00266     
00267     if( aForeground )
00268         {
00269         _LIT(KAppSentToForeground, "App sent to foreground");
00270         iAppContainer->AddMessageL( KAppSentToForeground );
00271         }
00272     else
00273         {
00274         _LIT(KAppSentToBackground, "App sent to background");
00275         iAppContainer->AddMessageL( KAppSentToBackground );
00276         }
00277     }
00278 
00279 
00280 // =============================================================================
00281 //                          VIBRA RELATED METHODS
00282 // =============================================================================
00283 
00284 // -----------------------------------------------------------------------------
00285 // CHWRMTestAppAppUi::VibraReserveL
00286 // Reserve vibra
00287 // -----------------------------------------------------------------------------
00288 //
00289 void CHWRMTestAppAppUi::VibraReserveL()
00290     {
00291     TInt item(0);
00292     TBuf<100> buf;
00293     TBool restore;
00294     TBool forceNoCCoeEnv;
00295     
00296     CAknListQueryDialog* listDlg = new (ELeave)CAknListQueryDialog( &item );
00297     if( listDlg->ExecuteLD(R_HWRMTESTAPP_RESTORE_LIST) )
00298         {
00299         // got restore state parameter
00300         item == 0 ? restore = EFalse : restore = ETrue;
00301         //now get force no CCoeEnv parameter
00302         listDlg = new (ELeave)CAknListQueryDialog( &item );
00303         if( listDlg->ExecuteLD(R_HWRMTESTAPP_NOCCOEENV_LIST) )
00304             {
00305             // got ForceNoCCoeEnv parameter
00306             item == 0 ? forceNoCCoeEnv = EFalse : forceNoCCoeEnv = ETrue;
00307             _LIT(KReserveVibraLParameters, "ReserveVibraL(restore=%d,forceNoCCoeEnv=%d)");
00308             buf.Format( KReserveVibraLParameters, restore, forceNoCCoeEnv );
00309             iAppContainer->AddMessageL( buf );
00310             iVibra->ReserveVibraL( restore, forceNoCCoeEnv );
00311             }
00312         else
00313             {
00314             // did not get ForceNoCCoeEnv parameter
00315             _LIT(KReserveVibraLNotCalled, "ReserveVibraL not called, no ForceNoCCoeEnv value");
00316             iAppContainer->AddMessageL( KReserveVibraLNotCalled );
00317             }
00318         }
00319     else
00320         {
00321         // did not get restore parameter
00322         _LIT(KReserveVibraL, "ReserveVibraL()");
00323         iAppContainer->AddMessageL( KReserveVibraL );
00324         iVibra->ReserveVibraL();
00325         }
00326     }
00327     
00328 // -----------------------------------------------------------------------------
00329 // CHWRMTestAppAppUi::VibraReleaseL
00330 // Release vibra
00331 // -----------------------------------------------------------------------------
00332 //
00333 void CHWRMTestAppAppUi::VibraReleaseL()
00334     {
00335     _LIT(KReleaseVibraCalled, "ReleaseVibra called");
00336     iAppContainer->AddMessageL( KReleaseVibraCalled );
00337     iVibra->ReleaseVibra();
00338     }
00339     
00340 // -----------------------------------------------------------------------------
00341 // CHWRMTestAppAppUi::VibraStartL
00342 // Start vibra
00343 // -----------------------------------------------------------------------------
00344 //
00345 void CHWRMTestAppAppUi::VibraStartL()
00346     {
00347     CAknNumberQueryDialog* dlg;
00348     TInt intensity(0);
00349     TInt duration(0);
00350     TBuf<100> buf;
00351     
00352     //duration
00353     dlg = CAknNumberQueryDialog::NewL( duration );
00354     
00355     //KHWRMVibraMinIntensity, KHWRMVibraMaxIntensity, 5 ;
00356     if( dlg->ExecuteLD( R_HWRMTESTAPP_DURATION_QUERY ) )
00357         {
00358         // got duration so now optionally get the intensity
00359         dlg = CAknNumberQueryDialog::NewL( intensity );
00360         //KHWRMVibraMinIntensity, KHWRMVibraMaxIntensity, 5 ;
00361         if( dlg->ExecuteLD( R_HWRMTESTAPP_VIBRA_INTENSITY_QUERY ) )
00362             {
00363             // got the intenstity
00364             _LIT(KStartVibraL, "StartVibraL(duration=%d,intensity=%d)");
00365             buf.Format( KStartVibraL, duration, intensity );
00366             iAppContainer->AddMessageL( buf );
00367             iVibra->StartVibraL( duration, intensity );
00368             }
00369         else
00370             {
00371             // user pressed cancel for intensity query
00372             _LIT(KStartVibraLDuration, "StartVibraL(duration=%d)");
00373             buf.Format( KStartVibraLDuration, duration );
00374             iAppContainer->AddMessageL( buf );
00375             iVibra->StartVibraL( duration );
00376             }
00377         }
00378     else
00379         {
00380         // user pressed cancel for duration query
00381         // do nothing...
00382         _LIT(KStartVibraLNotCalled, "StartVibraL not called!");
00383         iAppContainer->AddMessageL( KStartVibraLNotCalled );
00384         }
00385     }
00386 
00387 // -----------------------------------------------------------------------------
00388 // CHWRMTestAppAppUi::VibraStopL
00389 // Stop vibra
00390 // -----------------------------------------------------------------------------
00391 //
00392 void CHWRMTestAppAppUi::VibraStopL()
00393     {
00394     _LIT(KStopVibraLCalled, "StopVibraL called");
00395     iAppContainer->AddMessageL( KStopVibraLCalled );
00396     iVibra->StopVibraL();
00397     }
00398 
00399 // -----------------------------------------------------------------------------
00400 // CHWRMTestAppAppUi::VibraSettings
00401 // Retrieve vibra settings
00402 // -----------------------------------------------------------------------------
00403 //
00404 void CHWRMTestAppAppUi::VibraSettings()
00405     {
00406     VibraModeChanged( iVibra->VibraSettings() );
00407     }
00408 
00409 // -----------------------------------------------------------------------------
00410 // CHWRMTestAppAppUi::VibraStatus
00411 // Retrieve vibra status
00412 // -----------------------------------------------------------------------------
00413 //
00414 void CHWRMTestAppAppUi::VibraStatus()
00415     {
00416     VibraStatusChanged( iVibra->VibraStatus() );
00417     }
00418 
00419 
00420 // =============================================================================
00421 //                          LIGHTS RELATED METHODS
00422 // =============================================================================
00423 
00424 // -----------------------------------------------------------------------------
00425 // CHWRMTestAppAppUi::LightsReserveL
00426 // Reserve lights
00427 // -----------------------------------------------------------------------------
00428 //
00429 void CHWRMTestAppAppUi::LightsReserveL()
00430     {
00431     TInt item(0);
00432     TBuf<100> buf;
00433     TBool restore;
00434     TBool forceNoCCoeEnv;
00435     TInt target(CHWRMLight::ENoTarget);
00436     
00437     // Get the lights target
00438     target = GetLightsTargetL();
00439     
00440     if( target == KErrCancel )
00441         {
00442         // no target entered
00443         _LIT(KReserveLightLNotCalled, "ReserveLightL not called, no target!");
00444         iAppContainer->AddMessageL( KReserveLightLNotCalled );
00445         return;
00446         }
00447     
00448     CAknListQueryDialog* listDlg = new (ELeave)CAknListQueryDialog( &item );
00449     
00450     if( listDlg->ExecuteLD(R_HWRMTESTAPP_RESTORE_LIST) )
00451         {
00452         // got restore state parameter
00453         item == 0 ? restore = EFalse : restore = ETrue;
00454         //now get force no CCoeEnv parameter
00455         listDlg = new (ELeave)CAknListQueryDialog( &item );
00456         if( listDlg->ExecuteLD(R_HWRMTESTAPP_NOCCOEENV_LIST) )
00457             {
00458             // got ForceNoCCoeEnv parameter
00459             item == 0 ? forceNoCCoeEnv = EFalse : forceNoCCoeEnv = ETrue;
00460             _LIT(KReserveLightL, "ReserveLightL(target=%d,restore=%d,forceNoCCoeEnv=%d)");
00461             buf.Format( KReserveLightL, target, restore, forceNoCCoeEnv );
00462             iAppContainer->AddMessageL( buf );
00463             iLight->ReserveLightL( target, restore, forceNoCCoeEnv );
00464             }
00465         else
00466             {
00467             // did not get ForceNoCCoeEnv parameter
00468             _LIT(KReserveLightLNotCalled, "ReserveLightL not called, no ForceNoCCoeEnv value");
00469             iAppContainer->AddMessageL( KReserveLightLNotCalled );
00470             }
00471         }
00472     else
00473         {
00474         // did not get restore parameter
00475         _LIT(KReserveLightLTarget, "ReserveLightL(target=%d)");
00476         buf.Format( KReserveLightLTarget, target );
00477         iAppContainer->AddMessageL( buf );
00478         iLight->ReserveLightL( target );
00479         }
00480 
00481     }
00482     
00483 // -----------------------------------------------------------------------------
00484 // CHWRMTestAppAppUi::LightsReleaseL
00485 // Release lights
00486 // -----------------------------------------------------------------------------
00487 //
00488 void CHWRMTestAppAppUi::LightsReleaseL()
00489     {
00490     TBuf<100> buf;
00491     TInt target(CHWRMLight::ENoTarget);
00492     
00493     // Get the lights target
00494     target = GetLightsTargetL();
00495     
00496     if( target == KErrCancel )
00497         {
00498         // no target entered
00499         _LIT(KReleaseLightNotCalled, "ReleaseLight not called, no target!");
00500         iAppContainer->AddMessageL( KReleaseLightNotCalled );
00501         }
00502     else
00503         {
00504         _LIT(KReleaseLight, "ReleaseLight(target=%d)");
00505         buf.Format( KReleaseLight, target );
00506         iAppContainer->AddMessageL( buf );
00507         iLight->ReleaseLight( target );
00508         }
00509     }
00510 
00511 // -----------------------------------------------------------------------------
00512 // CHWRMTestAppAppUi::LightsOnL
00513 // Turn lights on
00514 // -----------------------------------------------------------------------------
00515 //
00516 void CHWRMTestAppAppUi::LightsOnL()
00517     {
00518     TInt item(0);
00519     TInt duration(0);
00520     TInt intensity(0);
00521     TInt target(CHWRMLight::ENoTarget);
00522     TBool fade(EFalse);
00523     TBuf<100> buf;
00524     
00525     // Get the lights target
00526     target = GetLightsTargetL();
00527     
00528     if( target == KErrCancel )
00529         {
00530         // no target entered
00531         _LIT(KLightOnLNotCalled, "LightOnL not called, no target!");
00532         iAppContainer->AddMessageL( KLightOnLNotCalled );
00533         return;
00534         }
00535     
00536     //duration
00537     CAknNumberQueryDialog* queryDlg = CAknNumberQueryDialog::NewL( duration );
00538     if( queryDlg->ExecuteLD( R_HWRMTESTAPP_DURATION_QUERY ) )
00539         {
00540         // got duration so get intensity
00541         queryDlg = CAknNumberQueryDialog::NewL( intensity );
00542         if( queryDlg->ExecuteLD( R_HWRMTESTAPP_LIGHT_INTENSITY_QUERY ) )
00543             {
00544             // got the intenstity
00545             CAknListQueryDialog* listDlg = new (ELeave)CAknListQueryDialog( &item );
00546             if( listDlg->ExecuteLD(R_HWRMTESTAPP_FADE_LIST) )
00547                 {
00548                 // got fade parameter
00549                 item == 0 ? fade = EFalse : fade = ETrue;
00550                 _LIT(KLightOnLParameters, "LightOnL(target=%d,duration=%d,intensity=%d,fade=%d)");
00551                 buf.Format( KLightOnLParameters, target, duration, intensity, fade );
00552                 iAppContainer->AddMessageL( buf );
00553                 iLight->LightOnL( target, duration, intensity, fade );
00554                 }
00555             else
00556                 {
00557                 // did not get fade parameter
00558                 _LIT(KLightOnL, "LightOnL not called, no fade value!");
00559                 iAppContainer->AddMessageL( KLightOnL );
00560                 }
00561             }
00562         else
00563             {
00564             // user pressed cancel for intensity query
00565             _LIT(KLightOnLTargetDuration, "LightOnL(target=%d,duration=%d)");
00566             buf.Format( KLightOnLTargetDuration, target, duration );
00567             iAppContainer->AddMessageL( buf );
00568             iLight->LightOnL( target, duration );
00569             }        
00570         }
00571     else
00572         {
00573         // didn't get duration so call basic API
00574         _LIT(KLightOnLTarget, "LightOnL(target=%d)");
00575         buf.Format( KLightOnLTarget, target );
00576         iAppContainer->AddMessageL( buf );
00577         iLight->LightOnL( target );
00578         }
00579     }
00580 
00581 // -----------------------------------------------------------------------------
00582 // CHWRMTestAppAppUi::LightsBlinkL
00583 // Blink lights
00584 // -----------------------------------------------------------------------------
00585 //
00586 void CHWRMTestAppAppUi::LightsBlinkL()
00587     {
00588     TInt duration(0);
00589     TInt onDuration(0);
00590     TInt offDuration(0);
00591     TInt intensity(0);
00592     TBuf<100> buf;
00593     
00594     // Get the lights target
00595     TInt target = GetLightsTargetL();
00596     if( target == KErrCancel )
00597         {
00598         // no target entered
00599         _LIT(KLightsBlinkNotCalled, "LightsBlink not called, no target!");
00600         iAppContainer->AddMessageL( KLightsBlinkNotCalled );
00601         return;
00602         }
00603     
00604     // get duration
00605     CAknNumberQueryDialog* queryDlg = CAknNumberQueryDialog::NewL( duration );
00606     if( queryDlg->ExecuteLD( R_HWRMTESTAPP_DURATION_QUERY ) )
00607         {
00608         // got duration so get OnDuration
00609         queryDlg = CAknNumberQueryDialog::NewL( onDuration );
00610         CleanupStack::PushL( queryDlg );
00611         
00612         _LIT(KEnterONDuration, "Enter ON duration (0 to 2147482)");
00613         queryDlg->SetPromptL( KEnterONDuration );
00614         
00615         CleanupStack::Pop( queryDlg );
00616         if( queryDlg->ExecuteLD( R_HWRMTESTAPP_DURATION_QUERY ) )
00617             {
00618             // got OnDuration so get OffDuration
00619             queryDlg = CAknNumberQueryDialog::NewL( offDuration );
00620             CleanupStack::PushL( queryDlg );
00621             
00622             _LIT(KEnterOFFDuration, "Enter OFF duration (0 to 2147482)");
00623             queryDlg->SetPromptL( KEnterOFFDuration );
00624             
00625             CleanupStack::Pop( queryDlg );
00626             if( queryDlg->ExecuteLD( R_HWRMTESTAPP_DURATION_QUERY ) )
00627                 {
00628                 // got OffDuration so get intensity
00629                 queryDlg = CAknNumberQueryDialog::NewL( intensity );
00630                 if( queryDlg->ExecuteLD( R_HWRMTESTAPP_LIGHT_INTENSITY_QUERY ) )
00631                     {
00632                     // got the intenstity
00633                     _LIT(KLightBlinkLParameters, "LightBlinkL(target=%d,duration=%d,onDuration=%d,offDuration=%d,intensity=%d)");
00634                     buf.Format( KLightBlinkLParameters,target, duration, onDuration, offDuration, intensity );
00635                     iAppContainer->AddMessageL( buf );
00636                     iLight->LightBlinkL( target, duration, onDuration,
00637                                          offDuration, intensity );
00638                     }
00639                 else
00640                     {
00641                     // user pressed cancel for intensity
00642                     _LIT(KLightBlinkLNoIntensity, "LightBlinkL not called, no intensity value!");
00643                     iAppContainer->AddMessageL( KLightBlinkLNoIntensity );
00644                     }
00645                 
00646                 }
00647             else
00648                 {
00649                 // user pressed cancel for OffDuration
00650                 _LIT(KLightBlinkLNoOffDuration, "LightBlinkL not called, no offDuration value!");
00651                 iAppContainer->AddMessageL( KLightBlinkLNoOffDuration );
00652                 }
00653             }
00654         else
00655             {
00656             // user pressed cancel for OnDuration
00657             _LIT(KLightBlinkLTargetDuration, "LightBlinkL(target=%d,duration=%d)");
00658             buf.Format( KLightBlinkLTargetDuration, target, duration );
00659             iAppContainer->AddMessageL( buf );
00660             }
00661         }
00662     else
00663         {
00664         // user pressed cancel for Duration
00665         _LIT(KLightBlinkLTarget, "LightBlinkL(target=%d)");
00666         buf.Format( KLightBlinkLTarget, target );
00667         iAppContainer->AddMessageL( buf );
00668         }
00669     }
00670 
00671 // -----------------------------------------------------------------------------
00672 // CHWRMTestAppAppUi::LightsOffL
00673 // Turn lights off
00674 // -----------------------------------------------------------------------------
00675 //
00676 void CHWRMTestAppAppUi::LightsOffL()
00677     {
00678     TInt item(0);
00679     TInt duration(0);
00680     TInt target(CHWRMLight::ENoTarget);
00681     TBool fade(EFalse);
00682     TBuf<100> buf;
00683     
00684     // Get the lights target
00685     target = GetLightsTargetL();
00686     
00687     if( target == KErrCancel )
00688         {
00689         // no target entered
00690         _LIT(KLightsOffLNoTarget, "LightsOffL not called, no target!");
00691         iAppContainer->AddMessageL( KLightsOffLNoTarget );
00692         return;
00693         }
00694     
00695     //duration
00696     CAknNumberQueryDialog* queryDlg = CAknNumberQueryDialog::NewL( duration );
00697     if( queryDlg->ExecuteLD( R_HWRMTESTAPP_DURATION_QUERY ) )
00698         {
00699         // got duration so get fade
00700         CAknListQueryDialog* listDlg = new (ELeave)CAknListQueryDialog( &item );
00701         if( listDlg->ExecuteLD(R_HWRMTESTAPP_FADE_LIST) )
00702             {
00703             // got fade parameter
00704             item == 0 ? fade = EFalse : fade = ETrue;
00705             _LIT(KLightOffLParameters, "LightOffL(target=%d,duration=%d,fade=%d)");
00706             buf.Format( KLightOffLParameters, target, duration, fade );
00707             iAppContainer->AddMessageL( buf );
00708             iLight->LightOffL( target, duration, fade );
00709             }
00710         else
00711             {
00712             // did not get fade parameter
00713             _LIT(KLightOffLTargetDuration, "LightOffL(target=%d,duration=%d)");
00714             buf.Format( KLightOffLTargetDuration, target, duration );
00715             iAppContainer->AddMessageL( buf );
00716             iLight->LightOffL( target, duration );
00717             }
00718         }
00719     else
00720         {
00721         // didn't get duration so call basic API
00722         _LIT(KLightOffLTarget, "LightOffL(target=%d)");
00723         buf.Format( KLightOffLTarget, target );
00724         iAppContainer->AddMessageL( buf );
00725         }
00726     }
00727 
00728 // -----------------------------------------------------------------------------
00729 // CHWRMTestAppAppUi::LightsStatusL
00730 // Retrieve lights status
00731 // -----------------------------------------------------------------------------
00732 //
00733 void CHWRMTestAppAppUi::LightsStatusL()
00734     {
00735     TInt target(CHWRMLight::ENoTarget);
00736     TBuf<100> buf;
00737     
00738     // Get the lights target
00739     target = GetLightsTargetL();
00740     
00741     if( target == KErrCancel )
00742         {
00743         // no target entered
00744         _LIT(KLightStatusNoTarget, "LightStatus not called, no target!");
00745         iAppContainer->AddMessageL( KLightStatusNoTarget );
00746         }
00747     else
00748         {
00749         _LIT(KLightStatusTarget, "LightStatus(target=%d)");
00750         buf.Format( KLightStatusTarget, target );
00751         iAppContainer->AddMessageL( buf );
00752         LightStatusChanged( target, iLight->LightStatus( target ) );
00753         }
00754     }
00755 
00756 // -----------------------------------------------------------------------------
00757 // CHWRMTestAppAppUi::GetLightsTargetL
00758 // Retrieve lights target
00759 // -----------------------------------------------------------------------------
00760 //
00761 TInt CHWRMTestAppAppUi::GetLightsTargetL()
00762     {
00763     TInt item(0);
00764     TInt ret(KErrCancel);
00765     
00766     CAknListQueryDialog* listDlg = new (ELeave)CAknListQueryDialog( &item );
00767     if( listDlg->ExecuteLD(R_HWRMTESTAPP_LIGHTSTARGET_LIST) )
00768         {
00769         // This is a lookup table for the items defined in the
00770         // resource array r_hwrmtestapp_lightstarget_items
00771         switch ( item )
00772             {
00773             case 0: // ENoTarget
00774                 {
00775                 ret = CHWRMLight::ENoTarget;
00776                 break;
00777                 }
00778             case 1: // EPrimaryDisplay
00779                 {
00780                 ret = CHWRMLight::EPrimaryDisplay;
00781                 break;
00782                 }
00783             case 2: // EPrimaryKeyboard
00784                 {
00785                 ret = CHWRMLight::EPrimaryKeyboard;
00786                 break;
00787                 }
00788             case 3: // EPrimaryDisplayAndKeyboard
00789                 {
00790                 ret = CHWRMLight::EPrimaryDisplayAndKeyboard;
00791                 break;
00792                 }
00793             case 4: // ESecondaryDisplay
00794                 {
00795                 ret = CHWRMLight::ESecondaryDisplay;
00796                 break;
00797                 }
00798             case 5: // ESecondaryKeyboard
00799                 {
00800                 ret = CHWRMLight::ESecondaryKeyboard;
00801                 break;
00802                 }
00803             case 6: // ESecondaryDisplayAndKeyboard
00804                 {
00805                 ret = CHWRMLight::ESecondaryDisplayAndKeyboard;
00806                 break;
00807                 }
00808             case 7: // ECustomTarget1
00809                 {
00810                 ret = CHWRMLight::ECustomTarget1;
00811                 break;
00812                 }
00813             case 8: // ECustomTarget2
00814                 {
00815                 ret = CHWRMLight::ECustomTarget2;
00816                 break;
00817                 }
00818             case 9: // ECustomTarget3
00819                 {
00820                 ret = CHWRMLight::ECustomTarget3;
00821                 break;
00822                 }
00823             case 10: // ECustomTarget4
00824                 {
00825                 ret = CHWRMLight::ECustomTarget4;
00826                 break;                
00827                 }
00828             default:
00829                 break;
00830             }             
00831         }
00832     else
00833         {
00834         // no target entered
00835         ret = KErrCancel;
00836         }
00837     
00838     return ret;
00839     }
00840 
00841 // -----------------------------------------------------------------------------
00842 // CHWRMTestAppAppUi::PrintLightTargetsL
00843 // Prints list of the supported light targets
00844 // -----------------------------------------------------------------------------
00845 //
00846 void CHWRMTestAppAppUi::PrintLightTargetsL()
00847     {
00848     TInt targets = iLight->SupportedTargets();
00849     
00850     _LIT( KSupportedLightTargets, "Supported light targets:");
00851     iAppContainer->AddMessageL( KSupportedLightTargets );
00852     
00853     if ( targets & CHWRMLight::EPrimaryDisplay )
00854         {
00855         _LIT( KPrimaryDisplay, "EPrimaryDisplay" );
00856         iAppContainer->AddMessageL( KPrimaryDisplay );
00857         }
00858     if ( targets & CHWRMLight::EPrimaryKeyboard ) 
00859         {
00860         _LIT( KPrimaryKeyboard, "EPrimaryKeyboard" );
00861         iAppContainer->AddMessageL( KPrimaryKeyboard );
00862         }
00863     if ( targets & CHWRMLight::EPrimaryDisplayAndKeyboard )
00864         {
00865         _LIT( KPrimaryDisplayAndKeyboard, "EPrimaryDisplayAndKeyboard" );
00866         iAppContainer->AddMessageL( KPrimaryDisplayAndKeyboard );
00867         }
00868     if ( targets & CHWRMLight::ESecondaryDisplay )
00869         {
00870         _LIT( KSecondaryDisplay, "ESecondaryDisplay" );
00871         iAppContainer->AddMessageL( KSecondaryDisplay );
00872         }
00873     if ( targets & CHWRMLight::ESecondaryKeyboard)
00874         {
00875         _LIT( KSecondaryKeyboard, "ESecondaryKeyboard" );
00876         iAppContainer->AddMessageL( KSecondaryKeyboard );
00877         }
00878     if ( targets & CHWRMLight::ESecondaryDisplayAndKeyboard )
00879         {
00880         _LIT( KSecondaryDisplayAndKeyboard, "ESecondaryDisplayAndKeyboard" );
00881         iAppContainer->AddMessageL( KSecondaryDisplayAndKeyboard );
00882         }
00883     if ( targets & CHWRMLight::ECustomTarget1 )
00884         {
00885         _LIT( KCustomTarget1, "ECustomTarget1" );
00886         iAppContainer->AddMessageL( KCustomTarget1 );
00887         }
00888     if ( targets & CHWRMLight::ECustomTarget2 )
00889         {
00890         _LIT( KCustomTarget2, "ECustomTarget2" );
00891         iAppContainer->AddMessageL( KCustomTarget2 );
00892         }
00893     if ( targets & CHWRMLight::ECustomTarget3 )
00894         {
00895         _LIT( KCustomTarget3, "ECustomTarget3" );
00896         iAppContainer->AddMessageL( KCustomTarget3 );
00897         }
00898     if ( targets & CHWRMLight::ECustomTarget4 )
00899         {
00900         _LIT( KCustomTarget4, "ECustomTarget4" );
00901         iAppContainer->AddMessageL( KCustomTarget4 );       
00902         }
00903     }
00904 
00905 // =============================================================================
00906 //                      MHWRMVibraObserver METHODS
00907 // =============================================================================
00908 
00909 // -----------------------------------------------------------------------------
00910 // CHWRMTestAppAppUi::VibraModeChanged
00911 // Callback for when vibra mode is changed
00912 // -----------------------------------------------------------------------------
00913 //
00914 void CHWRMTestAppAppUi::VibraModeChanged(CHWRMVibra::TVibraModeState aStatus)
00915     {
00916     _LIT(KVibraModeStateChanged, "Vibra mode state changed:");
00917     TRAP_IGNORE( 
00918         iAppContainer->AddMessageL( KVibraModeStateChanged );
00919         switch ( aStatus )
00920             {
00921             case CHWRMVibra::EVibraModeUnknown:
00922                 {
00923                 _LIT(KEVibraModeUnknown, "  EVibraModeUnknown");
00924                 iAppContainer->AddMessageL( KEVibraModeUnknown );
00925                 break;
00926                 }
00927             case CHWRMVibra::EVibraModeON:
00928                 {
00929                 _LIT(KEVibraModeOn, "  EVibraModeON");
00930                 iAppContainer->AddMessageL( KEVibraModeOn );
00931                 break;
00932                 }
00933             case CHWRMVibra::EVibraModeOFF:
00934                 {
00935                 _LIT(KEVibraModeOff, "  EVibraModeOFF");
00936                 iAppContainer->AddMessageL( KEVibraModeOff );
00937                 break;
00938                 }
00939             default:
00940                 {
00941                 _LIT(KVibraModeUndefined, "  UNDEFINED !!!");
00942                 iAppContainer->AddMessageL( KVibraModeUndefined );
00943                 break;
00944                 }
00945             }
00946         ); // TRAP_IGNORE
00947     }
00948 
00949 // -----------------------------------------------------------------------------
00950 // CHWRMTestAppAppUi::VibraStatusChanged
00951 // Callback for when vibra status is changed
00952 // -----------------------------------------------------------------------------
00953 //
00954 void CHWRMTestAppAppUi::VibraStatusChanged(CHWRMVibra::TVibraStatus aStatus)
00955     {
00956     _LIT(KVibraStateChanged, "Vibra state changed:");
00957     TRAP_IGNORE(
00958         iAppContainer->AddMessageL( KVibraStateChanged );
00959         switch ( aStatus )
00960             {
00961             case CHWRMVibra::EVibraStatusUnknown:
00962                 {
00963                 _LIT(KEVibraStatusUnknown, "  EVibraStatusUnknown");
00964                 iAppContainer->AddMessageL( KEVibraStatusUnknown );
00965                 break;
00966                 }
00967             case CHWRMVibra::EVibraStatusNotAllowed:
00968                 {
00969                 _LIT(KEVibraStatusNotAllowed, "  EVibraStatusNotAllowed");
00970                 iAppContainer->AddMessageL( KEVibraStatusNotAllowed );
00971                 break;
00972                 }
00973             case CHWRMVibra::EVibraStatusStopped:
00974                 {
00975                 _LIT(KEVibraStatusStopped, "  EVibraStatusStopped");
00976                 iAppContainer->AddMessageL( KEVibraStatusStopped );
00977                 break;
00978                 }
00979             case CHWRMVibra::EVibraStatusOn:
00980                 {
00981                 _LIT(KEVibraStatusOn, "  EVibraStatusOn");
00982                 iAppContainer->AddMessageL( KEVibraStatusOn );
00983                 break;
00984                 }
00985             default:
00986                 {
00987                 _LIT(KVibraStatusUndefined, "  UNDEFINED !!!");
00988                 iAppContainer->AddMessageL( KVibraStatusUndefined );
00989                 break;
00990                 }
00991             }
00992         ); // TRAP_IGNORE
00993     }
00994 
00995 
00996 // =============================================================================
00997 //                      MHWRMLightObserver METHODS
00998 // =============================================================================
00999 
01000 // -----------------------------------------------------------------------------
01001 // CHWRMTestAppAppUi::LightStatusChanged
01002 // Callback for when lights status is changed
01003 // -----------------------------------------------------------------------------
01004 //
01005 void CHWRMTestAppAppUi::LightStatusChanged(TInt aTarget, 
01006                         CHWRMLight::TLightStatus aStatus)
01007     {
01008     TRAP_IGNORE(
01009         TBuf<100> buf;
01010         _LIT(KLightStateChangedForTarget, "Light state changed for target:");
01011         iAppContainer->AddMessageL( KLightStateChangedForTarget );
01012                 _LIT( KHexTarget, " 0x%x");
01013                 buf.Format(KHexTarget, aTarget);
01014         iAppContainer->AddMessageL( buf );
01015         
01016         switch ( aStatus )
01017             {
01018             case CHWRMLight::ELightOn:
01019                 {
01020                 _LIT(KLightChangedOn, "Light state changed: ELightOn");
01021                 iAppContainer->AddMessageL( KLightChangedOn );
01022                 break;
01023                 }
01024             case CHWRMLight::ELightOff:
01025                 {
01026                 _LIT(KLightChangedOff, "Light state changed: ELightOff");
01027                 iAppContainer->AddMessageL( KLightChangedOff );
01028                 break;
01029                 }
01030             case CHWRMLight::ELightBlink:
01031                 {
01032                 _LIT(KLightChangedBlink, "Light state changed: ELightBlink");
01033                 iAppContainer->AddMessageL( KLightChangedBlink );
01034                 break;
01035                 }
01036             case CHWRMLight::ELightStatusUnknown:
01037                 {
01038                 _LIT(KLightChangedUnknown, "Light state changed: ELightStatusUnknown");
01039                 iAppContainer->AddMessageL( KLightChangedUnknown );
01040                 break;
01041                 }
01042             default:
01043                 {
01044                 _LIT(KLightChangedUndefined, "Light state changed: UNDEFINED !!!");
01045                 iAppContainer->AddMessageL( KLightChangedUndefined );
01046                 break;
01047                 }
01048             }
01049         ); // TRAP_IGNORE
01050     }
01051 
01052 
01053 // End of File  
01054 

© Nokia 2009

Back to top