Skip to content

Commit af7ec6b

Browse files
committed
202304100 Candidate Production Release
1 parent 1deb277 commit af7ec6b

9 files changed

+477
-67
lines changed

README.md

+58-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,58 @@
1-
# hdmisource
1+
# BATC HDMI Signal Source for Raspberry Pi 3B
2+
3+
This software build for a Raspberry Pi 3B enables it to become a very HDMI test card generator or camera. Only 2 external controls are required. A pushbutton between pins 18 and 20 to select the desired testcard and, if a camera is fitted, a switch between pins 16 and 14 to select the camera.
4+
5+
The current installation method only needs a Windows PC connected to the same (internet-connected) network as a Raspberry Pi 3. Do not connect a keyboard directly to your Raspberry Pi. You could connect an HDMI display, but it is not required at this stage.
6+
7+
- First download the 2023-02-21 release of Raspios Bullseye Lite on to your Windows PC from here https://downloads.raspberrypi.org/raspios_lite_armhf/images/raspios_lite_armhf-2023-02-22/2023-02-21-raspios-bullseye-armhf-lite.img.xz
8+
9+
- Unzip the image (using 7zip as it is a .xz compressed file) and then transfer it to a Micro-SD Card using Win32diskimager https://sourceforge.net/projects/win32diskimager/
10+
11+
- Before you remove the card from your Windows PC, look at the card with windows explorer; the volume should be labeled "boot". Create a new empty file called ssh in the top-level (root) directory by right-clicking, selecting New, Text Document, and then change the name to ssh (not ssh.txt). You should get a window warning about changing the filename extension. Click OK. If you do not get this warning, you have created a file called ssh.txt and you need to rename it ssh. IMPORTANT NOTE: by default, Windows (all versions) hides the .txt extension on the ssh file. To change this, in Windows Explorer, select File, Options, click the View tab, and then untick "Hide extensions for known file types". Then click OK.
12+
13+
- Create a second file in the boot directory, userconf.txt, with the following text in it:
14+
```sh
15+
pi:$6$B6mdmoSQrTvKkAbL$Ocwu9m3VjPGpZEGe.uJvYNI4w/UcMUYTJjtt327ysNbmPRlnROBCvigF0nRsVFH.QhfsLozLj4OJS8lRT442N0
16+
```
17+
This will create the default user and password.
18+
19+
- Power up the RPi with the new card inserted, and a network connection. Do not connect a keyboard to the Raspberry Pi.
20+
21+
- Find the IP address of your Raspberry Pi using an IP Scanner (such as Advanced IP Scanner http://filehippo.com/download_advanced_ip_scanner/ for Windows, or Fing on an iPhone) to get the RPi's IP address.
22+
23+
- From your windows PC use Putty (http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html) to log in to the IP address that you noted earlier. You will get a Security warning the first time you try; this is normal.
24+
25+
- Log in (user: pi, password: raspberry) then cut and paste the following code in, one line at a time:
26+
27+
```sh
28+
wget https://raw.githubusercontent.com/BritishAmateurTelevisionClub/hdmisource/main/install.sh
29+
chmod +x install.sh
30+
./install.sh
31+
```
32+
33+
The build will request that you enter your callsign and locator, and then finish off in about 15 minutes with no more user input required, so go and make a cup of coffee wait for it to reboot. When the build is finished the Pi will reboot and show the first testcard on the HDMI output.
34+
35+
- If your ISP is Virgin Media and you receive an error after entering the wget line: 'GnuTLS: A TLS fatal alert has been received.', it may be that your ISP is blocking access to GitHub. If (only if) you get this error with Virgin Media, paste the following command in, and press return.
36+
```sh
37+
sudo sed -i 's/^#name_servers.*/name_servers=8.8.8.8/' /etc/resolvconf.conf
38+
```
39+
Then reboot, and try again. The command asks your RPi to use Google's DNS, not your ISP's DNS.
40+
41+
- If your ISP is BT, you will need to make sure that "BT Web Protect" is disabled so that you are able to download the software.
42+
43+
# Advanced notes
44+
45+
To load the development version, cut and paste in the following lines:
46+
47+
```sh
48+
wget https://raw.githubusercontent.com/davecrump/hdmisource/main/install.sh
49+
chmod +x install.sh
50+
./install.sh -d
51+
```
52+
53+
To load a version from your own GitHub repo (github.com/your_account/vidsource), cut, paste and amend the following lines:
54+
```sh
55+
wget https://raw.githubusercontent.com/your_account/hdmisource/main/install.sh
56+
chmod +x install.sh
57+
./install.sh -u your_account
58+
```

camera.sh

+12-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ end
2121
EOF
2222
}
2323

