webOS Nation Forums > webOS apps and software > webOS development > Tweak: Turn on LED when text message is received
1 2 3 4 5 6  ... Last
Member: Keegan99
at: 07:38 PM 07/06/2009
One of the features I liked on my old Treo was the blinking green LED when I had a waiting text message. There's no such functionality out of the box for the Pre.

With this change, however, the center button LED will illuminate when you have a waiting text message!

As a prerequisite, you'll need the webosinternals services installed so you can run shell commands from within your application. If you already have this installed (for the my-tether application, for example) you can skip this step.

As root:

[CODE]cd /tmp/
mount -o remount,rw /

wget http://gitorious.org/webos-internals/applications/blobs/raw/db385edfa3f71ceb98401c16dd94b2490bfaaae5/org.webosinternals.services/org.webosinternals.services-0.4_all.ipk
ipkg install org.webosinternals.services-0.4_all.ipk
rm org.webosinternals.services-0.4_all.ipk
[/CODE]

Next we'll create the script to turn on the LED:

[CODE]
cd /usr/palm/applications/com.palm.app.messaging/app/
mkdir scripts
cd scripts
[/CODE]

In vi or your editor of choice, create the file led_on.sh in the scripts directory:

[CODE]
#!/bin/sh
sleep 9
echo 100 >/sys/class/leds/core_navi_center/brightness
[/CODE]

While still in the scripts directory, change the permissions on the file:

[CODE]
chmod 744 led_on.sh
[/CODE]

Now we need to tie our script into the messaging application:

[CODE]
cd /usr/palm/applications/com.palm.app.messaging/app/controllers
[/CODE]

Apply the following patch:

[CODE]
--- notification-assistant.js.bak Mon Jul 6 14:04:10 2009
+++ notification-assistant.js Mon Jul 6 18:48:17 2009
@@ -189,7 +189,15 @@
var dashboard = this.controller.getStageController(DashboardMessageStageName);

if (dashboard) {
+ var displayOn = this.Messaging.DisplayState.isDisplayOn();
dashboard.delegateToSceneAssistant("update");
+ if (!displayOn) {
+ this.controller.serviceRequest('palm://org.webosinternals.shell', {
+ method: 'runCmd',
+ parameters: {
+ cmd: '/usr/palm/applications/com.palm.app.messaging/app/scripts/led_on.sh'}
+ });
+ }
} else {
// Create a dashboard
var f = function(stageController){
@@ -214,9 +222,13 @@
this.isNewMessageDashboardPending = true;
createDashboard.delay(5);
}
-
} else {
createDashboard(); // if the screen is off, create the dashboard right away
+ this.controller.serviceRequest('palm://org.webosinternals.shell', {
+ method: 'runCmd',
+ parameters: {
+ cmd: '/usr/palm/applications/com.palm.app.messaging/app/scripts/led_on.sh'}
+ });
}
}
};
[/CODE]

Now lock up the filesystem and reboot:

[CODE]
mount -o remount,ro /
/sbin/reboot
[/CODE]

