Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0aedf86c35 | |||
| 931c7119f5 | |||
| e1b1610598 | |||
| 4c2912ce1d | |||
| ba3404b7b8 | |||
| 8dc0e85dbc | |||
| 0048948102 | |||
| 454d109bc4 |
15
.github/workflows/go.yml
vendored
15
.github/workflows/go.yml
vendored
@ -12,7 +12,7 @@ on:
|
|||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build-package:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
@ -25,11 +25,16 @@ jobs:
|
|||||||
- name: install libusb
|
- name: install libusb
|
||||||
run: sudo apt update && sudo apt install -y libusb-1.0-0-dev
|
run: sudo apt update && sudo apt install -y libusb-1.0-0-dev
|
||||||
|
|
||||||
- name: Build
|
- name: Build Release
|
||||||
run: go build -v ./...
|
run: go build -v -o go-bsb-cams-${{ 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
|
uses: softprops/action-gh-release@v2
|
||||||
if: github.ref_type == 'tag'
|
if: github.ref_type == 'tag'
|
||||||
with:
|
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.
|
Simple program to take and output the Bigscreen Beyond 2e cameras to a webserver to be used with eyetracking software.
|
||||||
|
|
||||||
## Usage
|
## 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 .`
|
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.
|
||||||
|
|||||||
61
flake.lock
generated
Normal file
61
flake.lock
generated
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"flake-utils": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1731533236,
|
||||||
|
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1761236834,
|
||||||
|
"narHash": "sha256-+pthv6hrL5VLW2UqPdISGuLiUZ6SnAXdd2DdUE+fV2Q=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "d5faa84122bc0a1fd5d378492efce4e289f8eac1",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixpkgs-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-utils": "flake-utils",
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"systems": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
||||||
48
flake.nix
Normal file
48
flake.nix
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
{
|
||||||
|
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||||
|
inputs.flake-utils.url = "github:numtide/flake-utils";
|
||||||
|
|
||||||
|
outputs =
|
||||||
|
{ self
|
||||||
|
, nixpkgs
|
||||||
|
, flake-utils
|
||||||
|
}:
|
||||||
|
flake-utils.lib.eachDefaultSystem (
|
||||||
|
system:
|
||||||
|
let
|
||||||
|
pkgs = nixpkgs.legacyPackages."${system}";
|
||||||
|
go-bsb-cams-pkg = pkgs.buildGoModule {
|
||||||
|
pname = "go-bsb-cams";
|
||||||
|
version = "1.0.1";
|
||||||
|
src = ./.;
|
||||||
|
vendorHash = "sha256-U5B8QJRLSb4S1N0veMPodWfxRZuk/RkCjSd/RAzow78=";
|
||||||
|
|
||||||
|
buildInputs = with pkgs; [
|
||||||
|
libusb1
|
||||||
|
];
|
||||||
|
|
||||||
|
nativeBuildInputs = with pkgs; [
|
||||||
|
pkg-config
|
||||||
|
];
|
||||||
|
|
||||||
|
};
|
||||||
|
in
|
||||||
|
|
||||||
|
{
|
||||||
|
packages = {
|
||||||
|
default = go-bsb-cams-pkg;
|
||||||
|
oscgoesbrrr = go-bsb-cams-pkg;
|
||||||
|
};
|
||||||
|
|
||||||
|
devShells.default = pkgs.mkShell {
|
||||||
|
nativeBuildInputs = with pkgs; [
|
||||||
|
libusb1
|
||||||
|
go
|
||||||
|
gcc
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
formatter = pkgs.nixfmt-tree;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
80
main.go
80
main.go
@ -7,7 +7,10 @@ import (
|
|||||||
"image/jpeg"
|
"image/jpeg"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"os/user"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/google/gousb"
|
"github.com/google/gousb"
|
||||||
@ -16,22 +19,94 @@ import (
|
|||||||
"github.com/kevmo314/go-uvc/pkg/descriptors"
|
"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) {
|
func getdevice() (device string) {
|
||||||
ctx := gousb.NewContext()
|
ctx := gousb.NewContext()
|
||||||
defer ctx.Close()
|
defer ctx.Close()
|
||||||
dev, err := ctx.OpenDeviceWithVIDPID(0x35bd, 0x0202)
|
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 {
|
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()
|
defer dev.Close()
|
||||||
return fmt.Sprintf("/dev/bus/usb/%03v/%03v", dev.Desc.Bus, dev.Desc.Address)
|
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 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() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
if *version {
|
||||||
|
log.Print("go-bsb-cams " + gitVersion)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
stream := mjpeg.NewLiveStream()
|
stream := mjpeg.NewLiveStream()
|
||||||
device := getdevice()
|
device := getdevice()
|
||||||
// Pass your jpegBuffer frames using stream.UpdateJPEG(<your-buffer>)
|
// Pass your jpegBuffer frames using stream.UpdateJPEG(<your-buffer>)
|
||||||
@ -40,6 +115,7 @@ func main() {
|
|||||||
mux.Handle("/stream", stream)
|
mux.Handle("/stream", stream)
|
||||||
log.Print("Server Is Running And Can Be Accessed At: http://localhost:" + strconv.Itoa(*port) + "/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("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))
|
log.Fatal(http.ListenAndServe(":"+strconv.Itoa(*port), mux))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user