24+
# Put a black background up
25+
sudo fbi -T 1 -noverbose -a /home/pi/hdmisource/images/1080_Black.jpg >/dev/null 2>/dev/null
2426

2527
CONFIGFILE=/boot/hdmisource_config.txt
2628
CAMERA=$(get-config_var camera $CONFIGFILE)
@@ -30,6 +32,13 @@ if [ "$DEBUG" != "yes" ]; then
3032
clear
3133
fi
3234

35+
if [ "$CAMERA" == "auto" ]; then
36+
CAMERA=$1
37+
if [ ${#CAMERA} -lt 2 ]; then
38+
CAMERA=auto
39+
fi
40+
fi
41+
3342
############ IDENTIFY USB VIDEO DEVICES #############################
3443

3544
WEBCAM_TYPE="None"
@@ -186,7 +195,7 @@ fi
186195
fi
187196
fi
188197

189-
if [ "$WEBCAM_TYPE" == "None" ]; then
198+
if [ "$WEBCAM_TYPE" == "None" ] && [ "$CAMERA" == "picam" ]; then
190199
libcamera-hello --list-cameras | grep -q "No cameras available"
191200
if [ $? != 0 ] && [ "$CAMERA" == "picam" ]; then
192201
WEBCAM_TYPE="PiCam"
@@ -262,6 +271,7 @@ fi
262271

263272
sudo killall vlc >/dev/null 2>/dev/null
264273
sudo killall libcamera-hello >/dev/null 2>/dev/null
274+
sudo killall fbi >/dev/null 2>/dev/null
265275

266276
if [ "$WEBCAM_TYPE" == "OldC920" ]; then
267277

@@ -288,7 +298,7 @@ if [ "$WEBCAM_TYPE" == "USBTV007" ]; then
288298
v4l2:///"$VID_USB":width=720:height=576:chroma=I420:fps=25 >/dev/null 2>/dev/null
289299
fi
290300

291-
if [ "$WEBCAM_TYPE" == "MS210x" ]; then
301+
if [ "$WEBCAM_TYPE" == "MS210X" ]; then
292302

293303
# Reduce the contrast to prevent crushed whites
294304
(sleep 0.7; v4l2-ctl -d $VID_USB --set-ctrl $ECCONTRAST >/dev/null 2>/dev/null) &

controller.sh

+163-2
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,152 @@ end
2424
EOF
2525
}
2626

27+
############ Function to check available cameras ###############
28+
29+
do_check_cameras()
30+
{
31+
# Check each in turn. Reset first
32+
OLDC920_CONNECTED="no"
33+
EAGLEEYE_CONNECTED="no"
34+
EAGLEEYE2_CONNECTED="no"
35+
USBTV007_CONNECTED="no"
36+
MS210X_CONNECTED="no"
37+
38+
lsusb | grep -q "046d:082d"
39+
if [ $? == 0 ] ; then
40+
OLDC920_CONNECTED="yes"
41+
fi
42+
43+
lsusb | grep -q "095d:3001"
44+
if [ $? == 0 ]; then
45+
EAGLEEYE_CONNECTED="yes"
46+
EAGLEEYES="$(lsusb | grep -c "095d:3001")"
47+
if [ $EAGLEEYES == 2 ]; then
48+
EAGLEEYE2_CONNECTED="yes"
49+
fi
50+
fi
51+
52+
lsusb | grep -q "1b71:3002"
53+
if [ $? == 0 ]; then
54+
USBTV007_CONNECTED="yes"
55+
fi
56+
57+
lsusb | grep -q "534d:0021"
58+
if [ $? == 0 ]; then
59+
MS210X_CONNECTED="yes"
60+
fi
61+
62+
# Now determine the next in sequence
63+
64+
if [ "$CURRENT_CAMERA" == "none" ] || [ "$CURRENT_CAMERA" == "picam" ]; then
65+
if [ "$OLDC920_CONNECTED" == "yes" ]; then
66+
NEXT_CAMERA="c920"
67+
else
68+
if [ "$EAGLEEYE_CONNECTED" == "yes" ]; then
69+
NEXT_CAMERA="eagleeye"
70+
else
71+
if [ "$USBTV007_CONNECTED" == "yes" ]; then
72+
NEXT_CAMERA="easycap"
73+
else
74+
if [ "$MS210X_CONNECTED" == "yes" ]; then
75+
NEXT_CAMERA="easycap"
76+
else
77+
NEXT_CAMERA="picam"
78+
fi
79+
fi
80+
fi
81+
fi
82+
elif [ "$CURRENT_CAMERA" == "c920" ]; then
83+
if [ "$EAGLEEYE_CONNECTED" == "yes" ]; then
84+
NEXT_CAMERA="eagleeye"
85+
else
86+
if [ "$USBTV007_CONNECTED" == "yes" ]; then
87+
NEXT_CAMERA="easycap"
88+
else
89+
if [ "$MS210X_CONNECTED" == "yes" ]; then
90+
NEXT_CAMERA="easycap"
91+
else
92+
if [ "$PICAM_CONNECTED" == "yes" ]; then
93+
NEXT_CAMERA="picam"
94+
else
95+
NEXT_CAMERA="c920"
96+
fi
97+
fi
98+
fi
99+
fi
100+
elif [ "$CURRENT_CAMERA" == "eagleeye" ]; then
101+
if [ "$EAGLEEYE2_CONNECTED" == "yes" ]; then
102+
NEXT_CAMERA="eagleeye2"
103+
else
104+
if [ "$USBTV007_CONNECTED" == "yes" ]; then
105+
NEXT_CAMERA="easycap"
106+
else
107+
if [ "$MS210X_CONNECTED" == "yes" ]; then
108+
NEXT_CAMERA="easycap"
109+
else
110+
if [ "$PICAM_CONNECTED" == "yes" ]; then
111+
NEXT_CAMERA="picam"
112+
else
113+
if [ "$OLDC920_CONNECTED" == "yes" ]; then
114+
NEXT_CAMERA="c920"
115+
else
116+
NEXT_CAMERA="eagleeye"
117+
fi
118+
fi
119+
fi
120+
fi
121+
fi
122+
elif [ "$CURRENT_CAMERA" == "eagleeye2" ]; then
123+
if [ "$USBTV007_CONNECTED" == "yes" ]; then
124+
NEXT_CAMERA="easycap"
125+
else
126+
if [ "$MS210X_CONNECTED" == "yes" ]; then
127+
NEXT_CAMERA="easycap"
128+
else
129+
if [ "$PICAM_CONNECTED" == "yes" ]; then
130+
NEXT_CAMERA="picam"
131+
else
132+
if [ "$OLDC920_CONNECTED" == "yes" ]; then
133+
NEXT_CAMERA="c920"
134+
else
135+
NEXT_CAMERA="eagleeye"
136+
fi
137+
fi
138+
fi
139+
fi
140+
elif [ "$CURRENT_CAMERA" == "easycap" ]; then
141+
if [ "$PICAM_CONNECTED" == "yes" ]; then
142+
NEXT_CAMERA="picam"
143+
else
144+
if [ "$OLDC920_CONNECTED" == "yes" ]; then
145+
NEXT_CAMERA="c920"
146+
else
147+
if [ "$EAGLEEYE_CONNECTED" == "yes" ]; then
148+
NEXT_CAMERA="eagleeye"
149+
else
150+
NEXT_CAMERA="easycap"
151+
fi
152+
fi
153+
fi
154+
fi
155+
}
156+
157+
158+
159+
160+
################################################################
161+
162+
27163
############ Read Config File ###############
28164

29165
CAM_SWITCH=$(get-config_var cam_switch $CONFIGFILE)
30166
BUTTON=$(get-config_var button $CONFIGFILE)
31167
ACTIVE=$(get-config_var active $CONFIGFILE)
168+
CAMERA=$(get-config_var camera $CONFIGFILE)
32169

170+
CURRENT_CAMERA="none"
171+
NEXT_CAMERA="none"
172+
FIRST_CAMERA="yes"
33173

34174
clear # Clear the screen
35175

@@ -48,12 +188,22 @@ pigs pud $CAM_SWITCH u # Enable the pull-up on the camera switch
48188
pigs pud $BUTTON u # Enable the pull-up on the button GPIO
49189
pigs w $ACTIVE 1 # set the Active LED GPIO high
50190

191+
# Check if picam is connected at boot
192+
libcamera-hello --list-cameras | grep -q "No cameras available"
193+
if [ $? != 0 ] ; then
194+
PICAM_CONNECTED="yes"
195+
fi
51196

52197
while true; do # Main loop
53198

54199
CAM_SWITCH_POS=$(pigs r $CAM_SWITCH)
55200
if [[ $CAM_SWITCH_POS -eq 0 ]]; then # Camera selected
56-
/home/pi/hdmisource/camera.sh & # Start camera
201+
202+
if [ "$FIRST_CAMERA" == "yes" ]; then
203+
/home/pi/hdmisource/camera.sh & # Run as normal
204+
else
205+
eval "/home/pi/hdmisource/camera.sh $CURRENT_CAMERA &" # Start last used camera
206+
fi
57207
sleep 0.1s
58208
SHUTDOWN_COUNT=0 # Now monitor for shutdown or other change request
59209
while [[ $CAM_SWITCH_POS -eq 0 ]] && (! test -f /home/pi/tmp/camera_change); do # Exit if camera is deselected
@@ -67,6 +217,15 @@ while true; do # Main loop
67217
SHUTDOWN_COUNT=0
68218
fi
69219

220+
if [[ $SHUTDOWN_COUNT -eq 1 ]] && [ "$CAMERA" == "auto" ]; then # only change camera once
221+
echo shutdown | nc 127.0.0.1 1111 >/dev/null 2>/dev/null
222+
sudo killall libcamera-hello >/dev/null 2>/dev/null
223+
do_check_cameras
224+
eval "/home/pi/hdmisource/camera.sh $NEXT_CAMERA &" # Start camera
225+
CURRENT_CAMERA=$NEXT_CAMERA
226+
FIRST_CAMERA="no"
227+
fi
228+
70229
if [ $SHUTDOWN_COUNT -gt 19 ]; then # 2 second press, so
71230

72231
echo shutdown | nc 127.0.0.1 1111 >/dev/null 2>/dev/null
@@ -119,8 +278,10 @@ while true; do # Main loop
119278
sleep 0.1s
120279

121280
done # End of camera switch "OFF" monitoring loop
122-
(sleep 2; sudo killall fbi) & # kill fbi after delay for camera to start
281+
(sleep 2; sudo killall fbi >/dev/null 2>/dev/null) & # kill fbi after delay for camera to start
123282

124283
fi # End of if Test Card selected
125284

285+
sudo killall test_card.sh >/dev/null 2>/dev/null # make sure that we don't get multiple test cards running
286+
126287
done # End of Main Loop

0 commit comments

Comments
 (0)