forked from bettercap/bettercap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_amazon.go
40 lines (33 loc) · 848 Bytes
/
build_amazon.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package hid
import (
"github.com/bettercap/bettercap/network"
)
const (
amzFrameDelay = 5
)
type AmazonBuilder struct {
}
func (b AmazonBuilder) frameFor(cmd *Command) []byte {
return []byte{0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
0x0f, 0, cmd.Mode, 0, cmd.HID, 0}
}
func (b AmazonBuilder) BuildFrames(dev *network.HIDDevice, commands []*Command) error {
for i, cmd := range commands {
if i == 0 {
for j := 0; j < 5; j++ {
cmd.AddFrame(b.frameFor(&Command{}), amzFrameDelay)
}
}
if cmd.IsHID() {
cmd.AddFrame(b.frameFor(cmd), amzFrameDelay)
cmd.AddFrame(b.frameFor(&Command{}), amzFrameDelay)
} else if cmd.IsSleep() {
for i, num := 0, cmd.Sleep/10; i < num; i++ {
cmd.AddFrame(b.frameFor(&Command{}), 10)
}
}
}
return nil
}