Namespaces
Variants
Actions
(Difference between revisions)

Blinking flashing increasing brightness of backlight in WRT

Jump to: navigation, search
(New page: __NOTOC__ __NOEDITSECTION__ {{CodeSnippet |id=  |platform=S60 3rd Edition, FP2, S60 5th Edition |devices=Nokia E90, Nokia 5800 XpressMusic |category=Web Runtime (WRT) |subcategory=Har...)
 
m
Line 261: Line 261:
  
 
==Postconditions==
 
==Postconditions==
After starting the snippet four buttons are visible:
+
* After starting the snippet four buttons are visible:
<tt>"Light"</tt> - increases display brightness;
+
  <tt>"Light"</tt> - increases display brightness;
<tt> "Blink"</tt> - starts display blinking;
+
  <tt>"Blink"</tt> - starts display blinking;
<tt>"Flash"</tt> - make a short-time flash;
+
  <tt>"Flash"</tt> - make a short-time flash;
<tt>"Off"</tt> - sets default display state.
+
  <tt>"Off"</tt> - sets default display state.
  
Commands in options menu have the same captions and do the same actions.
+
* Commands in options menu have the same captions and do the same actions.
==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]]
+
 
 +
==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]]
 
[[Category:Web Runtime (WRT)]][[Category:Code Examples]]

Revision as of 21:22, 10 December 2008


Article Metadata

Tested with
Devices(s): Nokia E90, Nokia 5800 XpressMusic

Compatibility
Platform(s): S60 3rd Edition, FP2, S60 5th Edition

Article
Keywords: x-systeminfo-widget, SystemInfo.lightblink(), SystemInfo.lighton()
Created: (24 Nov 2008)
Last edited: kiran10182 (10 Dec 2008)


Overview

WRT snippet Flashing Backlight allows user to make flash using backlight of display, set high level of brightness for a long time and do display blinking.

It uses JavaScript WRT SystemInfo Service API. Code snippet uses SystemInfo.lighton(lighttarget, duration, intensity, fadein) function to make display brightness very high and to set it to default value then. In text above: lighttarget - Integer value defining which target light should be turned on; duration - Integer value defining the period during which the target light is switched on; intensity - Integer value defining the intensity (brightness) of the light; fadein - Boolean value which defines how target light will turn on/turn off (true, target lights will not turn on instantly but fade-in smoothly instead; if false, target lights will be turned on without the fading effect.)

To make a blinking snippet uses SystemInfo.lightblink(lighttarget, duration, onduration, offduration, intensity) function. In text above: lighttarget - String Defining which target light should be blinking; duration - Integer value defining the period during which the target light is set to blink (the period is measured in milliseconds); onduration - Integer value defining the period in milliseconds during which the target light is switched on in every blinking cycle; offduration - Integer value defining the period in milliseconds during which the target light is switched off in every blinking cycle; intensity - Integer value Defining the intensity (brightness) of the target light when it is switched on.

To get access to System Info API embedded object application/x-systeminfo-widget is used.

Source file: FlashingBackLight.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
 
<html>
<head>
<title>
Backlight Flashing
</title>
<script type="text/javascript" src="backlight.js">
</script>
 
<link href="flashingBacklight.css" rel="stylesheet" type="text/css">
 
</head>
 
<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>

Source file: flashingBacklight.css

.bodyClass {
width: 100%;
height: 100%;
background-color: white;
text-align: center;
vertical-align: middle;
}
 
.caption {
font-size: 150%;
font-weight: bold;
color: black;
text-align: center;
}
 
.offButton {
background-color: red;
color: black;
font-weight: bold;
}
 
.mainDiv {
text-align: center;
vertical-align: middle;
width: 100%;
height: 100%;
}

Source file: backlight.js

// 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() {
// First we should reset backlight state to default
off();
sysinfo.lighton(sysinfo.lighttargetsystem,
sysinfo.lightinfiniteduration, sysinfo.lightmaxintensity, true);
}
 
/**
* Function switches on display blinking for infinitive time.
*/

function blinkOn() {
// First we should reset backlight state to default
off();
sysinfo.lightblink(sysinfo.lighttargetsystem,
sysinfo.lightinfiniteduration,
sysinfo.lightdefaultcycletime,
sysinfo.lightdefaultcycletime, sysinfo.lightmaxintensity);
}
 
/**
* Function switches light on for short time ( makes flash effect ).
*/

function flash() {
// First we should reset backlight state to default
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,
sysinfo.lightmaxintensity, false);
}
 
/**
* Function sets lightening intensity of the display to default value.
*/

function off() {
sysinfo.lighton(sysinfo.lighttargetsystem,
sysinfo.lightinfiniteduration, sysinfo.lightdefaultintensity, true);
}
 
/**
* Function creates and initializes menu and right softkey.
*/

function setup() {
try {
// Get access to SystemInfo API
sysinfo = document.embeds[0];
} catch (e) {
alert('Setup error: ' + e);
}
 
// Create a right soft key
try {
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();
}
 
/**
* Function handles menu events.
* @param id - menu item identifier.
*/

function menuEventHandler (id) {
switch (id) {
case lightItemId:
lightOn();
break;
case blinkItemId:
blinkOn();
break;
case flashItemId:
flash();
break;
case offItemId:
off();
break;
case exitItemId:
exitFunc();
break;
default:
break;
}
}
 
/**
* 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();
}

Postconditions

  • After starting the snippet four buttons are visible:
 "Light" - increases display brightness;
 "Blink" - starts display blinking;
 "Flash" - make a short-time flash;
 "Off" - sets default display state.
  • Commands in options menu have the same captions and do the same actions.


Supplementary material

You can see source file and executable application in attached zip archive. Archive is available for download at Blinking_flashing_increasing_brightness_of_backlight_in_WRT.zip

179 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved