Difference between revisions of "Patch Camera Using Volume Buttons to Take a Picture"

From WebOS Internals
Jump to navigation Jump to search
(→‎Procedure: fixed malformed patch)
 
(One intermediate revision by the same user not shown)
Line 23: Line 23:
  
 
<pre><nowiki>
 
<pre><nowiki>
--- capture-assistant.js_2009-06-28 Sun Jun 28 20:55:45 2009
+
--- a/usr/palm/applications/com.palm.app.camera/app/controllers/capture-assistant.js
+++ capture-assistant.js Sun Jun 28 20:58:54 2009
+
+++ b/usr/palm/applications/com.palm.app.camera/app/controllers/capture-assistant.js
@@ -34,6 +34,8 @@
+
@@ -134,6 +134,7 @@
  this.defaultFilename = null;
+
this._handleCaptureToggle();
 +
  }.bind(this));
 
  }
 
  }
 +
+ this.volumeKeySubscription = null;
 
 
 
 
+ this.volumeKeySubscription = undefined;
+
+
+
},
+
@@ -136,7 +137,6 @@
 +
}
 +
 +
 +
-
 +
this.onKeyPressHandler = this.onKeyPress.bindAsEventListener(this);
 +
Mojo.listen(this.controller.sceneElement, Mojo.Event.keydown, this.onKeyPressHandler);
 +
Mojo.listen(this.controller.sceneElement, Mojo.Event.keyup, this.onKeyPressHandler);
 +
@@ -164,7 +164,16 @@
 +
AppAssistant.photoRollVideoLoader = AppAssistant.libraries["metascene.videos"];
 
   
 
   
 
@@ -86,6 +88,16 @@
 
elemC.style.display = '';
 
 
  }
 
  }
+
-
 
+ // listen to volume key events
 
+ // listen to volume key events
 
+ this.volumeKeySubscription = new Mojo.Service.Request(
 
+ this.volumeKeySubscription = new Mojo.Service.Request(
Line 47: Line 55:
 
+ onSuccess: this.handleVolumeKeys.bind(this),  
 
+ onSuccess: this.handleVolumeKeys.bind(this),  
 
+ });
 
+ });
+
+
+
 
  llog("CaptureAssistant::setup() finished");
 
  llog("CaptureAssistant::setup() finished");
  },
+
  }catch(e){llog("setup threw: "+Object.toJSON(e));}},
 
 
 
 
@@ -174,6 +186,11 @@
+
@@ -332,6 +341,11 @@
 
  }
 
  }
 
 
 
 
Line 59: Line 67:
 
+ if(this.volumeKeySubscription) {
 
+ if(this.volumeKeySubscription) {
 
+ this.volumeKeySubscription.cancel();
 
+ this.volumeKeySubscription.cancel();
+ }
+
+ }
 
  },
 
  },
 
 
 
 
 
  handleCommand: function(event){
 
  handleCommand: function(event){
@@ -191,6 +208,14 @@
+
@@ -382,6 +396,14 @@
onKeyPress: function(event) {
+
this.cameraControl.stillCapture();
// Space bar also takes a picture.
+
}
if (Mojo.Char.spaceBar == event.originalEvent.keyCode){
+
},
+ this.cameraControl.capture();
 
+ }
 
+ },
 
 
+
 
+
 
+ // capture on release of volume keys
 
+ // capture on release of volume keys
Line 75: Line 80:
 
+ // capture when either volume up or down buttons are released
 
+ // capture when either volume up or down buttons are released
 
+ if(payload.state === 'up' && (payload.key === 'volume_up' || payload.key === 'volume_down')) {
 
+ if(payload.state === 'up' && (payload.key === 'volume_up' || payload.key === 'volume_down')) {
this.cameraControl.capture();
+
+ this.cameraControl.stillCapture();
}
+
+ }
},
+
+ },
 +
 
 +
 +
/**
 
</nowiki></pre>
 
</nowiki></pre>
  

Latest revision as of 01:14, 7 April 2010


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.

--- a/usr/palm/applications/com.palm.app.camera/app/controllers/capture-assistant.js
+++ b/usr/palm/applications/com.palm.app.camera/app/controllers/capture-assistant.js
@@ -134,6 +134,7 @@
 				this._handleCaptureToggle();
 			}.bind(this));
 		}
+		this.volumeKeySubscription = null;
 		
 		
 		
@@ -136,7 +137,6 @@
 		}
 		
 		
-		
 		this.onKeyPressHandler = this.onKeyPress.bindAsEventListener(this);
 		Mojo.listen(this.controller.sceneElement, Mojo.Event.keydown, this.onKeyPressHandler);
 		Mojo.listen(this.controller.sceneElement, Mojo.Event.keyup, this.onKeyPressHandler);
@@ -164,7 +164,16 @@
 			AppAssistant.photoRollVideoLoader = AppAssistant.libraries["metascene.videos"];
 
 		}
-		
+		// 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");
 	}catch(e){llog("setup threw: "+Object.toJSON(e));}},
 	
@@ -332,6 +341,11 @@
 		}
 		
 		this.cameraControl.closeCamera();
+		
+		// clean up listener for volume keys
+		if(this.volumeKeySubscription) {
+			this.volumeKeySubscription.cancel();
+		}		
 	},
 	
 	handleCommand: function(event){
@@ -382,6 +396,14 @@
 			this.cameraControl.stillCapture();
 		}
 	},
+	
+	// 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.stillCapture();
+ 		}
+	},
   
 	
 	/**

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