×
Namespaces

Variants
Actions
(Difference between revisions)

Archived:Controlling light settings using CHWRMLight

From Nokia Developer Wiki
Jump to: navigation, search
Forum Nokia KB (Talk | contribs)
hamishwillee (Talk | contribs)
 
(10 intermediate revisions by 6 users not shown)
Line 1: Line 1:
__NOTOC__
+
{{Archived|timestamp=20120314040145|user=roy.debjit| }}
__NOEDITSECTION__
+
[[Category:Symbian C++]][[Category:Code Snippet]][[Category:Hardware]][[Category:S60 3rd Edition FP1]][[Category:Code Snippet]]
  
{|style="background:#eceff2" width="660px" border="1" cellpadding="5" cellspacing="0"
+
{{ArticleMetaData <!-- v1.2 -->
|-
+
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
|'''ID''' || &nbsp;
+
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
|'''Creation date''' || April 17, 2008
+
|devices= Nokia N95
|-
+
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
|'''Platform''' || S60 3rd Edition, FP1
+
|platform= S60 3rd Edition FP1
|'''Tested on devices''' || Nokia N95
+
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
|-
+
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
|'''Category''' || Symbian C++
+
|signing= <!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
|'''Subcategory''' || Hardware
+
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
|}
+
|keywords= CHWRMLight,MHWRMLightObserver,CHWRMLight::TLightStatus, CHWRMLight::ReserveLightL(), CHWRMLight::ReleaseLight(), CHWRMLight::LightOnL(), CHWRMLight::LightBlinkL(), CHWRMLight::LightOffL(), CHWRMLight::LightStatus(), MHWRMLightObserver::LightStatusChanged()
 
+
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 
+
|translated-by= <!-- [[User:XXXX]] -->
{|style="background:#eceff2" width="660px" border="1" cellpadding="5" cellspacing="0"
+
|translated-from-title= <!-- Title only -->
|-
+
|translated-from-id= <!-- Id of translated revision -->
|'''Keywords (APIs, classes, methods, functions):''' CHWRMLight,MHWRMLightObserver,CHWRMLight::TLightStatus, CHWRMLight::ReserveLightL(), CHWRMLight::ReleaseLight(), CHWRMLight::LightOnL(), CHWRMLight::LightBlinkL(), CHWRMLight::LightOffL(), CHWRMLight::LightStatus(), MHWRMLightObserver::LightStatusChanged()
+
|review-by= <!-- After re-review: [[User:username]] -->
|}
+
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 +
|update-by= <!-- After significant update: [[User:username]]-->
 +
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate= 20080417
 +
|author= [[User:Aknyman]]
 +
<!-- The following are not in current metadata -->
 +
|subcategory= Hardware
 +
|id= CS000912
 +
}}
  
 
==Overview==
 
==Overview==
This snippet shows how the <tt>CHWRMLight</tt> class can be used to control light settings. The example class <tt>CLightController</tt> contains methods to reserve and release light targets, set light target on, off or blinking and it also receives notifications about light target status changes by implementing interface <tt>MHWRMLightObserver</tt>.
+
{{Abstract|This code snippet shows how the {{Icode|CHWRMLight}} class can be used to control light settings.}} The example class {{Icode|CLightController}} contains methods to reserve and release light targets, set light target to on, off, or blinking, and it also receives notifications about light target status changes by implementing the interface {{Icode|MHWRMLightObserver}}.
  
 
This snippet can be self-signed.
 
