123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- package main
- import (
- "log"
- "net/http"
- "os"
- "os/signal"
- "syscall"
- "imuslab.com/remdeskvm/remdeskd/mod/remdesaux"
- "imuslab.com/remdeskvm/remdeskd/mod/usbcapture"
- )
- func startUsbKvmMode() error {
- log.Println("Starting in USB KVM mode...")
- //Start the HID controller
- err := usbKVM.Connect()
- if err != nil {
- log.Fatal(err)
- }
- //Start auxiliary MCU connections
- auxMCU, err = remdesaux.NewAuxOutbandController(*usbAuxilaryDeviceName, *usbAuxBaudRate)
- if err != nil {
- log.Fatal(err)
- }
- //Try get the UUID from the auxiliary MCU
- uuid, err := auxMCU.GetUUID()
- if err != nil {
- log.Println("Get UUID failed:", err)
- } else {
- log.Println("Auxiliary MCU found with UUID:", uuid)
- //Register the AUX routes if success
- registerLocalAuxRoutes()
- }
- // Initiate the video capture device
- videoCapture, err = usbcapture.NewInstance(&usbcapture.Config{
- DeviceName: *captureDeviceName,
- AudioConfig: usbcapture.GetDefaultAudioConfig(),
- })
- if err != nil {
- log.Fatalf("Failed to create video capture instance: %v", err)
- }
- //Get device information for debug
- usbcapture.PrintV4L2FormatInfo(*captureDeviceName)
- //Start the video capture device
- err = videoCapture.StartVideoCapture(&usbcapture.CaptureResolution{
- Width: 1920,
- Height: 1080,
- FPS: 10,
- })
- if err != nil {
- log.Fatal(err)
- }
- // Handle program exit to close the HID controller
- c := make(chan os.Signal, 1)
- signal.Notify(c, os.Interrupt, syscall.SIGTERM)
- go func() {
- <-c
- log.Println("Shutting down usbKVM...")
- if usbKVM != nil {
- //usbKVM.Close()
- }
- if auxMCU != nil {
- auxMCU.Close()
- }
- log.Println("Shutting down capture device...")
- if videoCapture != nil {
- videoCapture.Close()
- }
- os.Exit(0)
- }()
- // Register the API routes
- registerAPIRoutes()
- addr := ":9000"
- log.Printf("Serving on http://localhost%s\n", addr)
- err = http.ListenAndServe(addr, nil)
- return err
- }
|