×
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
tapla (Talk | contribs)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
 
__NOEDITSECTION__
 
__NOEDITSECTION__
 +
 
{{CodeSnippet
 
{{CodeSnippet
 
|id= 
 
|id= 
Line 6: Line 7:
 
|devices=Nokia E90, Nokia 5800 XpressMusic
 
|devices=Nokia E90, Nokia 5800 XpressMusic
 
|category=Web Runtime (WRT)
 
|category=Web Runtime (WRT)
|subcategory=Hardware
+
|subcategory=S60 Platform Services
 
|creationdate=November 24, 2008
 
|creationdate=November 24, 2008
 
|keywords=x-systeminfo-widget, SystemInfo.lightblink(), SystemInfo.lighton()
 
|keywords=x-systeminfo-widget, SystemInfo.lightblink(), SystemInfo.lighton()
 
}}
 
}}
 
  
 
==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>.
+
This code snippet demonstrates how to control the backlight of a device by using the SystemInfo Service API of the Web Runtime 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.
+
==Source==
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.
+
Embed the SystemInfo widget into the document:
 
+
==Source file: FlashingBackLight.html==
+
  
 
<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==
+
And here's 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==
+
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]]
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]]
 
[[Category:Web Runtime (WRT)]][[Category:Code Examples]]

Revision as of 17:29, 17 December 2008


Article Metadata
Tested with
Devices(s): Nokia E90, 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: (24 Nov 2008)
Last edited: tapla (17 Dec 2008)

Overview

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

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" />

And here's 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);
}

Postconditions

Different possibilities to control the backlight are demonstrated.

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

164 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.

×