×
Namespaces

Variants
Actions
(Difference between revisions)

Blinking flashing increasing brightness of backlight in WRT

From Nokia Developer Wiki
Jump to: navigation, search
kiran10182 (Talk | contribs)
m
hamishwillee (Talk | contribs)
m (Hamishwillee - Add Abstract. Tidy wiki text)
 
(17 intermediate revisions by 6 users not shown)
Line 1: Line 1:
__NOTOC__
+
[[Category:Symbian Web Runtime]][[Category:Code Examples]][[Category:Hardware]][[Category:S60 3rd Edition FP1]][[Category:S60 3rd Edition FP2]][[Category:S60 5th Edition]][[Category:Base/System]]
__NOEDITSECTION__
+
{{ArticleMetaData <!-- v1.2 -->
{{CodeSnippet
+
|sourcecode= [[Media:Blinking flashing increasing brightness of backlight in WRT.zip]]
|id=&nbsp;
+
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
|platform=S60 3rd Edition, FP2, S60 5th Edition
+
|devices= Nokia E90 Communicator (v.210.34.75 and later), Nokia 5800 XpressMusic
|devices=Nokia E90, Nokia 5800 XpressMusic
+
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
|category=Web Runtime (WRT)
+
|platform= S60 3rd Edition, FP2, S60 5th Edition
|subcategory=Hardware
+
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
|creationdate=November 24, 2008
+
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
|keywords=x-systeminfo-widget, SystemInfo.lightblink(), SystemInfo.lighton()
+
|signing= <!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
 +
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 +
|keywords= x-systeminfo-widget, SystemInfo.lightblink(), SystemInfo.lighton()
 +
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|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= 20081210
 +
|author= [[User:Dekuykin]]
 +
<!-- The following are not in current metadata -->
 +
|id= CS001248;
 
}}
 
}}
 
  
 
==Overview==
 
==Overview==
WRT snippet <tt>Flashing Backlight</tt> allows user to make flash using backlight of display,
 
set high level of brightness for a long time and do display blinking.
 
  
It uses <tt>JavaScript WRT SystemInfo Service API</tt>.
+
{{Abstract|This code snippet demonstrates how to control the backlight of a device on Symbian Web Runtime, using the SystemInfo Service API WRT version 1.0. }}
Code snippet uses <tt>SystemInfo.lighton(lighttarget, duration, intensity, fadein)</tt> function to make display brightness very high and to set it to default value then.
+
In text above:
+
<tt>lighttarget</tt> - Integer value defining which target light should be turned on;
+
<tt>duration</tt> - Integer value defining the period during which the target light is switched on;
+
<tt>intensity</tt> - Integer value defining the intensity (brightness) of the light;
+
<tt>fadein</tt> - Boolean value which defines how target light will turn on/turn off
+
(<tt>true</tt>, target lights will not turn on instantly but fade-in smoothly instead; if <tt>false</tt>, target lights will be turned on without the fading effect.)
+
  
To make a blinking snippet uses <tt>SystemInfo.lightblink(lighttarget, duration, onduration, offduration, intensity)</tt> function.
+
The API is supported from S60 3rd Edition, Feature Pack 2 onwards. It is also supported in select S60 3rd Edition, Feature Pack 1 devices or their newest firmware versions (for example, Nokia E90 Communicator, from v.210.34.75 onwards).  
In text above:
+
<tt>lighttarget</tt> - String Defining which target light should be blinking;
+
<tt>duration</tt> - Integer value defining the period during which the target light is set to blink (the period is measured in milliseconds);
+
<tt>onduration</tt> - Integer value defining the period in milliseconds during which the target light is switched on in every blinking cycle;
+
<tt>offduration</tt> - Integer value defining the period in milliseconds during which the target light is switched off in every blinking cycle;
+
<tt>intensity</tt> - Integer value Defining the intensity (brightness) of the target light when it is switched on.
+
  
To get access to System Info API embedded object <tt>application/x-systeminfo-widget</tt> is used.
+
==Source==
  
==Source file: FlashingBackLight.html==
+
Embed the SystemInfo widget into the document:
  
 
<code xml>
 
<code xml>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
+
<body>
    "http://www.w3.org/TR/html4/strict.dtd">
+
    <embed type="application/x-systeminfo-widget" hidden="yes" />
 +
