forked from dennwc/inkview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
112 lines (89 loc) · 1.68 KB
/
utils.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package ink
/*
#include "inkview.h"
#cgo CFLAGS: -pthread
#cgo LDFLAGS: -pthread -lpthread -linkview
*/
import "C"
import (
"time"
"unsafe"
)
func cbool(v bool) C.int {
if v {
return 1
}
return 0
}
func incPtr(ptr unsafe.Pointer) unsafe.Pointer {
return unsafe.Pointer(uintptr(unsafe.Pointer(ptr)) + unsafe.Sizeof(C.size_t(0)))
}
func strArr(list **C.char) (out []string) {
if list == nil {
return
}
for list != nil {
s := C.GoString(*list)
if len(s) == 0 {
break
}
out = append(out, s)
list = (**C.char)(incPtr(unsafe.Pointer(list)))
}
return
}
func SetSleepMode(on bool) {
C.iv_sleepmode(cbool(on))
}
func SleepMode() bool {
return C.GetSleepmode() != 0
}
func BatteryPower() int {
return int(C.GetBatteryPower())
}
func Temperature() int {
return int(C.GetTemperature())
}
func IsPressed(key Key) bool {
return C.IsKeyPressed(C.int(key)) != 0
}
func IsCharging() bool {
return C.IsCharging() != 0
}
func IsUSBconnected() bool {
return C.IsUSBconnected() != 0
}
func IsSDinserted() bool {
return C.IsSDinserted() != 0
}
func DeviceModel() string {
return C.GoString(C.GetDeviceModel())
}
func HardwareType() string {
return C.GoString(C.GetHardwareType())
}
func SoftwareVersion() string {
return C.GoString(C.GetSoftwareVersion())
}
func SerialNumber() string {
return C.GoString(C.GetSerialNumber())
}
func DeviceKey() string {
return C.GoString(C.GetDeviceKey())
}
func Sleep(dt time.Duration, deep bool) {
ms := int(dt / time.Millisecond)
if ms == 0 {
ms = 1
}
_ = C.GoSleep(C.int(ms), cbool(deep))
}
func SetAutoPowerOff(on bool) {
C.SetAutoPowerOff(cbool(on))
}
func PowerOff() {
C.PowerOff()
}
func OpenMainMenu() {
C.OpenMainMenu()
}