More testing and feedback would be appreciated. Only got this working this evening and there may be an unintended side effect or two, but hopefully not <knock on wood>.
Reply
Member: as4life
at: 08:33 PM 07/06/2009
i will definitely try this Thanks!
Reply
Member: lordelfkin
at: 08:40 PM 07/06/2009
ok... so how do i apply the patch? do i just mod the notification-assistant.js if so where does this code fit in? Thanks
Reply
Member: Keegan99
at: 08:46 PM 07/06/2009
You can either decode it by hand and edit the source file manually (It's basically inserting two small blocks of code into the original notification-assistant.js) or you can grab and use the patch utility:

[code]ipkg-opt install patch[/code]
Reply
Member: tozfeekum
at: 08:50 PM 07/06/2009
how do you use patch once you install it?
Reply
Member: Eguy
at: 09:04 PM 07/06/2009
This is great! Is there a way we can have it pulse twice for a new email, 3 times for a missed call, etc?
Reply
Member: lordelfkin
at: 09:51 PM 07/06/2009
when installing the patch i get

Originally Posted by :
patching file notification-assistant.js
patch: **** malformed patch at line 11: + method: 'runCmd',
?? not sure what i did, simply copied the patch code and created a file with it..
Reply
Member: Keegan99
at: 09:52 PM 07/06/2009
Pulsing would be a bit of a challenge, as it would require a continuously running script changing the value of the LED intensity. Without the ability to more cleanly kick off and terminate background processes (or a robust LED API) I don't see a way to do it.
Reply
Member: lordelfkin
at: 09:58 PM 07/06/2009
Originally Posted by tozfeekum:
how do you use patch once you install it?
"patch --help" will give you the syntax and how to use
Reply
Member: as4life
at: 10:01 PM 07/06/2009
how do u exactly install the patch? i tried going on the pre wiki page but its down.
Reply
Member: Keegan99
at: 10:42 PM 07/06/2009
Ok, the copy and paste may have marred the patch file, so here's the attachment.

To run the patch, copy it to /usr/palm/applications/com.palm.app.messaging/app/controllers, then:

[CODE]
cd /usr/palm/applications/com.palm.app.messaging/app/controllers
patch -p0 -i notification-assistant.js.patch.txt
[/CODE]
Attached: notification-assistant.js.patch.txt (1.1 KB) 
Reply
Member: atlanta
at: 10:46 PM 07/06/2009
Originally Posted by Eguy:
This is great! Is there a way we can have it pulse twice for a new email, 3 times for a missed call, etc?

You you can just have the script sleep then go to a different state then sleep again and go back to 100
Reply
Member: Keegan99
at: 10:54 PM 07/06/2009
Originally Posted by :
You you can just have the script sleep then go to a different state then sleep again and go back to 100
That's a one time pulse, but my reading of what Eguy wanted was more of a continual 'heartbeat', for lack of a better term. A morse code of sorts.
Reply
Member: Eguy
at: 10:59 PM 07/06/2009
Originally Posted by Keegan99:
That's a one time pulse, but my reading of what Eguy wanted was more of a continual 'heartbeat', for lack of a better term. A morse code of sorts.
Yes, so it keeps pulsing untill you clear the notification .


Just an FYI:


[code]root@castle:/usr/palm/applications/com.palm.app.messaging/app/controllers# patch
-p0 -i notification-assistant.js.patch.txt
patching file notification-assistant.js
Hunk #1 succeeded at 333 with fuzz 1 (offset 144 lines).
Hunk #2 FAILED at 366.
1 out of 2 hunks FAILED -- saving rejects to file notification-assistant.js.rej[/code]
Reply
Member: atlanta
at: 11:08 PM 07/06/2009
Opps put it in a while statement to create a pulse effect.
Reply
Member: Keegan99
at: 11:12 PM 07/06/2009
Originally Posted by atlanta:
Opps put it in a while statement to create a pulse effect.
The problem there is that there's no clean way to kill the process.
Reply
Member: Keegan99
at: 11:13 PM 07/06/2009
Originally Posted by :
root@castle:/usr/palm/applications/com.palm.app.messaging/app/controllers# patch
-p0 -i notification-assistant.js.patch.txt
patching file notification-assistant.js
Hunk #1 succeeded at 333 with fuzz 1 (offset 144 lines).
Hunk #2 FAILED at 366.
1 out of 2 hunks FAILED -- saving rejects to file notification-assistant.js.rej
Very strange. The lines being patched should be in the low 200's, not the mid to high 300's. Have you modified notification-assistant.js for something else previously?
Reply
Member: Eguy
at: 11:15 PM 07/06/2009
Nope, but just noticed it was wiped clean somehow and so was my backup, just copied a fresh js from the webos doctor and it worked.
Reply
Member: helfire
at: 11:29 PM 07/06/2009
Your first command should be mount -o remount,rw /

not
mount -o remount rw, /
Reply
Member: mdmogren
at: 11:32 PM 07/06/2009
Originally Posted by Keegan99:
You can either decode it by hand and edit the source file manually (It's basically inserting two small blocks of code into the original notification-assistant.js) or you can grab and use the patch utility:

[code]ipkg-opt install patch[/code]
Where is ipkg-opt located? I'm getting ipkg-opt not found?
Reply
1 2 3 4 5 6  ... Last
webOS Nation Forums > webOS apps and software > webOS development > Tweak: Turn on LED when text message is received