</body>
 +
</code>
  
<html>
+
Add three buttons to control the backlight:
  <head>
+
    <title>
+
    Backlight Flashing
+
    </title>
+
    <script type="text/javascript" src="backlight.js">
+
    </script>
+
  
    <link href="flashingBacklight.css" rel="stylesheet" type="text/css">
+
<code xml>
 
+
<input type="button" onclick="lightOn();" value="Light on" />
  </head>
+
<input type="button" onclick="blink();" value="Blink" />
 
+
<input type="button" onclick="lightOff();" value="Light off" />
  <body id="bodyId" class="bodyClass" onLoad="setup();">
+
   
+
  <embed type="application/x-systeminfo-widget" hidden="yes"></embed>
+
 
+
    <div class="caption">
+
    Flashing Backlight
+
    </div>
+
 
+
<div id="mainDiv" class="mainDiv">
+
 
+
  <p>
+
  <input id="lightButton" type="button" value="LIGHT" onClick="lightOn();">
+
  </p>
+
  <p> <input type="button" value="BLINK" onClick="blinkOn();"> </p>
+
  <p> <input type="button" value="FLASH" onClick="flash();"> </p>
+
  <p>
+
  <input type="button" value="OFF" class="offButton" onClick="off();" >
+
  </p>
+
 
+
</div>
+
 
+
  </body>
+
 
+
</html>
+
 
</code>
 
</code>
  
==Source file: flashingBacklight.css==
+
The JavaScript code:
  
<code css>
+
<code javascript>
.bodyClass {
+
var sysInfo = null;
    width: 100%;
+
    height: 100%;
+
    background-color: white;
+
    text-align: center;
+
    vertical-align: middle;
+
}
+
  
.caption {
+
window.onload = init;
    font-size: 150%;
+
    font-weight: bold;
+
    color: black;
+
    text-align: center;
+
}
+
  
.offButton {
+
var SMOOTH = true;
    background-color: red;
+
    color: black;
+
    font-weight: bold;
+
}
+
  
.mainDiv {
+
function init() {
text-align: center;
+
    // Obtain the SystemInfo object
vertical-align: middle;
+
    try {
width: 100%;
+
        sysInfo = document.embeds[0];
height: 100%;
+
    } catch (ex) {
 +
        alert("SystemInfo object cannot be found.");
 +
        return;
 +
    }
 
}
 
}
</code>
 
  
==Source file: backlight.js==
+
// Switches the display light on
 
+
<code javascript>
+
// Global variable for capturing of System Info object reference
+
var sysinfo;
+
// Menu command ids
+
var lightItemId = 2001;
+
var blinkItemId = 2002;
+
var flashItemId = 2003;
+
var offItemId = 2004;
+
var exitItemId = 2005;
+
 
+
/**
+
* Function switches display light on for infinitive time.
+
*/
+
 
function lightOn() {
 
function lightOn() {
     // First we should reset backlight state to default
+
    if (sysInfo == undefined) {
     off();
+
        alert("SystemInfo object is undefined.");
    sysinfo.lighton(sysinfo.lighttargetsystem,
+
        return;
        sysinfo.lightinfiniteduration, sysinfo.lightmaxintensity, true);
+
    }
}
+
   
 +
     // Reset the backlight state to default
 +
     resetLight();
  
/**
+
     sysInfo.lighton(sysInfo.lighttargetsystem, sysInfo.lightinfiniteduration,
* Function switches on display blinking for infinitive time.
+
         sysInfo.lightmaxintensity, SMOOTH);
*/
+
function blinkOn() {
+
    // First we should reset backlight state to default
+
    off();
+
     sysinfo.lightblink(sysinfo.lighttargetsystem,  
+
        sysinfo.lightinfiniteduration,  
+
         sysinfo.lightdefaultcycletime,  
+
        sysinfo.lightdefaultcycletime, sysinfo.lightmaxintensity);
+
 
}
 
}
  
