bluetoothengine/btsac/btrcc/src/btrccAbsoluteVolumeLevelController.cpp
branchRCL_3
changeset 21 53b7818cd282
parent 0 f63038272f30
child 45 b0aebde9b1fb
equal deleted inserted replaced
20:2f88a7d66f50 21:53b7818cd282
    26 #include "btrccAbsoluteVolumeLevelController.h"
    26 #include "btrccAbsoluteVolumeLevelController.h"
    27 #include "debug.h"
    27 #include "debug.h"
    28 
    28 
    29 const TInt KAbsoluteVolumeLevelSetServiceId = 0x02; 
    29 const TInt KAbsoluteVolumeLevelSetServiceId = 0x02; 
    30 const TInt KMaxRetries = 3;
    30 const TInt KMaxRetries = 3;
       
    31 const TInt KDefaultStep = 1000;
    31 
    32 
    32 // MODULE DATA STRUCTURES
    33 // MODULE DATA STRUCTURES
    33 
    34 
    34 // ================= MEMBER FUNCTIONS =======================
    35 // ================= MEMBER FUNCTIONS =======================
    35 
    36 
    51 // CBTRCCAbsoluteVolumeLevelController::CBTRCCAbsoluteVolumeLevelController
    52 // CBTRCCAbsoluteVolumeLevelController::CBTRCCAbsoluteVolumeLevelController
    52 // C++ constructor.
    53 // C++ constructor.
    53 // -----------------------------------------------------------------------------
    54 // -----------------------------------------------------------------------------
    54 //
    55 //
    55 CBTRCCAbsoluteVolumeLevelController::CBTRCCAbsoluteVolumeLevelController(MBTRCCVolumeControllerObserver& aObserver)
    56 CBTRCCAbsoluteVolumeLevelController::CBTRCCAbsoluteVolumeLevelController(MBTRCCVolumeControllerObserver& aObserver)
    56 : CBTRCCVolumeLevelControllerBase(aObserver)
    57 : CBTRCCVolumeLevelControllerBase(aObserver), iStep(KDefaultStep)
    57 	{
    58 	{
    58 	}
    59 	}
    59 
    60 
    60 // -----------------------------------------------------------------------------
    61 // -----------------------------------------------------------------------------
    61 // CBTRCCAbsoluteVolumeLevelController::ConstructL
    62 // CBTRCCAbsoluteVolumeLevelController::ConstructL
   151     iRemConAbsoluteVolumeController->CancelAbsoluteVolumeNotification(); 
   152     iRemConAbsoluteVolumeController->CancelAbsoluteVolumeNotification(); 
   152     iRemConAbsoluteVolumeController->RegisterAbsoluteVolumeNotification();
   153     iRemConAbsoluteVolumeController->RegisterAbsoluteVolumeNotification();
   153     }
   154     }
   154 
   155 
   155 // -----------------------------------------------------------------------------
   156 // -----------------------------------------------------------------------------
   156 // CBTRCCAbsoluteVolumeLevelController::GetPhoneVolume
   157 // CBTRCCAbsoluteVolumeLevelController::RoundRemoteVolume
   157 // -----------------------------------------------------------------------------
   158 // -----------------------------------------------------------------------------
   158 //
   159 //
   159 TInt CBTRCCAbsoluteVolumeLevelController::GetPhoneVolume(TInt &aVol)
   160 TInt CBTRCCAbsoluteVolumeLevelController::RoundRemoteVolume(TInt aPrevPhVol)
   160     {
   161     {
   161     TRACE_FUNC
   162     TRACE_FUNC
   162     return CBTRCCVolumeLevelControllerBase::GetPhoneVolume(aVol);
   163     TInt phoneVol = GetCurrentLocalVolume();
       
   164     TInt remoteVol = GetCurrentRemoteVolume();
       
   165     TRACE_INFO((_L("Volume to be rounded %d"), remoteVol))
       
   166     // Update step
       
   167     if( phoneVol != -1 && aPrevPhVol != -1 )
       
   168         {
       
   169         TInt step = Abs( phoneVol - aPrevPhVol );
       
   170         if( step )
       
   171             {
       
   172             TRACE_INFO((_L("Step %d"), step))
       
   173             // Only update step value if it is not equal to zero
       
   174             iStep = step;
       
   175             }
       
   176         }    
       
   177     if( remoteVol >= 0 && remoteVol <= iLocalMaxVolume )
       
   178         {        
       
   179         TInt lowLimit = 0;
       
   180         TInt highLimit = 0;
       
   181         
       
   182         for( TInt i = 0 ; highLimit < iLocalMaxVolume ; i++ )
       
   183             {
       
   184             lowLimit = i*iStep;
       
   185             highLimit = (i+1)*iStep;
       
   186             // Find the correct low and high value pair in which volume
       
   187             // belongs.
       
   188             if( remoteVol >= lowLimit && remoteVol <= highLimit )
       
   189                 {
       
   190                 break;
       
   191                 }
       
   192             }
       
   193         TInt diff1 = Abs( remoteVol - lowLimit );
       
   194         TInt diff2 = Abs( remoteVol - highLimit );
       
   195         remoteVol = diff1 <= diff2 ? lowLimit : highLimit;
       
   196         }
       
   197     TRACE_INFO((_L("Rounded volume %d"), remoteVol))
       
   198     return remoteVol;
   163     }
   199     }
   164 
   200 
   165 // -----------------------------------------------------------------------------
   201 // -----------------------------------------------------------------------------
   166 // CBTRCCAbsoluteVolumeLevelController::RequestCompletedL
   202 // CBTRCCAbsoluteVolumeLevelController::RequestCompletedL
   167 // -----------------------------------------------------------------------------
   203 // -----------------------------------------------------------------------------