-
Notifications
You must be signed in to change notification settings - Fork 0
/
epaper_test.go
94 lines (78 loc) · 1.87 KB
/
epaper_test.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package epaper_test
// sudo GOPATH=/home/pi/go /usr/local/go/bin/go test -v
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"testing"
"time"
"github.com/drahoslove/epaper"
_ "github.com/drahoslove/epaper/2in9" // will be used automatically
)
func TestReset(t *testing.T) {
displayBitmap := func(bitmap []byte) {
width := uint(bitmap[0])<<8 + uint(bitmap[1])
height := uint(bitmap[2])<<8 + uint(bitmap[3])
epaper.Display(bitmap[4:], 0, 0, width, height)
// Display(bitmap, 0, 0, model.Spec.Res.WIDTH, model.Spec.Res.HEIGHT)
}
epaper.Setup()
defer epaper.Teardown()
filename := os.Getenv("FILE")
mode := os.Getenv("MODE")
port := os.Getenv("SERVE")
epaper.Init(mode)
println("FILE", filename)
println("MODE", mode)
println("SERVE", port)
if filename != "" {
fileContent, err := ioutil.ReadFile(filename)
if err != nil {
panic(err)
}
displayBitmap(fileContent)
}
if port != "" {
lock := make(chan bool, 1)
http.HandleFunc("/epd/full", func(w http.ResponseWriter, r *http.Request) {
lock <- true
epaper.Init("full")
bodyContent, err := ioutil.ReadAll(r.Body)
if err != nil {
println(err)
}
displayBitmap(bodyContent)
w.Header().Add("Access-Control-Allow-Origin", "*")
epaper.Init("partial")
<-lock
})
http.HandleFunc("/epd/partial", func(w http.ResponseWriter, r *http.Request) {
lock <- true
bodyContent, err := ioutil.ReadAll(r.Body)
if err != nil {
println(err)
}
displayBitmap(bodyContent)
w.Header().Add("Access-Control-Allow-Origin", "*")
<-lock
})
http.ListenAndServe(":"+port, nil)
}
if os.Getenv("NOISE") != "" {
time.Sleep(time.Second)
for {
epaper.Randomize()
time.Sleep(time.Second)
}
}
if os.Getenv("BLINK") != "" {
tick := time.Tick(time.Millisecond * 300)
for {
epaper.Clear(0xFF)
fmt.Println(<-tick)
epaper.Clear(0x00)
fmt.Println(<-tick)
}
}
}