Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e1b1610598 | |||
| 4c2912ce1d | |||
| ba3404b7b8 | |||
| 8dc0e85dbc | |||
| 0048948102 | |||
| 454d109bc4 |
15
.github/workflows/go.yml
vendored
15
.github/workflows/go.yml
vendored
@ -12,7 +12,7 @@ on:
|
||||
permissions:
|
||||
contents: write
|
||||
jobs:
|
||||
build:
|
||||
build-package:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
@ -25,11 +25,16 @@ jobs:
|
||||
- name: install libusb
|
||||
run: sudo apt update && sudo apt install -y libusb-1.0-0-dev
|
||||
|
||||
- name: Build
|
||||
run: go build -v ./...
|
||||
- name: Build Release
|
||||
run: go build -v -o go-bsb-cams-v${{ github.ref_name }} -ldflags "-X main.gitVersion=${{ github.ref_name }}" ./...
|
||||
if: github.ref_type == 'tag'
|
||||
|
||||
- name: Release
|
||||
- name: Build Non-Release
|
||||
run: go build ./...
|
||||
if: github.ref_type != 'tag'
|
||||
|
||||
- name: Release Binary
|
||||
uses: softprops/action-gh-release@v2
|
||||
if: github.ref_type == 'tag'
|
||||
with:
|
||||
files: go-bsb-cams
|
||||
files: go-bsb-cams-v*
|
||||
|
||||
12
README.md
12
README.md
@ -1,9 +1,15 @@
|
||||
# go-bsb-cams 1.0
|
||||
# go-bsb-cams
|
||||
Simple program to take and output the Bigscreen Beyond 2e cameras to a webserver to be used with eyetracking software.
|
||||
|
||||
## Usage
|
||||
Pre-Compiled Binares are in the Releases Section, and can be run out of the box with `./go-bsb-cams`
|
||||
|
||||
The code by default outputs to `localhost:8080/stream` but can be configured with the `-port` flag.
|
||||
|
||||
To run or build the src with golang:
|
||||
|
||||
Clone This repo and get the dependencies with: `go get .`
|
||||
|
||||
To run, execute the following command within the root directory: `go run main.go` or build the package and run the resulting executable.
|
||||
Execute the following command within the root directory: `go run main.go` to run as a go program
|
||||
|
||||
The code by default outputs to `localhost:8080/stream` but can be configured within the code.
|
||||
Alternatively, the program can be built with `go build` and run via the resulting executable.
|
||||
|
||||
80
main.go
80
main.go
@ -7,7 +7,10 @@ import (
|
||||
"image/jpeg"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/user"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/google/gousb"
|
||||
@ -16,22 +19,94 @@ import (
|
||||
"github.com/kevmo314/go-uvc/pkg/descriptors"
|
||||
)
|
||||
|
||||
const udevrule = `# Bigscreen Bigeye
|
||||
KERNEL=="hidraw*", SUBSYSTEM=="hidraw", ATTRS{idVendor}=="35bd", ATTRS{idProduct}=="0202", MODE="0660", GROUP="users", TAG+="uaccess"
|
||||
SUBSYSTEM=="usb", ATTRS{idVendor}=="35bd", ATTRS{idProduct}=="0202", MODE="0660", GROUP="users", TAG+="uaccess"
|
||||
`
|
||||
const udevfilename = "99-bsb-cams.rules"
|
||||
|
||||
func getdevice() (device string) {
|
||||
ctx := gousb.NewContext()
|
||||
defer ctx.Close()
|
||||
dev, err := ctx.OpenDeviceWithVIDPID(0x35bd, 0x0202)
|
||||
user, _ := user.Current()
|
||||
if user.Username == "root" && !*sudo {
|
||||
log.Print("Running As Root Isnt Reccomended For Safety, Creating A UDEV Rule To Allow Rootless Access ")
|
||||
if _, err := os.Stat(udevfilename); err == nil {
|
||||
log.Print("File Already Exists")
|
||||
} else {
|
||||
err := os.WriteFile(udevfilename, []byte(udevrule), 0644)
|
||||
if err != nil {
|
||||
log.Fatalf("Could not Create File: %v", err)
|
||||
}
|
||||
}
|
||||
var response string
|
||||
log.Print("Would You Like The UDEV Rule Automatically Moved And Put In Place? (Y/N)")
|
||||
fmt.Scan(&response)
|
||||
switch strings.ToLower(response) {
|
||||
case "yes", "ye", "y":
|
||||
log.Printf("Would You Like The Rule Moved To The Userspace (/usr/lib/udev/rules.d/%v) Or The Linux OS Space (/etc/udev/rules.d/%v) (Good For Atomic Operating Systems) ", udevfilename)
|
||||
log.Print("0/Userspace 1/OS Space")
|
||||
fmt.Scan(&response)
|
||||
switch strings.ToLower(response) {
|
||||
case "0", "userspace":
|
||||
log.Printf("Putting File In /usr/lib/udev/rules.d/%v !!", udevfilename)
|
||||
err := os.Rename(udevfilename, "/usr/lib/udev/rules.d/"+udevfilename)
|
||||
if err != nil {
|
||||
log.Fatalf("Could Not Move File: %v", err)
|
||||
}
|
||||
case "1", "os space":
|
||||
log.Printf("Putting File In /etc/udev/rules.d/%v !!", udevfilename)
|
||||
err := os.Rename(udevfilename, "/etc/udev/rules.d/"+udevfilename)
|
||||
if err != nil {
|
||||
log.Fatalf("Could Not Move File: %v", err)
|
||||
}
|
||||
default:
|
||||
log.Fatal("Invalid Response")
|
||||
}
|
||||
log.Print("Please Reboot Your PC For Changes To Take Effect!!")
|
||||
os.Exit(0)
|
||||
case "n", "no":
|
||||
log.Printf("Please move the file (%v) into your udev rule directory and reboot for it to take effect, or if you REALLLLY want to run this program as sudo append --sudo to your run command", udevfilename)
|
||||
os.Exit(0)
|
||||
default:
|
||||
log.Fatal("Invalid Answer")
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
log.Fatalf("Could not open a device: %v", err)
|
||||
if err == gousb.ErrorAccess {
|
||||
log.Print("It looks like the cameras cannot be accessed, udev file being created in this directory")
|
||||
log.Printf("Creating UDEV Rule At %v", udevfilename)
|
||||
err := os.WriteFile(udevfilename, []byte(udevrule), 0644)
|
||||
if err != nil {
|
||||
log.Fatalf("Could not Create File: %v", err)
|
||||
}
|
||||
log.Print("File Created ! Please copy to your udev directory, chown to root, and reboot for it to take effect")
|
||||
os.Exit(0)
|
||||
|
||||
} else {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
if dev == nil {
|
||||
log.Fatal("Could Not Find Device, Please Make Sure It Is On And Plugged In !")
|
||||
}
|
||||
defer dev.Close()
|
||||
return fmt.Sprintf("/dev/bus/usb/%03v/%03v", dev.Desc.Bus, dev.Desc.Address)
|
||||
}
|
||||
|
||||
var gitVersion string
|
||||
var verbosePtr = flag.Bool("verbose", false, "Whether or not to show libusb errors")
|
||||
var port = flag.Int("port", 8080, "What Port To Output Frames To (Default is 8080)")
|
||||
var port = flag.Int("port", 8080, "What Port To Output Frames To")
|
||||
var version = flag.Bool("version", false, "Flag To Show Current Version")
|
||||
var sudo = flag.Bool("sudo", false, "Force Program To Run As Sudo")
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
if *version {
|
||||
log.Print("go-bsb-cams " + gitVersion)
|
||||
os.Exit(0)
|
||||
}
|
||||
stream := mjpeg.NewLiveStream()
|
||||
device := getdevice()
|
||||
// Pass your jpegBuffer frames using stream.UpdateJPEG(<your-buffer>)
|
||||
@ -40,6 +115,7 @@ func main() {
|
||||
mux.Handle("/stream", stream)
|
||||
log.Print("Server Is Running And Can Be Accessed At: http://localhost:" + strconv.Itoa(*port) + "/stream")
|
||||
log.Print("Make Sure You Have No Ending / When Inputting The Url Into Baballonia !!!")
|
||||
log.Print("If You Are Here And Cannot See The Cams, Please Close This Program, Unplug And Replug Your BSB, And Try Again :)")
|
||||
log.Fatal(http.ListenAndServe(":"+strconv.Itoa(*port), mux))
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user