javaextensions/sensor/src.s60/cpsbatterychargesensor.cpp
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     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:  Battery Level sensor implementation
       
    15 *
       
    16 */
       
    17 
       
    18 #include <hwrmpowerstatesdkpskeys.h>
       
    19 #include <e32math.h>
       
    20 #include "cpsbatterychargesensor.h"
       
    21 #include "csensorproperties.h"
       
    22 #include "logger.h"
       
    23 
       
    24 _LIT(KBatteryLevelSensorDescriptionPart1,
       
    25      "battery_charge#"
       
    26      L"device#"
       
    27      L"device#"
       
    28      L"Nokia#"
       
    29      L"description=");
       
    30 _LIT(KBatteryLevelSensorDescriptionPart2,
       
    31      "#model=Nokia#"
       
    32      L"connectiontype=1#"
       
    33      L"1#" // isAvailable
       
    34      L"1#" // channel count
       
    35      L"battery_charge#" // channel name. for single channel sensors should be same as model
       
    36      L"0.1429#" // accuracy, 7 steps (0-7)
       
    37      L"2#" // data type. here TYPE_INT
       
    38      L"0#" // scale. here zero (means that scaling is not used)
       
    39      L"%#" // unit. percent
       
    40      L"1#" // measurement range count
       
    41      L"0#" // smallest measurable value
       
    42      L"100#" // largest measurable value
       
    43      L"14.29#" // measurement resolution
       
    44      L"@ch_end#");  // channel terminator constant
       
    45 
       
    46 const TInt KPollInterval = 100000; // 0.1 sec
       
    47 const TReal KInterpretMultiplier = 14.29f;
       
    48 
       
    49 CPSBatteryChargeSensor* CPSBatteryChargeSensor::NewL()
       
    50 {
       
    51     JELOG2(ESensor);
       
    52     CPSBatteryChargeSensor* self = new(ELeave)CPSBatteryChargeSensor();
       
    53     CleanupStack::PushL(self);
       
    54     self->ConstructL(KPSUidHWRMPowerState, KHWRMBatteryLevel);
       
    55     CleanupStack::Pop(); // self
       
    56     return self;
       
    57 }
       
    58 
       
    59 CPSBatteryChargeSensor::CPSBatteryChargeSensor()
       
    60         : CPSSensorBase(KPollInterval)
       
    61 {
       
    62     JELOG2(ESensor);
       
    63 }
       
    64 
       
    65 CPSBatteryChargeSensor::~CPSBatteryChargeSensor()
       
    66 {
       
    67 }
       
    68 
       
    69 HBufC* CPSBatteryChargeSensor::CreateDescriptionLC()
       
    70 {
       
    71     JELOG2(ESensor);
       
    72     HBufC* desc = HBufC::NewLC(KMaxSensorDescriptionLength);
       
    73     TPtr desPtr = desc->Des();
       
    74     desPtr.Append(KBatteryLevelSensorDescriptionPart1);
       
    75     desPtr.Append(SensorProperties::GetPropertyString(KSensorDescription,
       
    76                   EBatteryChargeSensor));
       
    77     desPtr.Append(KBatteryLevelSensorDescriptionPart2);
       
    78     return desc;
       
    79 }
       
    80 
       
    81 CSensorBase* CPSBatteryChargeSensor::DuplicateL()
       
    82 {
       
    83     JELOG2(ESensor);
       
    84     return NewL();
       
    85 }
       
    86 
       
    87 TReal CPSBatteryChargeSensor::InterpretValue(TReal aValue)
       
    88 {
       
    89     JELOG2(ESensor);
       
    90     if (aValue > 0)
       
    91     {
       
    92         TReal value = KInterpretMultiplier * aValue;
       
    93         TInt32 retVal;
       
    94         Math::Round(value, value, 0);
       
    95         Math::Int(retVal, value);
       
    96         return retVal;
       
    97     }
       
    98     else
       
    99     {
       
   100         return aValue;
       
   101     }
       
   102 }
       
   103