Using USB remote to control chdkptp with Raspberry Pi - page 5 - Hello, I'm a NEWBIE - HELP!! (Newbies assistance, User Guides and thank you notes) - CHDK Forum

Using USB remote to control chdkptp with Raspberry Pi

  • 68 Replies
  • 34064 Views
Re: Using USB remote to control chdkptp with Raspberry Pi
« Reply #40 on: 12 / April / 2017, 16:41:11 »
Advertisements
Hey y'all!

I'm making some progress with this project, and am messing with the USB remote currently (still in the process of making a Python code that generates chdkptp commands, but as soon as I do I will post it so everyone can take a look).

In the meantime, I have a specific question regarding downloading a video to an external source. While messing with the chdkptp GUI in the "User" tab, I can set an external destination to download files to. Now, when I hit "Download", the program downloads whatever is in my camera to the destination I set, right? What I am trying to figure out is how to do the same thing using the CLI. I see on the "CLI Quickstart" page that there is a command for downloading and downloading multiple files, but how exactly do I execute a command that takes everything on my camera and downloads it to a specified directory?

*

Offline reyalp

  • ******
  • 14118
Re: Using USB remote to control chdkptp with Raspberry Pi
« Reply #41 on: 12 / April / 2017, 16:57:21 »
I see on the "CLI Quickstart" page that there is a command for downloading and downloading multiple files, but how exactly do I execute a command that takes everything on my camera and downloads it to a specified directory?
If you want to download images, the imdl command is probably what you want. If you want other files too (like the CHDK directory, or SD card root) then use mdl.

Use help to see the options for either command. These commands both have a lot of options, but for simple case you don't need most of them.

"imdl" by itself downloads all image files from A/DCIM into a matching directory tree in the current directory. To download without the nnnCANON or date named sub-directories, use imdl -d=${name}. Note that if you have enough photos for the counter to wrap around, you might get name collisions with this command.

To download everything on the to /test, you could use

mdl A/ /test

Note the trailing / on the A/ is because the root directory in the canon OS is actually name "A/". For other directories, you would not use the trailing /, e.g. mdl CHDK/SCRIPTS my-script-backup

With either command, you can use -pretend to see what it would do.
Don't forget what the H stands for.

Re: Using USB remote to control chdkptp with Raspberry Pi
« Reply #42 on: 13 / April / 2017, 11:24:07 »
To download everything on the to /test, you could use

mdl A/ /test

Note the trailing / on the A/ is because the root directory in the canon OS is actually name "A/". For other directories, you would not use the trailing /, e.g. mdl CHDK/SCRIPTS my-script-backup

With either command, you can use -pretend to see what it would do.

Perfect, thank you for that

Another question that relates to what you said a little bit ago:

or write output that is piped into chdkptp, so for example you start your program like

remote_program | chdkptp.sh

and then when your program sees the zoom button, it outputs something like

=click('zoom_in')

So, my programming skills are mediocre at best, and I typically catch on quickly... but I'm not going to lie, I didn't know what "piping" was until yesterday. That's what I want to do, but I didn't realize it was the "|" command... so apologies for my ignorance haha. I am running into troubles with this, and hopefully you can clarify something for me. I figured out how to read a remote input from here: http://ericgoebelbecker.com/2015/06/raspberry-pi-and-gamepad-programming-part-1-reading-the-device/

and made a test Python program that looks like this:
Code: [Select]
#!/usr/bin/env python

#it said /usr/bin/ env python
import sys

from evdev import InputDevice, categorize, ecodes, KeyEvent
remote = InputDevice('/dev/input/event0')

for event in remote.read_loop():
    if event.type == ecodes.EV_KEY:
        keyevent = categorize(event)
        if keyevent.keystate == KeyEvent.key_down:
            if keyevent.keycode == 'KEY_B':
                #print "Zoom Out"
                sys.stdout.write('c')
            elif keyevent.keycode == 'KEY_F':
                print "Zoom In"
            elif keyevent.keycode == 'KEY_PLAYPAUSE':
                print "Start"
            elif keyevent.keycode == 'KEY_STOPCD':
                print "Stop"


For this test, I am just trying to set one button press to be a standard output (which I want to be chdkptp.sh) and if the "KEY_B" is pressed, to pipe that output to chdkptp. The rest can be just printed to the screen for now.

What I don't understand is how to set up the pipe. Do I do this from the command line? I have tried this and get an error that says the command is not found (the picture I attached). I have Googled this issue and can't find anything. I feel like this is a very simple thing to set up, but can't. Again, I know this particular question is programming related, and not chdk related, but reyalp, you have been quick with your responses.

