mirror of
https://github.com/taigrr/adb.git
synced 2026-04-02 02:58:42 -07:00
in progress on capture implementation
This commit is contained in:
5
adb.go
5
adb.go
@@ -14,6 +14,10 @@ const (
|
|||||||
Network
|
Network
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Create a Device with Connect() or a slice with Devices()
|
||||||
|
//
|
||||||
|
// Device contains the information necessary to connect to and
|
||||||
|
// communicate with a device
|
||||||
type Device struct {
|
type Device struct {
|
||||||
SerialNo Serial
|
SerialNo Serial
|
||||||
ConnType Connection
|
ConnType Connection
|
||||||
@@ -21,6 +25,7 @@ type Device struct {
|
|||||||
FileHandle string // TODO change this to a discrete type
|
FileHandle string // TODO change this to a discrete type
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Provides a connection string for Connect()
|
||||||
type ConnOptions struct {
|
type ConnOptions struct {
|
||||||
Address net.IPAddr
|
Address net.IPAddr
|
||||||
SerialNo Serial
|
SerialNo Serial
|
||||||
|
|||||||
31
capture.go
31
capture.go
@@ -2,6 +2,7 @@ package adb
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"log"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -64,6 +65,27 @@ type TapSequence struct {
|
|||||||
Events []Input
|
Events []Input
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ShortenSleep allows you to shorten all the sleep times between tap and swipe events.
|
||||||
|
//
|
||||||
|
// Provide a scalar value to divide the sleeps by. Providing `2` will halve all
|
||||||
|
// sleep durations in the TapSequence. Swipe durations and tap durations are
|
||||||
|
// unaffected.
|
||||||
|
|
||||||
|
func (t TapSequence) ShortenSleep(scalar int) TapSequence {
|
||||||
|
seq := []Input{}
|
||||||
|
for _, s := range t.Events {
|
||||||
|
switch y := s.(type) {
|
||||||
|
case SequenceSleep:
|
||||||
|
y.Duration = y.Duration / time.Duration(scalar)
|
||||||
|
seq = append(seq, y)
|
||||||
|
default:
|
||||||
|
seq = append(seq, s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
t.Events = seq
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
// GetLength returns the length of all Input events inside of a given TapSequence
|
// GetLength returns the length of all Input events inside of a given TapSequence
|
||||||
//
|
//
|
||||||
// This function is useful for devermining how long a context timeout should
|
// This function is useful for devermining how long a context timeout should
|
||||||
@@ -87,5 +109,14 @@ func (d Device) ReplayTapSequence(ctx context.Context, t TapSequence) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d Device) CaptureSequence(ctx context.Context) (t TapSequence, err error) {
|
func (d Device) CaptureSequence(ctx context.Context) (t TapSequence, err error) {
|
||||||
|
// this command will never finish, and always returns error code 130 if successful
|
||||||
|
stdout, _, errCode, err := execute(ctx, []string{"shell", "getevent", "-tl"})
|
||||||
|
if errCode != 130 {
|
||||||
|
log.Printf("Expected error code 130, but got \n", errCode)
|
||||||
|
}
|
||||||
|
if stdout == "" {
|
||||||
|
return TapSequence{}, ErrStdoutEmpty
|
||||||
|
}
|
||||||
|
|
||||||
return TapSequence{}, nil
|
return TapSequence{}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user