5
5
"fmt"
6
6
"log"
7
7
"os"
8
+ "os/signal"
9
+ "syscall"
8
10
9
11
"github.com/bahaaador/bluetooth-usb-peripheral-relay/internal/device"
10
12
"github.com/bahaaador/bluetooth-usb-peripheral-relay/internal/relay"
@@ -24,6 +26,10 @@ func main() {
24
26
fmt .Println ("Bluetooth Device Verification Tool" )
25
27
fmt .Println ("=================================" )
26
28
29
+ if err := verifyUSBHostSupport (); err != nil {
30
+ log .Fatal (err )
31
+ }
32
+
27
33
if err := verifyDevices (); err != nil {
28
34
log .Fatal (err )
29
35
}
@@ -33,6 +39,28 @@ func main() {
33
39
}
34
40
}
35
41
42
+ func verifyUSBHostSupport () error {
43
+ fmt .Println ("\n Checking USB Host Support:" )
44
+ hasHostCapability , isHostEnabled , err := device .CheckUSBHostSupport ()
45
+ if err != nil {
46
+ return fmt .Errorf ("failed to check USB host support: %v" , err )
47
+ }
48
+
49
+ if ! hasHostCapability {
50
+ return fmt .Errorf ("USB Host mode is not supported" )
51
+ } else {
52
+ fmt .Printf ("%s USB Host mode: supported\n " , checkMark )
53
+ }
54
+
55
+ if ! isHostEnabled {
56
+ return fmt .Errorf ("USB Host mode is not enabled" )
57
+ } else {
58
+ fmt .Printf ("%s USB Host mode: enabled\n " , checkMark )
59
+ }
60
+
61
+ return nil
62
+ }
63
+
36
64
func verifyDevices () error {
37
65
// Check HID gadget devices
38
66
fmt .Println ("\n Checking HID gadget devices:" )
@@ -94,7 +122,7 @@ func echoDeviceInputs() error {
94
122
95
123
// Only start readers for devices that were found
96
124
if mouseDevice != "" {
97
- mouseFile , err := osOpenFile (mouseDevice , os .O_WRONLY , 0666 )
125
+ mouseFile , err := osOpenFile (mouseDevice , os .O_RDONLY , 0666 )
98
126
if err != nil {
99
127
return fmt .Errorf ("failed to open mouse device: %v" , err )
100
128
}
@@ -103,16 +131,21 @@ func echoDeviceInputs() error {
103
131
}
104
132
105
133
if keyboardDevice != "" {
106
- keyboardFile , err := osOpenFile (keyboardDevice , os .O_WRONLY , 0666 )
134
+ keyboardFile , err := osOpenFile (keyboardDevice , os .O_RDONLY , 0666 )
107
135
if err != nil {
108
136
return fmt .Errorf ("failed to open keyboard device: %v" , err )
109
137
}
110
138
defer keyboardFile .Close ()
111
139
go readInput (keyboardFile , "Keyboard" )
112
140
}
113
141
114
- // Keep the program running
115
- select {}
142
+ // Add a channel to handle program termination
143
+ done := make (chan os.Signal , 1 )
144
+ signal .Notify (done , os .Interrupt , syscall .SIGTERM )
145
+
146
+ // Wait for interrupt signal
147
+ <- done
148
+ return nil
116
149
}
117
150
118
151
func readInput (file * os.File , deviceName string ) {
0 commit comments