Notices


Reply
Thread Tools
blubbi's Avatar
Posts: 288 | Thanked: 113 times | Joined on Dec 2009 @ Germany
#1
Hi all,

I am in the process of coding a nice GUI to remotely control your DSLR-Camera.

With the N900 there are a range of sensors available which can be used to trigger the Camera.

Yet, there is no GUI, just a proof of concept for the ambient light sensor (aka proximity sensor) but I am planing to include what is possible (accelerators, microphone, GPS...)

So heres the proof of concept:

Since these pictures are just for the proof of concept. I did not take special care about correct focus and light settings. The files are JPG-Files out-of-cam.

The Setup:


Taken with the n900 as trigger. As soon as the match is lit, the n900 triggers the camera via IR:


Taken manually... seems as my reaction time outperforms my code


And here's the code (It is heavily based on shutter by Thomas Waelti. Install shutter to pull in all required dependencies).

"luxus" is another useful app to visualize the current ambient light intensity for setting the min/max threshold.

PLEASE, DON'T copy the example for file polling... its very bad style... I am gathering solutions for file polling in /sys with python here.

Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# The IR-Code is from the app "shutter" by Thomas Waelti
#

import os, time, subprocess, datetime

ambient_sensor = '/sys/class/i2c-adapter/i2c-2/2-0029/lux'

#Treshold for the ambient light
min_threshold = 7
#Max treshold to avoid a release via the flash (not neccessary with "break")
max_threshold = 100

#Camera to use
REMOTE = "CANON-RC1/RC5"
CODE = "S"

#REMOTE = "NikonDSLR"
#CODE = "shutter"

#REMOTE = "Olympus_RM-2"
#CODE = "CAPTURE"

#REMOTE = "Pentax_RC-F"
#CODE = "CAPTURE"

def start_lircd():
    #Check if Lircd runs
    lircdPID = subprocess.Popen(["pgrep", "lircd"], stdout=subprocess.PIPE).communicate()[0]
    if lircdPID == "":
	lircdPID = 0

    stopLircdOnEnd = True
    if lircdPID > 0:
	message = "LIRCD already started: PID %d\n" % int(lircdPID)
	print message
	stopLircdOnEnd = False
    else:
	#Start if it doesn't
	message = "LIRCD started for " + os.getenv("LOGNAME")
	print message
	arg = []
	if os.getenv("LOGNAME") == "root": #For remote debugging through SSH as root
	    arg = ["/etc/init.d/lirc", "start"]
	else:
	    arg = ["sudo", "/etc/init.d/lirc", "start"]
	lircdstart = subprocess.Popen(arg)
	lircdstart.wait()
    return stopLircdOnEnd

def stop_lircd(stopLircdOnEnd):
    if stopLircdOnEnd == True:
      #We launched it, so we need to stop it again
      if os.getenv("LOGNAME") == "root": #For remote debugging through SSH as root
	lircdstop = subprocess.Popen(["/etc/init.d/lirc", "stop"])
      else:
	lircdstop = subprocess.Popen(["sudo", "/etc/init.d/lirc", "stop"])
      lircdstop.wait()
      print "LIRCD stopped."

def on_toggle(remote, code):
    irsend = subprocess.Popen(('/usr/bin/irsend', 'send_once', remote, code),
			      stdin = subprocess.PIPE)
    irsend.stdin.close()
    irsend.wait()
    if irsend.returncode != 0:
	message = "IRsend failed: %s" % irsend.returncode
    else:
	message = "IRsend success: %s" % irsend.returncode
    print message

stopLircdOnEnd = start_lircd()

# TODO: BAD BAD _VERY_ BAD!!!
f = open(ambient_sensor, 'r')
print "Waiting for event..."
while True:
    value = int(f.read())
    if value >= min_threshold and value <= max_threshold:
	on_toggle(REMOTE, CODE)
	print "treshold (%s) exceeded: %s" %(min_threshold, value)
	break
    f.seek(0)

stop_lircd(stopLircdOnEnd)
So improvements are welcome.

Cheers
Bjoern

Last edited by blubbi; 2010-06-09 at 13:06.
 

The Following 2 Users Say Thank You to blubbi For This Useful Post:
Posts: 162 | Thanked: 52 times | Joined on Feb 2010
#2
Looks very interesting, installed Shutter since buying a new DSLR camera. Will follow this closely )
 
xxxxts's Avatar
Posts: 491 | Thanked: 341 times | Joined on Nov 2009 @ LA
#3
Gonna be following this
 
Reply


 
Forum Jump


All times are GMT. The time now is 04:52.