maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Applications (https://talk.maemo.org/forumdisplay.php?f=41)
-   -   Blink Notification led on Battery Low (https://talk.maemo.org/showthread.php?t=46363)

cehteh 2010-03-03 09:29

Blink Notification led on Battery Low
 
Since i disabled system sounds, I often miss when the battery goes low. Unfortunately Nokia missed the opportunity to signal this with the notification LED. So here is a small hack, I may turn this into a proper daemon written in C someday, but thinking about it there is no much need for it. Note that it gets extremely rare waken up (only when battery gets low or you plug in the charger) so, by itself it needs very minimal resources, blinking the LED does not consume much power either just in case you thik about that.

I posting this here, maybe someone has use for it or may even package it (or implement it in C). There is currently one small problem that it leaves a stale process around when one stops it (busybox problem?) But since it should be started at startup and never be stopped this doesn't hurt much. Anyways If anyone fixes this, please notify me.

You need to hack some upstart and/or init.d scripts to start it on boot, I don't post these here and leave that as exercise to the reader. I've also defined my own 'PatternBatteryLow' in /etc/mce/mce.ini, if you are too lazy to define your own, you may just use the error pattern which blinks red at very high priority.


Code:

#!/bin/sh

# copy this to /usr/sbin/batlow.sh
# start it with:
# start-stop-daemon -b -p /var/run/batlow.pid -a /usr/sbin/batlow.sh -S

# Default error pattern is always present bit may be inapprobiate
#BATTERYLOW_PATTERN=PatternError

# When you defined your own pattern:
BATTERYLOW_PATTERN=PatternBatteryLow

dbus-monitor --system \
        "type='signal',member='charger_connected'" \
        "type='signal',member='battery_low'" | \
while read signal; do
        case "$signal" in
        *charger_connected*)
                echo "charger connected"
                dbus-send --system --dest="com.nokia.mce" --type=method_call \
                        "/com/nokia/mce/request" "com.nokia.mce.request.req_led_pattern_deactivate" \
                        "string:$BATTERYLOW_PATTERN"
                ;;
        *battery_low*)
                echo "battery low"
                dbus-send --system --dest="com.nokia.mce" --type=method_call \
                        "/com/nokia/mce/request" "com.nokia.mce.request.req_led_pattern_activate" \
                        "string:$BATTERYLOW_PATTERN"
                ;;
        esac
done


ossipena 2010-03-03 09:36

Re: Blink Notification led on Battery Low
 
http://wiki.maemo.org/Template:Danger

maemo.it 2011-01-15 02:25

Re: Blink Notification led on Battery Low
 
thank you cehteh for your script. I'll use it, really useful. but more important for me is to understand. please, can you explain your script? what means each code line?
eg:
1.what means com.nokia.mce, is it a web address?
2.why you didn't use a simpler one-line command like PatternbatteryLow=(code) in /etc/mce/mce.ini instead of script? we need both?
what I've to write in /init.d directory? a new file or I've to modify existing mce file?
please, don't forget to the newbies too and help them to understand.
thank you cehteh
:)

figaro 2011-02-10 10:20

Re: Blink Notification led on Battery Low
 
Quote:

Originally Posted by ossipena (Post 553586)

could you tell me what danger might be caused by this script? since I don't find anything dangerous other than IF YOU DECIDED TO deal with /etc/mce/mce.ini with your own LED pattern
otherwise this should be safe. or am I wrong?

Quote:

Originally Posted by maemo.it (Post 920632)
thank you cehteh for your script. I'll use it, really useful. but more important for me is to understand. please, can you explain your script? what means each code line?
eg:
1.what means com.nokia.mce, is it a web address?
2.why you didn't use a simpler one-line command like PatternbatteryLow=(code) in /etc/mce/mce.ini instead of script? we need both?
what I've to write in /init.d directory? a new file or I've to modify existing mce file?
please, don't forget to the newbies too and help them to understand.
thank you cehteh
:)

1) no. please go http://dbus.freedesktop.org/doc/dbus-tutorial.html or http://linux.die.net/man/1/dbus-monitor for details
2) you can make as many as LED pattern in mce.ini, but if nothing ever triggered it (such as "scripts"), then it'll do nothing

please correct me if I'm wrong

xxxxts 2011-02-10 12:37

Re: Blink Notification led on Battery Low
 
This is not working for me...

figaro 2011-02-10 13:29

Re: Blink Notification led on Battery Low
 
Quote:

Originally Posted by xxxxts (Post 940890)
This is not working for me...

above code is meant for those who've had PatternBatteryLow in their mce.ini
have you set PatternBatteryLow in yours?
if you haven't, and you don't wish to hassle with your mce.ini, change the code like below

Code:

# Default error pattern is always present bit may be inapprobiate
BATTERYLOW_PATTERN=PatternError

# When you defined your own pattern:
#BATTERYLOW_PATTERN=PatternBatteryLow


xxxxts 2011-02-10 14:21

Re: Blink Notification led on Battery Low
 
I inserted PatternBatteryLow in mce.ini, no luck - I also tried changing to PatternError but still no go...

figaro 2011-02-10 14:36

Re: Blink Notification led on Battery Low
 
try move the script to /home/user, and run it using X-Term and see if it works

it should not print anything unless triggered by battery low notification or changer being connected. if you see some lines while running the script, there might be an error while copying the code

please also make sure that "/com/nokia/mce/request" and "com.nokia.mce.request.req_led_pattern_activat e/deactivate" are in the same line (the code on my browser, it looked as if they're on different lines). or add trailing backslash after "/com/nokia/mce/request" (there are 2 of them, change both)

Code:

                dbus-send --system --dest="com.nokia.mce" --type=method_call \
                        "/com/nokia/mce/request" \
                        "com.nokia.mce.request.req_led_pattern_deactivate" \
                        "string:$BATTERYLOW_PATTERN"


pH5 2011-02-10 16:43

Re: Blink Notification led on Battery Low
 
Quote:

Originally Posted by cehteh (Post 553577)
I posting this here, maybe someone has use for it or may even package it (or implement it in C).

I've implemented the script in Vala and packaged it as Low Battery LED (lowbatled).
If there is no PatternBatteryLow in mce.ini, the package postinst will add it using mceledpattern and restart MCE.

hawaii 2011-02-10 17:02

Re: Blink Notification led on Battery Low
 
A lot of these small daemons can be translated into scripts that run on dbuscron, it would be a lot easier to manage and might reduce ticks.

Just an observation.


All times are GMT. The time now is 03:33.

vBulletin® Version 3.8.8