-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A camera control script that automates running camera-ctl #100
base: master
Are you sure you want to change the base?
Conversation
Shell script with accompanying instruction readme that performs all tasks required to start camera-ctl in a Termainl session.
Thanks for sending in the patch! It seems like the shellcheck did not pass, do you mind revising so that it passes Shellcheck? |
Changes required to eliminate shellcheck errors
Thanks for letting me know about shellcheck. I installed it for the IDE I am using and I believe all the bad code is removed. The script was tested on my end. |
Thanks for all your work here. I can definitely see the benefit here. I am just wondering, if this repo is actually the best place for this script. First, this repo is mostly about building the image and not working with an installed showmewebcam instance (except swmc-expect). Secondly, it does seem highly custom to MacOS, does not work in Linux in its current state and is mostly useless for Windows. If the goal is to easily run camera-ctl, we could also set up PAM to autologin a user, or even to start camera-ctl automatically when logging in. In any case, the portname should stay the same at all times, and so you can easily work with your shell history or add an alias. In any case I would be very happy to link to your script, add further details on the wiki etc. @htruong would be happy to hear your opinion as well. |
picamctl/picamctl.sh
Outdated
# edit this next line to be the correct text pattern for your computer. | ||
portnamepat="tty.usbmodem" #typical for showmewebcam on Appl OS X | ||
#portnamepat="ttyACM" #probably typical for showmewebcam on Linux | ||
#portnamepat="tty." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should auto discover this, based on the platform you are on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I will work on that. I have a Raspberry Pi 4 I can use for testing the Linux side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Auto discover is now implemented.
picamctl/picamctl.sh
Outdated
clear | ||
# terminates all the ort screen sessions. | ||
screen -ls | grep Attached | cut -d. -f1 | awk '{print $1}' | xargs kill | ||
screen -ls | grep Detached | cut -d. -f1 | awk '{print $1}' | xargs kill |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why two times?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is my first shell script, so I have to dive deep to understand even the smallest aspects. Based on tests, what I had for what is supposed to handle both Attached and Detached in one line did not work. The single lines did. So I used those and moved on. There are many brute force parts of this script that I assume must have much better solutions.
picamctl/picamctl.sh
Outdated
#portnamepat="tty." | ||
# The client is an application you want this script to also run. | ||
runtheclient="true" | ||
clientname="Photo Booth" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MacOs specific, should be based on the platform, a parameter or optional
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is MacOS specific. The intent is for educator to make edits, which is one reason these are brought to the script top. The intended users (school setting as webcam attached to microscope camera attachment) would not know what a parameter is. I understand the point. Perhaps there is something that could be done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In combination with the auto discover implementation the script sets these per OS.
picamctl/picamctl.sh
Outdated
#portnamepat="ttyACM" #probably typical for showmewebcam on Linux | ||
#portnamepat="tty." | ||
# The client is an application you want this script to also run. | ||
runtheclient="true" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better as a parameter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the intended situation running the client is almost 100% wanted and in MacOS it would be difficult to have multiple instances. This variable is almost an ort from the early development process. An issue with parameters is that they result in what is viewed as unnecessary complication by the intended user.
picamctl/picamctl.sh
Outdated
@@ -0,0 +1,146 @@ | |||
#!/bin/bash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#!/bin/sh or #!/usr/bin/env bash are better for platform compatibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I will check this out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The script has been entirely refactored for sh.
picamctl/picamctl.sh
Outdated
if [ "$runtheclient" = "true" ]; then | ||
# -g causes application to open in background | ||
# https://scriptingosx.com/2017/02/the-macos-open-command/ | ||
open -g -a "$clientname" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Linux, this would probably be xdg-open
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Hopefully I'll get the platform checking to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In combination with auto discover the application Webcamoid is run for Linux situations. This has been tested on a Raspberry Pi 4 running a Raspbian system.
I could be wrong but xdg-open wants an image file for an argument, so I did not find a way to use it. In the script situation an application needs to be run, For the Linux situation I found running a detached screen running Webcamoid as a solution. The difference between the Apple and Linux situations is this detached screen existence that gets blown away the next time the script is run. Webcamoid closes and reopens if it was already running whereas an already running PhotoBooth just stays.
picamctl/picamctl.sh
Outdated
# trick is used to get around that. | ||
screen -dmS spawner | ||
screen -S spawner -X screen screen -dR thispicam "$piusbwebcamport" 115200 | ||
sleep 0.3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the delays? You can just read the output and wait for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how to read the output. I hardly understand screens. Can you provide a reference link to start me on the right track to read screen output? The sleeps were necessary. Sometimes the Pi Zero was not ready in time. I thought it was lucky sleep would take decimal numbers instead of only integers. Perhaps by reading the screen output it might also be possible to detect the unrefreshed state camera-ctl can be in when the Pi Zero already had it running.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on my tests with a Raspberry Pi 4, an even longer sleep is required, particularly this first one immediately after starting the screen connection.
picamctl/picamctl.sh
Outdated
# a detached target screen does not work without the target screen having | ||
# been attached at some point. Here the nest screen into a spawner screen | ||
# trick is used to get around that. | ||
screen -dmS spawner |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One might need sudo to access the device with screen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure what you mean. I can tell you it took a lot of testing to determine what was going on. Apparently one cannot stuff to a detached screen that has not been attached yet. Looking online knowing that observed behaviour led to this solution. The visible, ie attached, initial screen session blocks the script until that screen is terminated. Therefore the succeeding stuffs to provide root, root, camera-ctl do not occur until the first screen is terminated. Starting the initial screen detached allowed the succeeding code to proceed, but the stuffs vanish.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depending on the access mode of the device, you need sudo to access it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I know what you are talking about. I would never see that on my Pi 4 where I run as root. The script now checks for root user and advises running the script with sudo. It also checks for a screen command.
Sounds good. We could put the swmc-expect script there as well. |
I figured you all would decide how this script would fit in the repository, if it could fit in. I did not see a logical spot in the current repository. That is why I isolated it into its own folder.
I gather you might have seen the youtube video made regarding a microscope setup. I put that out soon after first getting it to work because of its potential in school settings. The setup is created for my wife’s school science department where she and other teachers, due to the pandemic, are trying to figure out ways to fit their lab course work into remote learning. This showmewebcam used this way is a game changer for them. For example it has been used to make videos of Daphina heart beats for students at home to figure out the beat rate. It has been used to make still images of anesthetized fruit flys for students at home to count genetic ratios in crossed fruit fly types. It provides a remote learning solution for all classroom lab sessions that involve using a microscope. We can not thank you enough for making this possible.
… On Feb 9, 2021, at 2:45 AM, Huan Truong ***@***.***> wrote:
Yeah I agree with @dgsiegel <https://github.com/dgsiegel>.
I also understand the intention of @akseidel <https://github.com/akseidel> though, as you seem to have a pretty nice set up with your microscope. Perhaps having this example script in a separate sample directory for specific example use-cases would be OK for me too.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#100 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ABOYA45MMJVD6RIP42DSBYLS6DY4JANCNFSM4XIIG5DQ>.
|
changes to conform with sh, started to add and make changes per initial comments
more sh conforming Added images for readme & added edited readme
testing in linux generated extra output when zargs kill had nothing to do
changes per linux and discoveries made experimenting with linux on RPI 4
Linux implementation as determined by working with Raspbian on a Raspberry Pi 4 and the application Webcamoid.
I'm curious about this, is it to be able to configure the camera when it's running? Wouldn't that be handled by setting controls on the host which are interpreted by uvc-gadget and then set accordingly? Or is this more specific? The camera should be configurable without using the serial console. |
Yes, you're right, see #93 However this is not fully functional right now, as it needs kernel/uvc patches and probably further changes in uvc-gadget. |
changes to arguments and how they are processed. Added sleep after client startup to avoid communication clash with USB serial connection startup.
ort cleanup
-m command parameter disables the automatic logging in to Pi Zero
Added missing comment regarding -m in the argument reaction function.
added help parameter
regarding newly added -m and -h
Description and instructions regarding the garbled login after a fresh boot.
#109 might be interesting to you, as it enables auto login through the serial console |
Yes the auto login looks promising. I was planning to eliminate the greeting line myself as the very first change to make if I ever managed to venture into building it. |
- detect missing screen command - detect user not root in linux - tested with showmewebcam autlog buiild - detect missing client application - other minor
This is a shell script with accompanying instruction readme that performs all tasks required to start camera-ctl in a Terminal session.
This script when executed in a Terminal window finishes up with "camera-ctl" running in a screen session. It automates the serial connection after detecting the tty serial device presence, logs in as root and runs "camera-ctl".
Although the showmewebcam readme describes "camera-ctl" in debugging it is actually an essential utility required to be running when showmewebcam is being used in dynamic situations. This script allows ordinary users to easily invoke "camera-ctl".