/**
+
// Starts blinking the display
* Function switches light on for short time ( makes flash effect ). 
+
function blink() {
*/
+
     if (sysInfo == undefined) {
function flash() {
+
         alert("SystemInfo object is undefined.");
    // First we should reset backlight state to default
+
         return;
    off();
+
    // Duration of flash in milliseconds
+
    var flashDuration = 200;
+
   
+
     if (flashDuration >= sysinfo.lightmaxduration) {
+
         // If our flash duration is less then minimum available
+
         // set this to minimum available duration
+
        flashDuration = sysinfo.lightmaxduration;
+
 
     }
 
     }
 
      
 
      
     sysinfo.lighton(sysinfo.lighttargetsystem, flashDuration,
+
     // Reset the backlight state to default
        sysinfo.lightmaxintensity, false);
+
    resetLight();
}
+
  
/**
+
     sysInfo.lightblink(sysInfo.lighttargetsystem,
* Function sets lightening intensity of the display to default value.
+
         sysInfo.lightinfiniteduration, sysInfo.lightdefaultcycletime,
*/
+
        sysInfo.lightdefaultcycletime, sysInfo.lightmaxintensity);
function off() {
+
     sysinfo.lighton(sysinfo.lighttargetsystem,  
+
         sysinfo.lightinfiniteduration, sysinfo.lightdefaultintensity, true);
+
 
}
 
}
  
/**
+
// Switches the display light off
* Function creates and initializes menu and right softkey. 
+
function lightOff() {
*/
+
     if (sysInfo == undefined) {
function setup() {
+
         alert("SystemInfo object is undefined.");
     try {
+
         return;
         // Get access to SystemInfo API
+
        sysinfo = document.embeds[0];  
+
    } catch (e) {
+
         alert('Setup error: ' + e);
+
 
     }
 
     }
 
+
      
     // Create a right soft key
+
     sysInfo.lightoff(sysInfo.lighttargetsystem, sysInfo.lightinfiniteduration,
     try {
+
         SMOOTH);
        if (menu != undefined) {
+
            menu.clear();
+
            menu.showSoftkeys();
+
    // Create menu items
+
     
+
            var lightItem = new MenuItem('Light', lightItemId);
+
            var blinkItem = new MenuItem('Blink', blinkItemId);
+
            var flashItem = new MenuItem('Flash', flashItemId);
+
            var offItem = new MenuItem('Off', offItemId);
+
            var exitItem = new MenuItem('Exit', exitItemId);
+
     
+
            lightItem.onSelect = menuEventHandler;     
+
            blinkItem.onSelect = menuEventHandler;
+
            flashItem.onSelect = menuEventHandler;     
+
            offItem.onSelect = menuEventHandler;
+
            exitItem.onSelect = menuEventHandler;
+
     
+
            menu.append(lightItem);
+
            menu.append(blinkItem);
+
            menu.append(flashItem);
+
            menu.append(offItem);
+
            menu.append(exitItem);
+
     
+
         } else {
+
            alert("Menu not found!");
+
        }
+
    } catch (e) {
+
        alert("Menu Initialization error!");
+
    }
+
 
+
    setFocus();
+
 
}
 
}
  
/**
+
// Sets the backlight of the display to default value
* Function handles menu events.
+
function resetLight() {
* @param id - menu item identifier.
+
     if (sysInfo == undefined) {
*/
+
         alert("SystemInfo object is undefined.");
function menuEventHandler (id) {
+
         return;
     switch (id) {
+
    case lightItemId:
+
         lightOn();
+
         break;
+
    case blinkItemId:
+
        blinkOn();
+
        break;
+
    case flashItemId:
+
        flash();
+
        break;
+
    case offItemId:
+
        off();
+
        break;
+
    case exitItemId:
+
        exitFunc();
+
        break;
+
    default:
+
        break;
+
 
     }
 
     }
}
+
   
 
+
    sysInfo.lighton(sysInfo.lighttargetsystem, sysInfo.lightinfiniteduration,
/**
+
        sysInfo.lightdefaultintensity, SMOOTH);
* Function sets lightning to default value and exit program.
+
*/
+
function exitFunc() {
+
  off();
+
  window.close();
+
}
+
 
+
/**
+
* Function gives focus to document.
+
*/
+
function setFocus() {
+
    document.getElementById('lightButton').focus();
+
 
}
 
}
 
</code>
 
</code>
  
 
==Postconditions==
 
