Active Topics

 


Reply
Thread Tools
Posts: 986 | Thanked: 1,526 times | Joined on Jul 2010
#1
Add actions to volume/power/proximitySensor from lockscreen, camera, and other apps.

N9 Button Monitor | mt-toggle for n9bm

Highlights:
  • Toggle flashlight/torch from lockscreen
  • Take pictures from lockscreen {quickSnap}
  • Focuses/snaps pix in camera, using VOL+ instead of touch-button
  • Music suite lockscreen controls
  • Take a screenshot {goes into MyDocs}

Features:
  • Run arbitrary commands or certain builtin actions
  • Per-screen actions {do different things in lockscreen, camera, FBReader, mplayer, etc.}
  • Buttons: proximitySensor, volumeUp, volumeDown, cameraBtn {n950}, powerBtn, bluetoothHeadsetButtons
  • Click patterns: single-click, double-click, treble-click, long-click-start, long-click-stop
  • Simple config file, plus an ugly gui for editing it if you really want.
  • Changes are automatically picked up without restart when you edit or use the gui.
  • Optional mt-toggle for turning on/off


Installation:
dpkg --force-depends -i n9-button-monitor_*.deb
#force-depends installs dependencies, like apt-get -f install


https://github.com/teleshoes/n9-button-monitor

config file is located at /home/user/.config/n9-button-monitor.conf
Default Config {this gets created if there is no file}

feel generous?
{or send money via paypal to elliot.wolk@gmail.com}

Last edited by wolke; 2013-08-20 at 03:06. Reason: sourceforge => openrepos
 

The Following 51 Users Say Thank You to wolke For This Useful Post:
Posts: 986 | Thanked: 1,526 times | Joined on Jul 2010
#2
you need to define your own getActions() function.

heres an example that does the camerra hack {vol+ to take pictures in camera app} and play/pauses music using mplayer
Code:
def getActions():
  return [
    Action(volup, cond=appOnTop("camera-ui"),
      action=cmd("xresponse -d 820x240,820x240 -w 1")),

    Action(volup, cond=screenLocked,
      action=cmd(
         "killall mplayer || " +
         "find ~/MyDocs/Music -iname *.mp3 -print0 | " +
         "xargs -0 mplayer"))
  ])
 

The Following 5 Users Say Thank You to wolke For This Useful Post:
Posts: 986 | Thanked: 1,526 times | Joined on Jul 2010
#3
v0.1
Code:
#!/usr/bin/python
#n9-button-monitor v0.1
#Copyright 2012 Elliot Wolk
#based on:
#####
# Ye Olde Camerra Hack - Another fine Harmattan Hack Powered by Python(tm)!
# 2012-01-12; Thomas Perl <thp.io/about>
#####
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#

from QmSystem import *
from PySide.QtGui import *
from PySide.QtDeclarative import *

import sys
import os
import subprocess
import re

###############
###############
###############
def getActions():
  return ([ None
  , Action(volup, cond=appOnTop("camera-ui"), action=cmd("camera-click"))
  , Action(volup, cond=screenLocked, action=cmd("klomp-cmd pause"))
  , Action(voldn, cond=screenLocked, action=cmd("klomp-cmd next"))
  ])

def readProc(cmdarr):
  out, err = subprocess.Popen(cmdarr, stdout=subprocess.PIPE).communicate()
  return out

def screenLocked():
  return "locked\n" == readProc(['lock', '-g'])
def screenUnlocked():
  return not screenLocked()

def appOnTop(app):
  return lambda: isAppOnTop(app)
def isAppOnTop(app):
  winId = readProc(["xprop", "-root", "_NET_ACTIVE_WINDOW"]) [40:]
  winCmd = readProc(["xprop", "-id", winId, "WM_COMMAND"]) [24:-4]
  return app in winCmd

def cmd(cmd):
  return lambda: runcmd(cmd)
def runcmd(cmd):
  print 'running cmd: "' + cmd + '"'
  subprocess.Popen(['bash', '-c', cmd])
###############
###############
###############

evtPressed = 'pressed'
evtRepeated = 'repeated'
evtReleased = 'released'

stateOn = 2
stateOff = 0

power = 20
volup = 2
voldn = 3

class Action():
  def __init__(self, key, event=evtPressed, action=None, cond=None, stop=True):
    self.key = key
    self.event = event
    self.action = action
    self.cond = cond
    self.stop = stop

keysPressed = set()
actions = getActions()

def keyEvent(key, state):
  event = None
  if state == stateOn:
    if key not in keysPressed:
      event = evtPressed
    else:
      event = evtRepeated
  elif state == stateOff:
    event = evtReleased

  if state == stateOn:
    keysPressed.add(key)
  elif state == stateOff:
    keysPressed.discard(key)

  for action in actions:
    if action != None and action.key == key and action.event == event:
      if action.cond == None or action.cond():
        action.action()
        if action.stop:
          return

