tactilefeedback/tactilefeedbackresolver/plugins/tactilevibraplugin/src/tactilevibraplayer.cpp
changeset 0 d54f32e146dd
child 12 63c33341dc19
child 15 8c57b70b4bf3
equal deleted inserted replaced
-1:000000000000 0:d54f32e146dd
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Class for producing vibra feedback.
       
    15 * Part of:      Tactile Feedback.
       
    16 *
       
    17 */
       
    18 
       
    19 #include <e32debug.h>
       
    20 #include <hwrmvibra.h>
       
    21 #include <centralrepository.h>
       
    22 #include <ecom/implementationproxy.h>
       
    23 #include <profileinternal.hrh>
       
    24 
       
    25 #include "tactilefeedbackprivatecrkeys.h"
       
    26 #include "tactilefeedbacktrace.h"
       
    27 
       
    28 #include "tactilevibraplayer.h"
       
    29 #include "OstTraceDefinitions.h"
       
    30 #ifdef OST_TRACE_COMPILER_IN_USE
       
    31 #include "tactilevibraplayerTraces.h"
       
    32 #endif
       
    33 
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // Constructor.
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 CTactileVibraPlayer::CTactileVibraPlayer( CRepository& aRepository ):
       
    40         iRepository ( aRepository )
       
    41     {    
       
    42     }
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // 2nd phase constructor.
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 void CTactileVibraPlayer::ConstructL()
       
    49     {
       
    50     TRACE("CTactileVibraPlayer::ConstructL - Begin");
       
    51 
       
    52     User::LeaveIfError( iRepository.Get( KTactileFeedbackHapticsStrength, 
       
    53                                          iVibraLevel ) );
       
    54                                          
       
    55     if ( iVibraLevel > EProfileTactileFeedbackLevel3 )
       
    56         {
       
    57         User::Leave( KErrGeneral );
       
    58         }
       
    59         
       
    60     ReadSettings();
       
    61 
       
    62     iCenRepNotifier = CCenRepNotifyHandler::NewL( *this, 
       
    63                                                   iRepository, 
       
    64                                                   CCenRepNotifyHandler::EIntKey,
       
    65                                                   KTactileFeedbackHapticsStrength );
       
    66     iCenRepNotifier->StartListeningL();     
       
    67 
       
    68     TRACE("CTactileVibraPlayer::ConstructL - End");
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // 2-phased constructor.
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 CTactileVibraPlayer* CTactileVibraPlayer::NewL( CRepository& aRepository )
       
    76     {
       
    77     CTactileVibraPlayer* self = 
       
    78         new ( ELeave ) CTactileVibraPlayer ( aRepository );
       
    79     CleanupStack::PushL( self );
       
    80     self->ConstructL();
       
    81     CleanupStack::Pop( self );
       
    82     return self;
       
    83     }
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // Destructor.
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 CTactileVibraPlayer::~CTactileVibraPlayer()
       
    90     {
       
    91     delete iCenRepNotifier;
       
    92     delete iVibra;
       
    93     iVibraParams.Close();
       
    94     }
       
    95 
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // From class CTactilePlayer
       
    99 //
       
   100 // Duration and intensity for the vibra are selected from the array
       
   101 // according to logical feedback type.
       
   102 //
       
   103 // Feedback is not produced in case duration or intensity is zero.
       
   104 // ---------------------------------------------------------------------------
       
   105 //
       
   106 TInt CTactileVibraPlayer::PlayFeedback( TTouchLogicalFeedback aFeedback )
       
   107     {
       
   108     TInt ret(KErrNotReady);
       
   109     if ( iVibraLevel != EProfileTactileFeedbackOff )
       
   110         {
       
   111         TInt effectIndex = KErrNotFound;
       
   112         
       
   113         switch ( aFeedback )
       
   114             {
       
   115             case ETouchFeedbackBasic:               // flow through
       
   116             case ETouchFeedbackBasicButton:         // flow through
       
   117             case ETouchFeedbackList:                // flow through
       
   118             case ETouchFeedbackBoundaryList:        // flow through
       
   119             case ETouchFeedbackSlider:              // flow through
       
   120             case ETouchFeedbackEdit:                // flow through
       
   121             case ETouchFeedbackSensitiveInput:
       
   122             case ETouchFeedbackLineSelection:       // flow through
       
   123             case ETouchFeedbackBlankSelection:      // flow through
       
   124             case ETouchFeedbackTextSelection:       // flow through
       
   125             case ETouchFeedbackEmptyLineSelection:  // flow through
       
   126             case ETouchFeedbackTab:                 // flow through
       
   127             case ETouchFeedbackPopUp:               // flow through
       
   128             case ETouchFeedbackIncreasingPopUp:     // flow through
       
   129             case ETouchFeedbackDecreasingPopUp:     // flow through
       
   130             case ETouchFeedbackFlick:               // flow through
       
   131             case ETouchFeedbackCheckbox:            // flow through
       
   132             case ETouchFeedbackCharacterInputButton:
       
   133             case ETouchFeedbackMultiTouchRecognized:
       
   134                 effectIndex = 0;
       
   135                 break;
       
   136             case ETouchFeedbackSensitive:           // flow through
       
   137             case ETouchFeedbackSensitiveButton:     // flow through
       
   138             case ETouchFeedbackSensitiveList:      
       
   139                 effectIndex = 1;                    
       
   140                 break;                              
       
   141             default:                                
       
   142                 effectIndex = 0;                    
       
   143                 break;                              
       
   144             }
       
   145         
       
   146         if ( effectIndex < iVibraParams.Count() && 
       
   147              iVibraParams[effectIndex].iTime > 0 &&
       
   148              iVibraParams[effectIndex].iIntensity != 0)
       
   149             {
       
   150             TRACE2("CTactileVibraPlayer::PlayFeedback %d", aFeedback);  
       
   151             TRAP( ret, DoPlayFeedbackL( 
       
   152                 iVibraParams[effectIndex].iTime, 
       
   153                 iVibraParams[effectIndex].iIntensity ) ); 
       
   154 
       
   155             if (!ret)    
       
   156                 {
       
   157                 TRACE2("CTactileVibraPlayer: Vibra playing leave code: %d", ret);  
       
   158                 }
       
   159             }        
       
   160         }
       
   161     return ret;
       
   162     }
       
   163     
       
   164 // ---------------------------------------------------------------------------
       
   165 // Start feedback.
       
   166 // ---------------------------------------------------------------------------
       
   167 //   
       
   168 TInt CTactileVibraPlayer::StartFeedback( TTouchContinuousFeedback aType,
       
   169                                          TInt aIntensity )
       
   170     {
       
   171     TRACE("CTactileVibraPlayer::StartFeedback - Begin");
       
   172     TRAPD( ret, DoStartFeedbackL( aType, aIntensity ) );
       
   173     TRACE("CTactileVibraPlayer::StartFeedback - End");
       
   174     return ret;
       
   175     }
       
   176         
       
   177 // ---------------------------------------------------------------------------
       
   178 // Modify feedback.
       
   179 // ---------------------------------------------------------------------------
       
   180 //                        
       
   181 TInt CTactileVibraPlayer::ModifyFeedback( TInt /*aIntensity*/ )
       
   182     {
       
   183     return KErrNotSupported;
       
   184     }
       
   185     
       
   186 // ---------------------------------------------------------------------------
       
   187 // Stop feedback.
       
   188 // ---------------------------------------------------------------------------
       
   189 //    
       
   190 void CTactileVibraPlayer::StopFeedback()
       
   191     {
       
   192     TRACE("CTactileVibraPlayer::StopFeedback - Begin");
       
   193     if ( iVibra )
       
   194         {
       
   195         TRAP_IGNORE( iVibra->StopVibraL() );
       
   196         }    
       
   197     TRACE("CTactileVibraPlayer::StopFeedback - End");
       
   198     }
       
   199   
       
   200 // ---------------------------------------------------------------------------
       
   201 //
       
   202 // ---------------------------------------------------------------------------
       
   203 //    
       
   204 TInt CTactileVibraPlayer::PlayPreviewFeedback( TInt aLevel, 
       
   205                                              TTouchLogicalFeedback aFeedback )    
       
   206     {
       
   207     TRACE("CTactileVibraPlayer::PlayPreviewFeedback - Begin");
       
   208     TInt ret( KErrArgument );
       
   209     
       
   210     if ( aLevel > EProfileTactileFeedbackOff  &&
       
   211          aLevel <= EProfileTactileFeedbackLevel3 )
       
   212         {
       
   213         iOriginalLevel = iVibraLevel;
       
   214         iVibraLevel = aLevel;
       
   215         ReadSettings();    
       
   216         ret = PlayFeedback( aFeedback );
       
   217         iVibraLevel = iOriginalLevel;
       
   218         ReadSettings();
       
   219         }    
       
   220     
       
   221     TRACE("CTactileVibraPlayer::PlayPreviewFeedback - End");
       
   222     return ret;    
       
   223     }
       
   224 
       
   225 // ---------------------------------------------------------------------------
       
   226 // Read vibra effects from central repository.
       
   227 // ---------------------------------------------------------------------------
       
   228 //
       
   229 void CTactileVibraPlayer::ReadSettings()
       
   230     {    
       
   231     TRACE("CTactileVibraPlayer::ReadSettings - Begin");
       
   232     TTactileVibraParams basicParams;
       
   233     
       
   234     basicParams.iTime = 0;
       
   235     basicParams.iIntensity = 0;
       
   236 
       
   237     TTactileVibraParams sensitiveParams = basicParams;
       
   238         
       
   239     if ( iVibraLevel == EProfileTactileFeedbackLevel1 )
       
   240         {
       
   241         // Read settings for ETouchFeedbackBasic
       
   242         iRepository.Get( KTactileVibraIntensityBasicLevel1, 
       
   243                           basicParams.iIntensity );
       
   244         iRepository.Get( KTactileVibraDurationBasicLevel1,  
       
   245                           basicParams.iTime );
       
   246         
       
   247         // Read settings for ETouchFeedbackSensitive
       
   248         iRepository.Get( KTactileVibraIntensitySensitiveLevel1, 
       
   249                           sensitiveParams.iIntensity );
       
   250         iRepository.Get( KTactileVibraDurationSensitiveLevel1,  
       
   251                           sensitiveParams.iTime );
       
   252         }
       
   253     else if ( iVibraLevel == EProfileTactileFeedbackLevel2 )
       
   254         {
       
   255         // Read settings for ETouchFeedbackBasic
       
   256         iRepository.Get( KTactileVibraIntensityBasicLevel2, 
       
   257                           basicParams.iIntensity );
       
   258         iRepository.Get( KTactileVibraDurationBasicLevel2,  
       
   259                           basicParams.iTime );
       
   260         
       
   261         // Read settings for ETouchFeedbackSensitive
       
   262         iRepository.Get( KTactileVibraIntensitySensitiveLevel2, 
       
   263                           sensitiveParams.iIntensity );
       
   264         iRepository.Get( KTactileVibraDurationSensitiveLevel2,  
       
   265                           sensitiveParams.iTime );
       
   266         }
       
   267     else if ( iVibraLevel == EProfileTactileFeedbackLevel3 )
       
   268         {
       
   269         // Read settings for ETouchFeedbackBasic
       
   270         iRepository.Get( KTactileVibraIntensityBasicLevel3, 
       
   271                           basicParams.iIntensity );
       
   272         iRepository.Get( KTactileVibraDurationBasicLevel3,  
       
   273                           basicParams.iTime );
       
   274         
       
   275         // Read settings for ETouchFeedbackSensitive
       
   276         iRepository.Get( KTactileVibraIntensitySensitiveLevel3, 
       
   277                           sensitiveParams.iIntensity );
       
   278         iRepository.Get( KTactileVibraDurationSensitiveLevel3,  
       
   279                           sensitiveParams.iTime );
       
   280         }
       
   281     
       
   282     iVibraParams.Reset();
       
   283 
       
   284     iVibraParams.Append( basicParams );        
       
   285     iVibraParams.Append( sensitiveParams );         
       
   286     TRACE("CTactileVibraPlayer::ReadSettings - End");      
       
   287     }    
       
   288     
       
   289 // ---------------------------------------------------------------------------
       
   290 // Actually play feedback.
       
   291 // ---------------------------------------------------------------------------
       
   292 //
       
   293 void CTactileVibraPlayer::DoPlayFeedbackL( TInt aTime, TInt aIntensity )
       
   294     {
       
   295     TRACE("CTactileVibraPlayer::DoPlayFeedbackL - Begin");
       
   296     if ( !iVibra )
       
   297         {
       
   298         // Construct iVibra at first feedback request.
       
   299         iVibra = CHWRMVibra::NewL();
       
   300         }
       
   301     
       
   302     TRACE("CTactileVibraPlayer::DoPlayFeedbackL - Starting Vibra");
       
   303     
       
   304     OstTrace0( TACTILE_PERFORMANCE, TACTILE_PLAY_VIBRA_FEEDBACK_1, "e_TACTILE_PLAY_VIBRA_FEEDBACK 1");
       
   305     
       
   306     iVibra->PulseVibraL( aTime, aIntensity ); 
       
   307 
       
   308     OstTrace0( TACTILE_PERFORMANCE, TACTILE_PLAY_VIBRA_FEEDBACK_0, "e_TACTILE_PLAY_VIBRA_FEEDBACK 0");
       
   309     TRACE("CTactileVibraPlayer::DoPlayFeedbackL - End");
       
   310     }
       
   311 
       
   312 // ---------------------------------------------------------------------------
       
   313 //
       
   314 // ---------------------------------------------------------------------------
       
   315 //    
       
   316 void CTactileVibraPlayer::DoStartFeedbackL( TTouchContinuousFeedback /*aType*/,
       
   317                                             TInt /*aIntensity*/ )
       
   318     {
       
   319     if ( !iVibra )
       
   320         {
       
   321         // Construct iVibra at first feedback request.
       
   322         iVibra = CHWRMVibra::NewL();
       
   323         }    
       
   324 
       
   325     if ( iVibraParams.Count() )
       
   326         {
       
   327         TRACE2("CTactileVibraPlayer: StartVibraL  Duration: %d", KHWRMVibraMaxDuration ); 
       
   328         TRACE2("CTactileVibraPlayer: StartVibraL  Intensity: %d", iVibraParams[0].iIntensity );
       
   329         iVibra->StartVibraL( KHWRMVibraMaxDuration, 
       
   330                              iVibraParams[0].iIntensity );
       
   331         }    
       
   332     }                                            
       
   333 
       
   334 // ---------------------------------------------------------------------------
       
   335 // From MCenRepNotifyHandlerCallback.
       
   336 // ---------------------------------------------------------------------------
       
   337 //    
       
   338 void CTactileVibraPlayer::HandleNotifyInt( TUint32 aId, TInt aNewValue )    
       
   339     {
       
   340     TRACE("CTactileVibraPlayer::HandleNotifyInt - Begin");
       
   341     if ( aId == KTactileFeedbackHapticsStrength )
       
   342         {
       
   343         iVibraLevel = aNewValue;
       
   344         if ( iVibraLevel != EProfileTactileFeedbackOff )
       
   345             {
       
   346             ReadSettings();    
       
   347             }
       
   348         }
       
   349     TRACE("CTactileVibraPlayer::HandleNotifyInt - End");
       
   350     }
       
   351 
       
   352 //---------------------------------------------------------------------------
       
   353 // ImplementationTable[]
       
   354 //
       
   355 //---------------------------------------------------------------------------
       
   356 //
       
   357 const TImplementationProxy ImplementationTable[] = 
       
   358     {
       
   359     IMPLEMENTATION_PROXY_ENTRY( 0x2001CB9B, CTactileVibraPlayer::NewL )
       
   360     };
       
   361 
       
   362 //---------------------------------------------------------------------------
       
   363 // TImplementationProxy* ImplementationGroupProxy()
       
   364 //
       
   365 //---------------------------------------------------------------------------
       
   366 //
       
   367 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount )
       
   368     {
       
   369     aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
   370     return ImplementationTable;
       
   371     }
       
   372    
       
   373 // End of file