Patch Camera Using Volume Buttons to Take a Picture

From WebOS Internals
Revision as of 00:12, 3 August 2009 by Hopspitfire (talk | contribs)
Jump to navigation Jump to search


Note: If you are only looking for a hardware-based button to take a picture, the space bar will do that for you already.

Preamble

You will need write permissions to the filesystem on your Pre to apply this patch.

To get write persmissions execute:

rootfs_open -w

To remount the filesystem as read-only:

mount -o remount,ro /

Procedure

The patch is performed on /usr/palm/applications/com.palm.app.camera/app/controllers/capture-assistant.js. Please back up this file before proceeding.

--- capture-assistant.js_2009-06-28	Sun Jun 28 20:55:45 2009
+++ capture-assistant.js	Sun Jun 28 20:58:54 2009
@@ -34,6 +34,8 @@
 			this.defaultFilename = null;
 		}
 		
+		this.volumeKeySubscription = undefined;
+		
 	},
 
 	
@@ -86,6 +88,16 @@
 			elemC.style.display = '';
 		}
 		
+		// listen to volume key events
+		this.volumeKeySubscription = new Mojo.Service.Request(
+			'palm://com.palm.keys/audio', 
+			{
+				method: 'status',
+				parameters: {'subscribe': true},
+				onFailure: function() { Mojo.Log.error("Could not subscribe to volume key events"); },
+				onSuccess: this.handleVolumeKeys.bind(this), 
+			});
+		
 		llog("CaptureAssistant::setup() finished");
 	},
 	
@@ -174,6 +186,11 @@
 		}
 		
 		this.cameraControl.closeCamera();
+		
+		// clean up listener for volume keys
+		if(this.volumeKeySubscription) {
+			this.volumeKeySubscription.cancel();
+		}
 	},
 	
 	handleCommand: function(event){
@@ -191,6 +208,14 @@
 	onKeyPress: function(event) {
 		// Space bar also takes a picture.
 		if (Mojo.Char.spaceBar == event.originalEvent.keyCode){
+			this.cameraControl.capture();
+		}
+	},
+	
+	// capture on release of volume keys
+	handleVolumeKeys: function(payload) {
+		// capture when either volume up or down buttons are released
+		if(payload.state === 'up' && (payload.key === 'volume_up' || payload.key === 'volume_down')) {
 			this.cameraControl.capture();
 		}
 	},

Notes

Volume Control

The keys will still alter the volume of the device. There is a way to lock the buttons so that they don't modify volume when pressed but still report events. Needs futher investigation.

~FXDemolisher