This snippet can be self-signed.
Line 427: Line 435:
 
         if( queryDlg->ExecuteLD( R_LIGHTCONTROLLER_LIGHT_INTENSITY_QUERY ) )
 
         if( queryDlg->ExecuteLD( R_LIGHTCONTROLLER_LIGHT_INTENSITY_QUERY ) )
 
             {
 
             {
             // got the intenstity
+
             // got the intensity
 
             CAknListQueryDialog* listDlg = new (ELeave)CAknListQueryDialog( &item );
 
             CAknListQueryDialog* listDlg = new (ELeave)CAknListQueryDialog( &item );
 
             if( listDlg->ExecuteLD(R_LIGHTCONTROLLER_FADE_LIST) )
 
             if( listDlg->ExecuteLD(R_LIGHTCONTROLLER_FADE_LIST) )
Line 751: Line 759:
  
  
* in header file:
+
* In the header file:
  
 
<code cpp>
 
<code cpp>
Line 766: Line 774:
 
</code>
 
</code>
  
* in source file:
+
* In the source file:
  
 
<code cpp>
 
<code cpp>
Line 789: Line 797:
 
   /*
 
   /*
 
     1. target - the light device that should be controlled (display, keyboard,  
 
     1. target - the light device that should be controlled (display, keyboard,  
     hardware specific custom target)
+
     hardware-specific custom target)
 
     2. param - restore: if ETrue is selected, the light state on last release  
 
     2. param - restore: if ETrue is selected, the light state on last release  
 
     will be restored  
 
     will be restored  
 
     upon successful reservation.
 
     upon successful reservation.
     3. param - NoCCoeEnv: if EFalse is selected light target will be automatically
+
     3. param - NoCCoeEnv: if EFalse is selected, the light target will be automatically
 
     released when the  
 
     released when the  
 
     application goes to background and reserved when the application is restored  
 
     application goes to background and reserved when the application is restored  
Line 822: Line 830:
 
   /*  
 
   /*  
 
   1. param - target: the light device that should be controlled (display,  
 
   1. param - target: the light device that should be controlled (display,  
   keyboard, hardware specific custom target)
+
   keyboard, hardware-specific custom target)
   2-4. - params durations: times in milliseconds light target will be active  
+
   2-4. - params durations: times in milliseconds that the light target will be active  
 
   5. param - intensity: percentage of full light intensity   
 
   5. param - intensity: percentage of full light intensity   
 
   */
 
   */
Line 835: Line 843:
 
   /*  
 
   /*  
 
   1. param - target: the light device that should be controlled (display, keyboard,
 
   1. param - target: the light device that should be controlled (display, keyboard,
   hardware specific custom target)
+
   hardware-specific custom target)
   2. param - duration: time in milliseconds light target will be active
+
   2. param - duration: time in milliseconds that the light target will be active
 
   3. param - fade: if ETrue is selected, the light target will be turned
 
   3. param - fade: if ETrue is selected, the light target will be turned
 
   on/off gradually (fade-in/fade-out)
 
   on/off gradually (fade-in/fade-out)
Line 864: Line 872:
 
==Postconditions==
 
==Postconditions==
  
The CLightController class controls light settings and receives light target status change information.
+
The CLightController class controls light settings and receives information on light target status changes.
  
 
<!--
 
<!--
 
==See also==
 
==See also==
 
-->
 
-->
 
[[Category:Symbian C++]][[Category:Code Examples]][[Category:Hardware]]
 

Latest revision as of 04:51, 19 June 2012

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Article Metadata
Tested with
Devices(s): Nokia N95
Compatibility
Platform(s): S60 3rd Edition FP1
S60 3rd Edition FP1
Article
Keywords: CHWRMLight,MHWRMLightObserver,CHWRMLight::TLightStatus, CHWRMLight::ReserveLightL(), CHWRMLight::ReleaseLight(), CHWRMLight::LightOnL(), CHWRMLight::LightBlinkL(), CHWRMLight::LightOffL(), CHWRMLight::LightStatus(), MHWRMLightObserver::LightStatusChanged()
Created: aknyman (17 Apr 2008)
Last edited: hamishwillee (19 Jun 2012)

Contents

[edit] Overview

This code snippet shows how the CHWRMLight class can be used to control light settings. The example class CLightController contains methods to reserve and release light targets, set light target to on, off, or blinking, and it also receives notifications about light target status changes by implementing the interface MHWRMLightObserver.

This snippet can be self-signed.

[edit] MMP file

The following libraries are required:

LIBRARY HWRMLightClient.lib
LIBRARY avkon.lib //CAknListQueryDialog CAknNumberQueryDialog

[edit] Resource file

#include <eikon.rh>
#include <avkon.rsg>
#include <avkon.rh>
 
RESOURCE ARRAY r_lightcontroller_bool_items
{
items =
{
LBUF { txt = "EFalse"; },
LBUF { txt = "ETrue"; }
};
}
 
RESOURCE DIALOG r_lightcontroller_light_intensity_query
{
flags=EGeneralQueryFlags;
buttons=R_AVKON_SOFTKEYS_OK_CANCEL;
items=
{
DLG_LINE
{
type=EAknCtQuery;
id=EGeneralQuery;
control= AVKON_DATA_QUERY
{
layout = ENumberLayout;
label = "Enter light intensity (0 to 100)";
control = AVKON_INTEGER_EDWIN
{
min=0;
max=100;
};
};
}
};
}
 
RESOURCE DIALOG r_lightcontroller_duration_query
{
flags=EGeneralQueryFlags;
buttons=R_AVKON_SOFTKEYS_OK_CANCEL;
items=
{
DLG_LINE
{
type=EAknCtQuery;
id=EGeneralQuery;
control= AVKON_DATA_QUERY
{
layout = ENumberLayout;
label = "Enter duration (0 to 2147482)";
control = AVKON_INTEGER_EDWIN
{
min=0;
max=2147482;
};
};
}
};
}
 
RESOURCE ARRAY r_lightcontroller_lightstarget_items
{
items =
{
LBUF { txt = "ENoTarget"; },
LBUF { txt = "EPrimaryDisplay"; },
LBUF { txt = "EPrimaryKeyboard"; },
LBUF { txt = "EPrimaryDisplayAndKeyboard"; },
LBUF { txt = "ESecondaryDisplay"; },
LBUF { txt = "ESecondaryKeyboard"; },
LBUF { txt = "ESecondaryDisplayAndKeyboard"; },
LBUF { txt = "ECustomTarget1"; },
LBUF { txt = "ECustomTarget2"; },
LBUF { txt = "ECustomTarget3"; },
LBUF { txt = "ECustomTarget4"; }
};
}
 
RESOURCE DIALOG r_lightcontroller_lightstarget_list
{
flags = EGeneralQueryFlags;
buttons = R_AVKON_SOFTKEYS_OK_CANCEL;
items =
{
DLG_LINE
{
type = EAknCtListQueryControl;
id = EListQueryControl;
control = AVKON_LIST_QUERY_CONTROL
{
listtype = EAknCtSinglePopupMenuListBox;
heading = "Lights target:";
listbox = LISTBOX
{
flags = EAknListBoxSelectionList;
array_id = r_lightcontroller_lightstarget_items;
};
};
}
};
}
 
RESOURCE AVKON_LIST_QUERY r_lightcontroller_restore_list
{
flags = EGeneralQueryFlags;
items =
{
AVKON_LIST_QUERY_DLG_LINE
{
type = EAknCtListQueryControl;
id = EListQueryControl;
control = AVKON_LIST_QUERY_CONTROL
{
listtype = EAknCtSinglePopupMenuListBox;
heading = "Restore parameter:";
listbox = LISTBOX
{
flags = EAknListBoxSelectionList;
array_id = r_lightcontroller_bool_items;
};
};
}
};
}
 
RESOURCE AVKON_LIST_QUERY r_lightcontroller_noccoeenv_list
{
flags = EGeneralQueryFlags;
items =
{
AVKON_LIST_QUERY_DLG_LINE
{
type = EAknCtListQueryControl;
id = EListQueryControl;
control = AVKON_LIST_QUERY_CONTROL
{
listtype = EAknCtSinglePopupMenuListBox;
heading = "NoCCoeEnv parameter:";
listbox = LISTBOX
{
flags = EAknListBoxSelectionList;
array_id = r_lightcontroller_bool_items;
};
};
}
};
}
 
RESOURCE AVKON_LIST_QUERY r_lightcontroller_fade_list
{
flags = EGeneralQueryFlags;
items =
{
AVKON_LIST_QUERY_DLG_LINE
{
type = EAknCtListQueryControl;
id = EListQueryControl;
control = AVKON_LIST_QUERY_CONTROL
{
listtype = EAknCtSinglePopupMenuListBox;
heading = "Fade parameter:";
listbox = LISTBOX
{
flags = EAknListBoxSelectionList;
array_id = r_lightcontroller_bool_items;
};
};
}
};
}


[edit] Header file

 #ifndef LIGHTCONTROLLER_H
#define LIGHTCONTROLLER_H
 
#include <HWRMLight.h>
 
class CLightController : public CBase,
public MHWRMLightObserver
 
{
public:
static CLightController* NewL();
~CLightController();
 
//ask reserve parameters with dialogs
void LightsReserveL();
void LightsReserveL(TInt aTarget,
TBool aRestoreState,
TBool aForceNoCCoeEnv);
 
//ask light on parameters with dialogs
void LightsOnL();
void LightsOnL(TInt aTarget,
TInt aDuration,
TInt aIntensity,
TBool aFadeIn);
 
//ask light blink parameters with dialogs
void LightsBlinkL();
void LightsBlinkL(TInt aTarget,
TInt aDuration,
TInt aOnDuration,
TInt aOffDuration,
TInt aIntensity);
 
//ask light off parameters with dialogs
void LightsOffL();
void LightsOffL(TInt aTarget,
TInt aDuration,
TBool aFadeOut);
void LightsReleaseL(TInt aTarget=0);
 
CHWRMLight::TLightStatus LightsStatusL(TInt aTarget=0);
private:
 
void ConstructL();
 
// from MHWRMLightObserver
virtual void LightStatusChanged(TInt aTarget,
CHWRMLight::TLightStatus aStatus);
 
// returns the target or KErrCancel if user pressed cancel
TInt GetLightsTargetL();
private:
CHWRMLight* iLight;
};
 
#endif // LIGHTCONTROLLER_H

[edit] Source file

#include <aknNoteWrappers.h> //CAknListQueryDialog,CAknNumberQueryDialog
#include <LightController.rsg>
#include "LightController.h"
 
CLightController* CLightController::NewL()
{
CLightController* self=
new(ELeave) CLightController( );
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop(self);
return self;
}
 
void CLightController::ConstructL()
{
iLight = CHWRMLight::NewL(this);
}
 
CLightController::~CLightController()
{
delete iLight;
}
 
void CLightController::LightsReserveL(TInt aTarget,
TBool aRestoreState,
TBool aForceNoCCoeEnv)
 
{
if(aTarget <= CHWRMLight::ENoTarget || aTarget > CHWRMLight::ECustomTarget4)
LightsReserveL();
else
iLight->ReserveLightL( aTarget, aRestoreState, aForceNoCCoeEnv );
}
 
void CLightController::LightsReserveL()
{
TInt item(0);
TBool restore;
TBool forceNoCCoeEnv;
TInt target(CHWRMLight::ENoTarget);
 
// get the lights target
target = GetLightsTargetL();
 
if( target == KErrCancel )
{
// no target entered, just return
return;
}
 
CAknListQueryDialog* listDlg = new (ELeave)CAknListQueryDialog( &item );
 
if( listDlg->ExecuteLD(R_LIGHTCONTROLLER_RESTORE_LIST) )
{
// got restore state parameter
item == 0 ? restore = EFalse : restore = ETrue;
//now get force no CCoeEnv parameter
listDlg = new (ELeave)CAknListQueryDialog( &item );
if( listDlg->ExecuteLD(R_LIGHTCONTROLLER_NOCCOEENV_LIST) )
{
// got ForceNoCCoeEnv parameter
item == 0 ? forceNoCCoeEnv = EFalse : forceNoCCoeEnv = ETrue;
iLight->ReserveLightL( target, restore, forceNoCCoeEnv );
}
else
{
// did not get ForceNoCCoeEnv parameter
// do not call ReserveLightL() at all
}
}
else
{
// did not get restore parameter
iLight->ReserveLightL( target );
}
 
}
 
void CLightController::LightsReleaseL(TInt aTarget)
{
TInt target(CHWRMLight::ENoTarget);
 
if(aTarget <= CHWRMLight::ENoTarget || aTarget > CHWRMLight::ECustomTarget4)
{
// get the lights target
target = GetLightsTargetL();
}
else
{
target = aTarget;
}
 
if( target == KErrCancel )
{
// no target entered
// do not call ReleaseLight at all
}
else
{
//call ReleaseLight with the given target
iLight->ReleaseLight( target );
}
}
 
void CLightController::LightsOnL(TInt aTarget,
TInt aDuration,
TInt aIntensity,
TBool aFadeIn)
{
 
 
if(aTarget <= CHWRMLight::ENoTarget || aTarget > CHWRMLight::ECustomTarget4 ||
aDuration < KHWRMInfiniteDuration || aDuration > KHWRMLightMaxDuration ||
aIntensity < KHWRMDefaultIntensity || aIntensity > KHWRMLightMaxIntensity)
{
LightsOnL();
}
else
{
iLight->LightOnL(aTarget, aDuration,
aIntensity, aFadeIn);
}
}
 
void CLightController::LightsOnL()
{
TInt item(0);
TInt duration(0);
TInt intensity(0);
TInt target(CHWRMLight::ENoTarget);
TBool fade(EFalse);
 
// get the lights target
target = GetLightsTargetL();
 
if( target == KErrCancel )
{
// no target entered
// do not call LightOnL at all
return;
}
 
//duration
CAknNumberQueryDialog* queryDlg = CAknNumberQueryDialog::NewL( duration );
if( queryDlg->ExecuteLD( R_LIGHTCONTROLLER_DURATION_QUERY ) )
{
// got duration so get intensity
queryDlg = CAknNumberQueryDialog::NewL( intensity );
if( queryDlg->ExecuteLD( R_LIGHTCONTROLLER_LIGHT_INTENSITY_QUERY ) )
{
// got the intensity
CAknListQueryDialog* listDlg = new (ELeave)CAknListQueryDialog( &item );
if( listDlg->ExecuteLD(R_LIGHTCONTROLLER_FADE_LIST) )
{
// got fade parameter
item == 0 ? fade = EFalse : fade = ETrue;
iLight->LightOnL( target, duration, intensity, fade );
}
else
{
// did not get fade parameter
// do not call LightOnL() at all
}
}
else
{
// user pressed cancel for intensity query
iLight->LightOnL( target, duration );
}
}
else
{
// didn't get duration so call basic API
iLight->LightOnL( target );
}
}
 
void CLightController::LightsBlinkL(TInt aTarget,
TInt aDuration,
TInt aOnDuration,
TInt aOffDuration,
TInt aIntensity)
{
if(aTarget <= CHWRMLight::ENoTarget || aTarget > CHWRMLight::ECustomTarget4 ||
aDuration < KHWRMInfiniteDuration || aDuration > KHWRMLightMaxDuration ||
aOnDuration < KHWRMInfiniteDuration || aOnDuration > KHWRMLightMaxDuration ||
aOffDuration < KHWRMInfiniteDuration || aOffDuration > KHWRMLightMaxDuration ||
aIntensity < KHWRMDefaultIntensity || aIntensity > KHWRMLightMaxIntensity)
{
LightsBlinkL();
}
else
{
iLight->LightBlinkL(aTarget, aDuration, aOnDuration,
aOffDuration, aIntensity);
}
}
 
void CLightController::LightsBlinkL()
{
TInt duration(0);
TInt onDuration(0);
TInt offDuration(0);
TInt intensity(0);
 
// get the lights target
TInt target = GetLightsTargetL();
if( target == KErrCancel )
{
// no target entered, just return
return;
}
 
// get duration
CAknNumberQueryDialog* queryDlg = CAknNumberQueryDialog::NewL( duration );
if( queryDlg->ExecuteLD( R_LIGHTCONTROLLER_DURATION_QUERY ) )
{
// got duration so get OnDuration
queryDlg = CAknNumberQueryDialog::NewL( onDuration );
CleanupStack::PushL( queryDlg );
 
_LIT(KEnterONDuration, "Enter ON duration (0 to 2147482)");
queryDlg->SetPromptL( KEnterONDuration );
 
CleanupStack::Pop( queryDlg );
if( queryDlg->ExecuteLD( R_LIGHTCONTROLLER_DURATION_QUERY ) )
{
// got OnDuration so get OffDuration
queryDlg = CAknNumberQueryDialog::NewL( offDuration );
CleanupStack::PushL( queryDlg );
 
_LIT(KEnterOFFDuration, "Enter OFF duration (0 to 2147482)");
queryDlg->SetPromptL( KEnterOFFDuration );
 
CleanupStack::Pop( queryDlg );
if( queryDlg->ExecuteLD( R_LIGHTCONTROLLER_DURATION_QUERY ) )
{
// got OffDuration so get intensity
queryDlg = CAknNumberQueryDialog::NewL( intensity );
if( queryDlg->ExecuteLD( R_LIGHTCONTROLLER_LIGHT_INTENSITY_QUERY ) )
{
// got the intenstity
iLight->LightBlinkL( target, duration, onDuration,
offDuration, intensity );
}
else
{
// user pressed cancel for intensity
// do not call LightBlinkL() at all
}
}
else
{
// user pressed cancel for OffDuration
// do not call LightBlinkL() at all
}
}
else
{
// user pressed cancel for OnDuration
iLight->LightBlinkL( target, duration );
}
}
else
{
// user pressed cancel for Duration
iLight->LightBlinkL( target );
}
}
 
void CLightController::LightsOffL(TInt aTarget,
TInt aDuration,
TBool aFadeOut)
{
if(aTarget <= CHWRMLight::ENoTarget || aTarget > CHWRMLight::ECustomTarget4 ||
aDuration < KHWRMInfiniteDuration || aDuration > KHWRMLightMaxDuration)
{
LightsOffL();
}
else
{
iLight->LightOffL(aTarget, aDuration, aFadeOut);
}
}
 
void CLightController::LightsOffL()
{
TInt item(0);
TInt duration(0);
TInt target(CHWRMLight::ENoTarget);
TBool fade(EFalse);
 
// get the lights target
target = GetLightsTargetL();
 
if( target == KErrCancel )
{
// no target entered, just return
return;
}
 
//duration
CAknNumberQueryDialog* queryDlg = CAknNumberQueryDialog::NewL( duration );
if( queryDlg->ExecuteLD( R_LIGHTCONTROLLER_DURATION_QUERY ) )
{
// got duration so get fade
CAknListQueryDialog* listDlg = new (ELeave)CAknListQueryDialog( &item );
if( listDlg->ExecuteLD(R_LIGHTCONTROLLER_FADE_LIST) )
{
// got fade parameter
item == 0 ? fade = EFalse : fade = ETrue;
iLight->LightOffL( target, duration, fade );
}
else
{
// did not get fade parameter
iLight->LightOffL( target, duration );
}
}
else
{
// didn't get duration so call basic API
iLight->LightOffL( target );
}
}
 
CHWRMLight::TLightStatus CLightController::LightsStatusL(TInt aTarget)
{
TInt target(CHWRMLight::ENoTarget);
 
if(aTarget <= CHWRMLight::ENoTarget || aTarget > CHWRMLight::ECustomTarget4)
{
// get the lights target
target = GetLightsTargetL();
}
else
{
target = aTarget;
}
 
if( target == KErrCancel )
{
// no target entered
return CHWRMLight::ELightStatusUnknown;
}
else
{
return iLight->LightStatus( target );
}
}
 
TInt CLightController::GetLightsTargetL()
{
TInt item(0);
TInt ret(KErrCancel);
 
CAknListQueryDialog* listDlg = new (ELeave)CAknListQueryDialog( &item );
if( listDlg->ExecuteLD(R_LIGHTCONTROLLER_LIGHTSTARGET_LIST) )
{
// This is a lookup table for the items defined in the
// resource array r_lightcontroller_lightstarget_items
switch ( item )
{
case 0: // ENoTarget
{
ret = CHWRMLight::ENoTarget;
break;
}
case 1: // EPrimaryDisplay
{
ret = CHWRMLight::EPrimaryDisplay;
break;
}
case 2: // EPrimaryKeyboard
{
ret = CHWRMLight::EPrimaryKeyboard;
break;
}
case 3: // EPrimaryDisplayAndKeyboard
{
ret = CHWRMLight::EPrimaryDisplayAndKeyboard;
break;
}
case 4: // ESecondaryDisplay
{
ret = CHWRMLight::ESecondaryDisplay;
break;
}
case 5: // ESecondaryKeyboard
{
ret = CHWRMLight::ESecondaryKeyboard;
break;
}
case 6: // ESecondaryDisplayAndKeyboard
{
ret = CHWRMLight::ESecondaryDisplayAndKeyboard;
break;
}
case 7: // ECustomTarget1
{
ret = CHWRMLight::ECustomTarget1;
break;
}
case 8: // ECustomTarget2
{
ret = CHWRMLight::ECustomTarget2;
break;
}
case 9: // ECustomTarget3
{
ret = CHWRMLight::ECustomTarget3;
break;
}
case 10: // ECustomTarget4
{
ret = CHWRMLight::ECustomTarget4;
break;
}
default:
break;
}
}
else
{
// no target entered
ret = KErrCancel;
}
 
return ret;
}
 
void CLightController::LightStatusChanged(TInt aTarget,
CHWRMLight::TLightStatus aStatus)
{
if(!aTarget)
{
//No target specified
}
 
switch ( aStatus )
{
case CHWRMLight::ELightOn:
{
//ELightOn do something...
break;
}
case CHWRMLight::ELightOff:
{
//ELightOff do something...
break;
}
case CHWRMLight::ELightBlink:
{
//ELightBlink do something...
break;
}
case CHWRMLight::ELightStatusUnknown:
{
//ELightStatusUnknown do something...
break;
}
default:
{
//Lights status undefined do something...
break;
}
}
 
}

[edit] Using CLightController class

  • In the header file:
class CLightController;
 
class CTestingAppUi : public CAknAppUi
{
//...
private:
//...
CLightController* iLightController;
};
  • In the source file:
#include "LightController.h"
#include <HWRMLight.h>
 
void CTestingAppUi::ConstructL()
{
iLightController = CLightController::NewL();
}
 
CTestingAppUi::~CTestingAppUi()
{
delete iLightController;
}
 
void CTestingAppUi::ControlLightsL()
{
CHWRMLight::TLightTarget target = CHWRMLight::EPrimaryDisplayAndKeyboard;
 
// == RESERVE ==
/*
1. target - the light device that should be controlled (display, keyboard,
hardware-specific custom target)
2. param - restore: if ETrue is selected, the light state on last release
will be restored
upon successful reservation.
3. param - NoCCoeEnv: if EFalse is selected, the light target will be automatically
released when the
application goes to background and reserved when the application is restored
to foreground.
*/

 
//show dialogs to ask values
iLightController->LightsReserveL();
//...or set values without dialogs
iLightController->LightsReserveL(target, EFalse, EFalse);
 
// == LIGHTS ON ==
/*
1. param - target: the light device that should be controlled (display,
keyboard, hardware specific custom target)
2. param - duration: time in milliseconds light target will be active
3. param - intensity: percentage of full light intensity
4. param - fade: if ETrue is selected, the light target will be
turned on/off gradually (fade-in/fade-out)
*/

 
//show dialogs to ask values
iLightController->LightsOnL();
//...or set values without dialogs
iLightController->LightsOnL(target, 2000, 50, EFalse);
 
// == LIGHTS BLINK ==
/*
1. param - target: the light device that should be controlled (display,
keyboard, hardware-specific custom target)
2-4. - params durations: times in milliseconds that the light target will be active
5. param - intensity: percentage of full light intensity
*/

 
//show dialogs to ask values
iLightController->LightsBlinkL();
//...or set values without dialogs
iLightController->LightsBlinkL(target, 2000, 1000, 1000, 50);
 
// == LIGHTS OFF ==
/*
1. param - target: the light device that should be controlled (display, keyboard,
hardware-specific custom target)
2. param - duration: time in milliseconds that the light target will be active
3. param - fade: if ETrue is selected, the light target will be turned
on/off gradually (fade-in/fade-out)
*/

//show dialogs to ask values
iLightController->LightsOffL();
//...or set values without dialogs
iLightController->LightsOffL(target, 2000, EFalse);
 
// == RELEASE ==
//show dialogs to ask target
iLightController->LightsReleaseL();
//...or set target without a dialog
iLightController->LightsReleaseL(target);
 
// == GET STATUSES
//show dialog to ask target
CHWRMLight::TLightStatus status(CHWRMLight::ELightStatusUnknown);
 
status = iLightController->LightsStatusL();
//...or set target without a dialog
status = iLightController->LightsStatusL(target);
}

[edit] Postconditions

The CLightController class controls light settings and receives information on light target status changes.


This page was last modified on 19 June 2012, at 04:51.
93 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×