def main():
  app = QApplication(sys.argv)
  keys = QmKeys()
  keys.keyEvent.connect(keyEvent)
  app.exec_()

if __name__ == "__main__":
  sys.exit(main())
 

The Following 6 Users Say Thank You to wolke For This Useful Post:
Posts: 986 | Thanked: 1,526 times | Joined on Jul 2010
#4
i put the above script in /usr/bin/n9-button-monitor, chmod +x.

i run it on startup with upstart.

/etc/init/n9-button-monitor.conf
Code:
# Description of the script, mandatory
description "Startup script for n9-button-monitor"

# Author e-mail address, mandatory
author "elliot.wolk@gmail.com"

start on filesystem or runlevel [2345]
stop on runlevel [!2345]

#none: stdout to /dev/null
#output: direct stdout to console
console output

#if application exits, restart max 3 times within 300 secs
respawn
#respawn limit 3 300

exec /usr/bin/aegis-exec -s -u user bash -c 'DISPLAY=:0 n9-button-monitor'

Last edited by wolke; 2012-02-24 at 18:52.
 

The Following 3 Users Say Thank You to wolke For This Useful Post:
Posts: 188 | Thanked: 90 times | Joined on Sep 2006
#5
Thanks for sharing, I have to think on how I can used this for my wife's N9.
__________________
If I said something useful, please hit the 'Thanks!' link related to that post.
 
F2thaK's Avatar
Posts: 4,365 | Thanked: 2,467 times | Joined on Jan 2010 @ Australia Mate
#6
Cool!

Any aims for this? GUI maybe?
 

The Following User Says Thank You to F2thaK For This Useful Post:
Posts: 986 | Thanked: 1,526 times | Joined on Jul 2010
#7
Originally Posted by F2thaK View Post
Cool!

Any aims for this? GUI maybe?
the next things i plan on doing are
1) investigating consuming button presses, overriding the default button actions like zooming/volume when an action is defined in the script. {or maybe just overriding it period in all cases, and simulating all the actually useful ones with actions in the script}

2) making the volume keep the phone's ringer volume and speaker volume in lockstep. so many times ive turned down the vol only to have loud music blast out of it. what id do is make it so that every time you press a volume button, ill get the ringer volume and set the phone volume to some variation on that.

3) separating out the action configuration from the script, so you dont need to be a python developer to use it. i imagine a simple rc file a la
~/.n9-button-monitor
[volume-up-press]
screen_lock = start_music
camera_on_top = snap_picture

[volume-up-release]
always = sync_volume

i would need to find out what people would even want to use this for, and add all of them to the rc-file grammar.

4) implement state for macro-ish controls
e.g.: make it so pressing and holding volume up, and then pressing volume down, and then releasing volume down and then releasing volume up, turned on the flashlight for 20 seconds

"UP DOWN down up" => "flashlight on; sleep 20; flashlight off"

{i think im going to rename the vol+/vol- keys INC and DEC to avoid confusion with button-up and button-down for keypresses.}
 

The Following 2 Users Say Thank You to wolke For This Useful Post:
Posts: 986 | Thanked: 1,526 times | Joined on Jul 2010
#8
Originally Posted by aRTee View Post
Thanks for sharing, I have to think on how I can used this for my wife's N9.
please please share when you do. im dying for things for this to actually do. so far:

1) play/pause/skip/prev music players on the lock-screen
2) flashlight on/off on the lock-screen
3) camera take picture {and maybe focus first}
4) camera take delayed picture
5) answer calls, instead of swiping up

1, 3, and 4 are easy and done. the camera doesnt focus first though, so what id REALLY like to do is make it so volUp-PRESS focuses, and volUp-RELEASE snaps. i dont think i have enough control to do this, though.

if anybody thinks of anything even remotely awesome, please post.
 
Posts: 986 | Thanked: 1,526 times | Joined on Jul 2010
#9
i got torch/flashlight toggling to work from the lowpowerscreen.
__________________
~ teleshoes ~
 

The Following User Says Thank You to wolke For This Useful Post:
Posts: 1,539 | Thanked: 1,604 times | Joined on Oct 2011 @ With my N9
#10
Originally Posted by wolke View Post
i got torch/flashlight toggling to work from the lowpowerscreen.
This is becoming pretty cool.
__________________
Arie|www.everythingn9.com|Nokia N9 64GB x2|Nokia N950

@everythingn9

Temporary Inception Fix


Times Banned from TMO: 4
 
Reply

Tags
harmattan, nokia n9


 
Forum Jump


All times are GMT. The time now is 14:22.