==Postconditions==
* After starting the snippet four buttons are visible:
 
  <tt>"Light"</tt> - increases display brightness;
 
  <tt>"Blink"</tt> - starts display blinking;
 
  <tt>"Flash"</tt> - make a short-time flash;
 
  <tt>"Off"</tt> - sets default display state.
 
 
* Commands in options menu have the same captions and do the same actions.
 
  
 +
Different possibilities to control the backlight are demonstrated.
  
 
==Supplementary material==
 
==Supplementary material==
You can see source file and executable application in attached zip archive. Archive is available for download at [[Media:Blinking_flashing_increasing_brightness_of_backlight_in_WRT.zip|Blinking_flashing_increasing_brightness_of_backlight_in_WRT.zip]]
 
  
[[Category:Web Runtime (WRT)]][[Category:Code Examples]]
+
For a complete example that makes use of the SystemInfo Service API to control the backlight, see [[Media:Blinking flashing increasing brightness of backlight in WRT.zip|Blinking flashing increasing brightness of backlight in WRT.zip]]

Latest revision as of 09:41, 5 October 2012

Article Metadata
Code ExampleTested with
Devices(s): Nokia E90 Communicator (v.210.34.75 and later), Nokia 5800 XpressMusic
Compatibility
Platform(s): S60 3rd Edition, FP2, S60 5th Edition
S60 5th Edition
S60 3rd Edition FP2
S60 3rd Edition FP1
Article
Keywords: x-systeminfo-widget, SystemInfo.lightblink(), SystemInfo.lighton()
Created: dekuykin (10 Dec 2008)
Last edited: hamishwillee (05 Oct 2012)

Contents

[edit] Overview

This code snippet demonstrates how to control the backlight of a device on Symbian Web Runtime, using the SystemInfo Service API WRT version 1.0.

The API is supported from S60 3rd Edition, Feature Pack 2 onwards. It is also supported in select S60 3rd Edition, Feature Pack 1 devices or their newest firmware versions (for example, Nokia E90 Communicator, from v.210.34.75 onwards).

[edit] Source

Embed the SystemInfo widget into the document:

<body>
<embed type="application/x-systeminfo-widget" hidden="yes" />
</body>

Add three buttons to control the backlight:

<input type="button" onclick="lightOn();" value="Light on" />
<input type="button" onclick="blink();" value="Blink" />
<input type="button" onclick="lightOff();" value="Light off" />

The JavaScript code:

var sysInfo = null;
 
window.onload = init;
 
var SMOOTH = true;
 
function init() {
// Obtain the SystemInfo object
try {
sysInfo = document.embeds[0];
} catch (ex) {
alert("SystemInfo object cannot be found.");
return;
}
}
 
// Switches the display light on
function lightOn() {
if (sysInfo == undefined) {
alert("SystemInfo object is undefined.");
return;
}
 
// Reset the backlight state to default
resetLight();
 
sysInfo.lighton(sysInfo.lighttargetsystem, sysInfo.lightinfiniteduration,
sysInfo.lightmaxintensity, SMOOTH);
}
 
// Starts blinking the display
function blink() {
if (sysInfo == undefined) {
alert("SystemInfo object is undefined.");
return;
}
 
// Reset the backlight state to default
resetLight();
 
sysInfo.lightblink(sysInfo.lighttargetsystem,
sysInfo.lightinfiniteduration, sysInfo.lightdefaultcycletime,
sysInfo.lightdefaultcycletime, sysInfo.lightmaxintensity);
}
 
// Switches the display light off
function lightOff() {
if (sysInfo == undefined) {
alert("SystemInfo object is undefined.");
return;
}
 
sysInfo.lightoff(sysInfo.lighttargetsystem, sysInfo.lightinfiniteduration,
SMOOTH);
}
 
// Sets the backlight of the display to default value
function resetLight() {
if (sysInfo == undefined) {
alert("SystemInfo object is undefined.");
return;
}
 
sysInfo.lighton(sysInfo.lighttargetsystem, sysInfo.lightinfiniteduration,
sysInfo.lightdefaultintensity, SMOOTH);
}

[edit] Postconditions

Different possibilities to control the backlight are demonstrated.

[edit] Supplementary material

For a complete example that makes use of the SystemInfo Service API to control the backlight, see Blinking flashing increasing brightness of backlight in WRT.zip

This page was last modified on 5 October 2012, at 09:41.
126 page views in the last 30 days.