javaextensions/sensor/src.s60/cpschargerstatesensor.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:  Charger state sensor implementation
       
    15 *
       
    16 */
       
    17 
       
    18 #include <hwrmpowerstatesdkpskeys.h>
       
    19 #include "cpschargerstatesensor.h"
       
    20 #include "csensorproperties.h"
       
    21 #include "logger.h"
       
    22 
       
    23 _LIT(KChargerStateSensorDescriptionPart1,
       
    24      "charger_state#"
       
    25      L"device#"
       
    26      L"device#"
       
    27      L"Nokia#"
       
    28      L"description=");
       
    29 
       
    30 _LIT(KChargerStateSensorDescriptionPart2,
       
    31      "#model=Nokia#"
       
    32      L"connectiontype=1#"
       
    33      L"1#" // isAvailable
       
    34      L"1#" // channel count
       
    35      L"charger_state#" // channel name. for single channel sensors should be same as model
       
    36      L"0#" // accuracy, exact
       
    37      L"2#" // data type. here TYPE_INT
       
    38      L"0#" // scale. here zero (means that scaling is not used)
       
    39      L"boolean#" // unit. Charger is attached or not attached
       
    40      L"1#" // measurement range count
       
    41      L"0#" // smallest measurable value
       
    42      L"1#" // largest measurable value
       
    43      L"1#" // measurement resolution
       
    44      L"@ch_end#");  // channel terminator constant
       
    45 
       
    46 const TInt KPollInterval = 100000; // 0.1 sec
       
    47 
       
    48 CPSChargerStateSensor* CPSChargerStateSensor::NewL()
       
    49 {
       
    50     JELOG2(ESensor);
       
    51     CPSChargerStateSensor* self = new(ELeave)CPSChargerStateSensor();
       
    52     CleanupStack::PushL(self);
       
    53     self->ConstructL(KPSUidHWRMPowerState, KHWRMChargingStatus);
       
    54     CleanupStack::Pop(); // self
       
    55     return self;
       
    56 }
       
    57 
       
    58 CPSChargerStateSensor::CPSChargerStateSensor()
       
    59         : CPSSensorBase(KPollInterval)
       
    60 {
       
    61     JELOG2(ESensor);
       
    62 }
       
    63 
       
    64 CPSChargerStateSensor::~CPSChargerStateSensor()
       
    65 {
       
    66     JELOG2(ESensor);
       
    67 }
       
    68 
       
    69 HBufC* CPSChargerStateSensor::CreateDescriptionLC()
       
    70 {
       
    71     JELOG2(ESensor);
       
    72     HBufC* desc = HBufC::NewLC(KMaxSensorDescriptionLength);
       
    73     TPtr desPtr = desc->Des();
       
    74     desPtr.Append(KChargerStateSensorDescriptionPart1);
       
    75     desPtr.Append(SensorProperties::GetPropertyString(KSensorDescription,
       
    76                   EChargerStateSensor));
       
    77     desPtr.Append(KChargerStateSensorDescriptionPart2);
       
    78     return desc;
       
    79 }
       
    80 
       
    81 CSensorBase* CPSChargerStateSensor::DuplicateL()
       
    82 {
       
    83     JELOG2(ESensor);
       
    84     return NewL();
       
    85 }
       
    86 
       
    87 TReal CPSChargerStateSensor::InterpretValue(TReal aValue)
       
    88 {
       
    89     JELOG2(ESensor);
       
    90     // Return 1 if aValue is bigger than 0. Return 0 if 0.
       
    91     // Negative aValue is an error code and is returned as is.
       
    92     return aValue > 0 ? 1 : aValue;
       
    93 }
       
    94