Re: Using USB remote to control chdkptp with Raspberry Pi
« Reply #43 on: 13 / April / 2017, 12:11:21 »
What I don't understand is how to set up the pipe. Do I do this from the command line? I have tried this and get an error that says the command is not found (the picture I attached). I have Googled this issue and can't find anything. I feel like this is a very simple thing to set up, but can't. Again, I know this particular question is programming related, and not chdk related, but reyalp, you have been quick with your responses.
Try putting ./ in front of both file names in your command string.   That tells Linux to look in the current directory for the files.
Ported :   A1200    SD940   G10    Powershot N    G16


Re: Using USB remote to control chdkptp with Raspberry Pi
« Reply #44 on: 13 / April / 2017, 12:35:49 »
Quote from: waterwingz link=topic=13062.msg132286#msg132286
Try putting ./ in front of both file names in your command string.   That tells Linux to look in the current directory for the files.

That seemed to work! I get this:


But now if I use the remote to press a button, nothing happens. And if I type something as if I were using the chdkptp.sh, nothing happens there either. Do I need to have the python program running separately?.. Apologies for stupidity.

*

Offline reyalp

  • ******
  • 14118
Re: Using USB remote to control chdkptp with Raspberry Pi
« Reply #45 on: 13 / April / 2017, 14:09:51 »
But now if I use the remote to press a button, nothing happens. And if I type something as if I were using the chdkptp.sh, nothing happens there either. Do I need to have the python program running separately?.. Apologies for stupidity.
Seeing the prompt is normal, chdkptp is still writing to standard output.

What you have set up seems like it should work, so there is probably some detail missing.

You need to send a newline with each chdkptp command, e.g. sys.stdout.write('c\n')

If not that, maybe python does some output buffering?

The following shell script worked for me on a raspberry pi:

Code: [Select]
#!/bin/bash
echo ver
read foo
echo help $foo
sleep 2
echo quit
./foo.sh | chdkptp
prints the version, waits for input and prints the help for the entered text, and then quits.

Don't forget what the H stands for.

Re: Using USB remote to control chdkptp with Raspberry Pi
« Reply #46 on: 13 / April / 2017, 14:50:09 »
What you have set up seems like it should work, so there is probably some detail missing.

You need to send a newline with each chdkptp command, e.g. sys.stdout.write('c\n')

If not that, maybe python does some output buffering?

Okay so I ended up changing the piece of code so it sends a new line as well as the character 'c' to connect to the camera, but it still didn't work. I thought maybe it could have to do with the fact that Python sends both a standard output and a standard error, and voila... the prompt actually gets a character (and this is me commenting out the sys.stdout part of the code and replacing it only with std.err)

BUT... still, nothing is happening. The prompt displays that 'c' was sent, but the camera does not connect.

*

Offline reyalp

  • ******
  • 14118
Re: Using USB remote to control chdkptp with Raspberry Pi
« Reply #47 on: 13 / April / 2017, 16:07:22 »
I thought maybe it could have to do with the fact that Python sends both a standard output and a standard error, and voila... the prompt actually gets a character
This is a mistake. If things are working correctly, you will not see the input sent by your python script. You see it because standard error is *not* being piped.

Googling "python output buffering" suggests this may be your issue. For example, see
https://unix.stackexchange.com/questions/182537/write-python-stdout-to-file-immediately
http://stackoverflow.com/questions/107705/disable-output-buffering

There's a lot of different answers there, but I'd try just calling sys.stdout.flush() after each write.
Don't forget what the H stands for.


Re: Using USB remote to control chdkptp with Raspberry Pi
« Reply #48 on: 14 / April / 2017, 12:27:48 »
This is a mistake. If things are working correctly, you will not see the input sent by your python script. You see it because standard error is *not* being piped.

Googling "python output buffering" suggests this may be your issue. For example, see
https://unix.stackexchange.com/questions/182537/write-python-stdout-to-file-immediately
http://stackoverflow.com/questions/107705/disable-output-buffering

There's a lot of different answers there, but I'd try just calling sys.stdout.flush() after each write.

Ah, that makes sense that I don't want the error to display.

BUT. Buffering was the issue! Calling sys.stdout.flush() after the write does the job.

Re: Using USB remote to control chdkptp with Raspberry Pi
« Reply #49 on: 17 / April / 2017, 12:50:04 »
Another Pi question...

So I have everything running, and the Python program I wrote is allowing me to control the camera perfectly by sending both chdkptp and Lua commands to chdkptp.sh, but I am struggling to get this to work on startup. As of right now, to get my Python program to run and pipe its output to chdkptp.sh, I am simply typing this into the command prompt:

Code: [Select]
cd chdkptp-r735 && ./remote_function.py|./chdkptp.sh
I have tried adding the complete path pipe to /etc/rc.local file and nothing is working!

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal