Skip to content

Commit

Permalink
update run.bat
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed Dec 17, 2014
1 parent 9d78649 commit 7d53dd2
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 84 deletions.
21 changes: 16 additions & 5 deletions go-airinput/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
}

Expand Down
92 changes: 15 additions & 77 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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, `<html>
<head><title>Native-Airinput</title></head>
<body><h2>Native Airinput</h2>
<div><img src="/screen.png" height="500px"/></div>
<a href="/test">pinch test</test>
</body></html>`)
})
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() {
Expand All @@ -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()
Expand All @@ -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)
*/
}
4 changes: 2 additions & 2 deletions run.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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.
54 changes: 54 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
@@ -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, `<html>
<head><title>Native-Airinput</title></head>
<body><h2>Native Airinput</h2>
<div><img src="/screen.png" height="500px"/></div>
<a href="/test">pinch test</test>
</body></html>`)
})
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)
}

0 comments on commit 7d53dd2

Please sign in to comment.