exampleapps/alfexanalogdialer/src/alfexanalogdialerfeedback.cpp
changeset 0 15bf7259bb7c
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2008-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 Analog Dialer example application, which
       
    15 *                implements long lasting tactile feed back event
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #include <touchfeedback.h>
       
    22 
       
    23 #include "alfexanalogdialerfeedback.h"
       
    24 
       
    25 // constants
       
    26 
       
    27 // minimum values for clock in milliseconds
       
    28 const TInt KFeedbackMinimumDuration = 100;
       
    29 const TInt KFeedbackMinimumInterval = 100;
       
    30 
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // NewLC
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 CAlfExAnalogDialerFeedback* CAlfExAnalogDialerFeedback::NewL()
       
    37     {
       
    38     CAlfExAnalogDialerFeedback* self = new (ELeave) CAlfExAnalogDialerFeedback();
       
    39     CleanupStack::PushL(self);
       
    40     self->ConstructL();
       
    41     CleanupStack::Pop(self);
       
    42     return self;
       
    43     }
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 CAlfExAnalogDialerFeedback::CAlfExAnalogDialerFeedback()
       
    50     {
       
    51     }
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 CAlfExAnalogDialerFeedback::~CAlfExAnalogDialerFeedback()
       
    58     {
       
    59     if ( iClock )
       
    60         {
       
    61         iClock->Cancel();
       
    62         delete iClock;
       
    63         }
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 void CAlfExAnalogDialerFeedback::ConstructL()
       
    71     {
       
    72     iFeedback = MTouchFeedback::Instance();
       
    73     // Remote control server command repeat timer.
       
    74     iClock = CPeriodic::NewL( EPriorityNormal );
       
    75     }
       
    76 
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 void CAlfExAnalogDialerFeedback::Start( TInt    aDurationMilliSeconds,
       
    82                                         TInt    aIntervalMilliSeconds)
       
    83     {
       
    84     iDuration = KFeedbackDefault;
       
    85     iInterval = KFeedbackMinimumInterval;
       
    86 
       
    87     // 1000: convert millis to micros
       
    88     if (iFeedback)
       
    89         {
       
    90         iFeedback->InstantFeedback(ETouchFeedbackBasic);
       
    91         }
       
    92     if ( aIntervalMilliSeconds > KFeedbackMinimumInterval )
       
    93         {
       
    94         iInterval = 1000*aIntervalMilliSeconds;   
       
    95         }
       
    96     if (aDurationMilliSeconds >= KFeedbackMinimumDuration)
       
    97         {    
       
    98         iDuration = 1000*aDurationMilliSeconds;   
       
    99         iDurationStop.HomeTime();
       
   100         iDurationStop +=  TTimeIntervalMicroSeconds(TInt64(iDuration));
       
   101         iClock->Cancel();
       
   102         iClock->Start(  iInterval,
       
   103                         iInterval, 
       
   104                         TCallBack( HandleInterval, this ));
       
   105         }
       
   106     }
       
   107 
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 void CAlfExAnalogDialerFeedback::Stop()
       
   113     {
       
   114     iClock->Cancel();
       
   115     }
       
   116 
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 // ---------------------------------------------------------------------------
       
   120 //
       
   121 void CAlfExAnalogDialerFeedback::DoHandleInterval()
       
   122     {
       
   123     TTime timeNow;
       
   124     timeNow.HomeTime();
       
   125     if (timeNow > iDurationStop)
       
   126         {
       
   127         iClock->Cancel();
       
   128         }
       
   129     else
       
   130         {
       
   131         if (iFeedback)
       
   132             {
       
   133             iFeedback->InstantFeedback(ETouchFeedbackBasic);
       
   134             }
       
   135         }
       
   136     }
       
   137 
       
   138 
       
   139 // ---------------------------------------------------------------------------
       
   140 //
       
   141 // ---------------------------------------------------------------------------
       
   142 //
       
   143 TInt CAlfExAnalogDialerFeedback::HandleInterval(TAny* aThis)
       
   144     {
       
   145     // cast, and call non-static function
       
   146     static_cast<CAlfExAnalogDialerFeedback*>(aThis)->DoHandleInterval();
       
   147     return KErrNone;
       
   148     }