diff --git a/go-airinput/input.go b/go-airinput/input.go
index a76446f..6cabf48 100644
--- a/go-airinput/input.go
+++ b/go-airinput/input.go
@@ -24,8 +24,7 @@ func dprintf(format string, args ...interface{}) {
}
}
-// Have to be call before other func
-func Init() error {
+func GuessTouchpad() (p string, err error) {
var id int = -1
for i := 0; i < 10; i++ {
namePath := fmt.Sprintf("/sys/class/input/event%d/device/name", i)
@@ -40,7 +39,7 @@ func Init() error {
dprintf("event%d: name: %s", i, name)
// $name may have Touchscreen and touchscreen
// atmel-maxtouch: Xiaomi2
- for _, possibleName := range []string{"ouchscreen$", "-tpd$", "atmel-maxtouch"} {
+ for _, possibleName := range []string{"ouchscreen$", "synaptics-rmi-ts", "ist30xx_ts_input", "mtk-tpd$", "atmel-maxtouch"} {
re := regexp.MustCompile(possibleName)
if re.MatchString(name) {
id = i
@@ -53,9 +52,21 @@ func Init() error {
}
dprintf("eventid: %d", id)
if id == -1 {
- return errors.New("cannot autodetect touchpad event")
+ return "", errors.New("cannot autodetect touchpad event")
+ }
+ return fmt.Sprintf("/dev/input/event%d", id), nil
+}
+
+// Have to be call before other func
+// if touchpadEvent == "", it will auto guess
+func Init(touchpadEvent string) (err error) {
+ if touchpadEvent == "" {
+ touchpadEvent, err = GuessTouchpad()
+ if err != nil {
+ return
+ }
}
- C.input_init(C.CString(fmt.Sprintf("/dev/input/event%d", id)))
+ C.input_init(C.CString(touchpadEvent))
return nil
}
diff --git a/main.go b/main.go
index 1886601..c1b7626 100644
--- a/main.go
+++ b/main.go
@@ -4,12 +4,7 @@ package main
import (
"flag"
"fmt"
- "image/png"
- "io"
"log"
- "net/http"
- "os"
- "time"
"github.com/netease/airinput/go-airinput"
"github.com/sevlyar/go-daemon"
@@ -19,52 +14,12 @@ var (
// m = macaron.Classic()
)
-func ServeWeb(addr string) {
- http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Content-Type", "text/html")
- io.WriteString(w, `
-
Native-Airinput
- Native Airinput
-
- pinch test
- `)
- })
- http.HandleFunc("/test", func(rw http.ResponseWriter, r *http.Request) {
- w, h := airinput.ScreenSize()
- fmt.Printf("width: %d, height: %d\n", w, h)
-
- lx, ly := w/6, 300
- mx, my := w/2, ly
- rx, ry := w/6*5, ly
- airinput.Pinch(lx, ly, mx, my,
- rx, ry, mx, my, 10, time.Second)
-
- time.Sleep(time.Second * 1)
-
- airinput.Pinch(mx, my, lx, ly,
- mx, my, rx, ry, 10, time.Second)
- io.WriteString(rw, "pinch run finish")
- })
- http.HandleFunc("/exit", func(w http.ResponseWriter, r *http.Request) {
- go func() {
- time.Sleep(500 * time.Microsecond)
- os.Exit(0)
- }()
- io.WriteString(w, "Server exit after 0.5s")
- })
- http.HandleFunc("/screen.png", func(w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Content-Type", "image/png")
- img, _ := airinput.TakeSnapshot()
- png.Encode(w, img)
- })
- http.ListenAndServe(addr, nil)
-}
-
var (
addr = flag.String("addr", ":21000", "server listen address")
debug = flag.Bool("debug", false, "enable debug")
isDaemon = flag.Bool("daemon", false, "run as daemon")
fix = flag.Bool("fix", false, "fix unexpected problem caused by airinput")
+ tpevent = flag.String("i", "", "touchpad event, eg: /dev/input/event1")
)
func main() {
@@ -77,7 +32,7 @@ func main() {
}
// initial
- if err := airinput.Init(); err != nil {
+ if err := airinput.Init(*tpevent); err != nil {
log.Fatal(err)
}
ipinfo, _ := MyIP()
@@ -98,35 +53,18 @@ func main() {
}
// useless
- img, err := airinput.TakeSnapshot()
- if err != nil {
- log.Fatal(err)
+ /*
+ img, err := airinput.TakeSnapshot()
+ if err != nil {
+ log.Fatal(err)
+ return
+ }
+ fd, err := os.Create("/data/local/tmp/air.png")
+ if err != nil {
+ log.Fatal(err)
+ }
+ defer fd.Close()
+ png.Encode(fd, img)
return
- }
- fd, err := os.Create("/data/local/tmp/air.png")
- if err != nil {
- log.Fatal(err)
- }
- defer fd.Close()
- png.Encode(fd, img)
- return
-
- w, h := airinput.ScreenSize()
- fmt.Printf("width: %d, height: %d\n", w, h)
-
- lx, ly := w/6, 300
- mx, my := w/2, ly
- rx, ry := w/6*5, ly
-
- // initial
- if err := airinput.Init(); err != nil {
- log.Fatal(err)
- }
- airinput.Pinch(lx, ly, mx, my,
- rx, ry, mx, my, 10, time.Second)
-
- time.Sleep(time.Second * 1)
-
- airinput.Pinch(mx, my, lx, ly,
- mx, my, rx, ry, 10, time.Second)
+ */
}
diff --git a/run.bat b/run.bat
index 5017163..941cc90 100644
--- a/run.bat
+++ b/run.bat
@@ -10,7 +10,7 @@ adb.exe push air-native "/data/local/tmp/air-native"
adb.exe shell chmod 755 "/data/local/tmp/air-native"
echo Starting...
-adb.exe shell kill -9 "/data/local/tmp/air-native"
-start /B adb.exe shell "/data/local/tmp/air-native -daemon"
+rem adb.exe shell kill -9 "/data/local/tmp/air-native"
+adb.exe shell "/data/local/tmp/air-native -daemon"
echo Service started successfully.
diff --git a/server.go b/server.go
new file mode 100644
index 0000000..fa07213
--- /dev/null
+++ b/server.go
@@ -0,0 +1,54 @@
+// Package main provides ...
+package main
+
+import (
+ "fmt"
+ "image/png"
+ "io"
+ "net/http"
+ "os"
+ "time"
+
+ "github.com/netease/airinput/go-airinput"
+)
+
+func ServeWeb(addr string) {
+ http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "text/html")
+ io.WriteString(w, `
+ Native-Airinput
+ Native Airinput
+
+ pinch test
+ `)
+ })
+ http.HandleFunc("/test", func(rw http.ResponseWriter, r *http.Request) {
+ w, h := airinput.ScreenSize()
+ fmt.Printf("width: %d, height: %d\n", w, h)
+
+ lx, ly := w/6, 300
+ mx, my := w/2, ly
+ rx, ry := w/6*5, ly
+ airinput.Pinch(lx, ly, mx, my,
+ rx, ry, mx, my, 10, time.Second)
+
+ time.Sleep(time.Second * 1)
+
+ airinput.Pinch(mx, my, lx, ly,
+ mx, my, rx, ry, 10, time.Second)
+ io.WriteString(rw, "pinch run finish")
+ })
+ http.HandleFunc("/exit", func(w http.ResponseWriter, r *http.Request) {
+ go func() {
+ time.Sleep(500 * time.Microsecond)
+ os.Exit(0)
+ }()
+ io.WriteString(w, "Server exit after 0.5s")
+ })
+ http.HandleFunc("/screen.png", func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "image/png")
+ img, _ := airinput.TakeSnapshot()
+ png.Encode(w, img)
+ })
+ http.ListenAndServe(addr, nil)
+}