Created
January 10, 2018 14:12
-
-
Save lenaschimmel/44e4f9fe1eace8cf8723f0823b735268 to your computer and use it in GitHub Desktop.
Two scripts which reset a USB cam whenever a Game is started in Unity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
IFS=$'\n\t' | |
VENDOR="05a3" | |
PRODUCT="9230" | |
while : ; do | |
echo "Waiting for ./restart to appear" | |
while : ; do | |
[[ -f "./restart" ]] && break | |
sleep 1 | |
done | |
rm ./restart | |
for DIR in $(find /sys/bus/usb/devices/ -maxdepth 1 -type l); do | |
if [[ -f $DIR/idVendor && -f $DIR/idProduct && $(cat $DIR/idVendor) == $VENDOR && $(cat $DIR/idProduct) == $PRODUCT ]]; then | |
echo "Now resetting camera " $DIR | |
echo 0 > $DIR/authorized | |
sleep 0.5 | |
echo 1 > $DIR/authorized | |
fi | |
done | |
DEV=$(ls -t /dev/vid* | head -1) | |
ln -sf $DEV ./camlink | |
chmod 777 ./camlink | |
echo "New camera file is linked to ./camlink" | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Awake() { | |
StartCoroutine(cameraHack()); | |
} | |
IEnumerator cameraHack() { | |
var fileTrigger = "usbhack/restart"; | |
var fileLink = "usbhack/camlink"; | |
File.Delete(fileLink); | |
if (File.Exists(fileTrigger)) | |
{ | |
Debug.Log(fileTrigger+" already exists. Maybe you should run sudo ./usbhack/resetcam.sh &"); | |
yield return null; | |
} else { | |
var sr = File.CreateText(fileTrigger); | |
sr.Close(); | |
while(!File.Exists(fileLink)) { | |
yield return new WaitForSeconds(0.1f); | |
} | |
Debug.Log("Ready to access " + fileLink); | |
GetComponent<ARController>().StartAR(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment