-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
93 lines (81 loc) · 2.43 KB
/
main.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
package main
/*
#cgo LDFLAGS: -ljabra
#include <stdlib.h>
#include "jabra/Common.h"
#include "jabra/JabraDeviceConfig.h"
#include "jabra/JabraNativeHid.h"
extern void goFirstscanfordevicesdonefunc(void);
extern void goDeviceattachedfunc(Jabra_DeviceInfo deviceInfo);
extern void goDeviceremovedfunc(unsigned short deviceID);
extern void goButtonindatarawhidfunc(unsigned short deviceID, unsigned short usagePage, unsigned short usage, unsigned char buttonInData);
__attribute__((weak))
char* testC(char* val) {
return val;
};
*/
import "C"
import (
"log"
"sync"
"time"
)
var deviceList = make(map[uint16]*DeviceInfo, 0)
var deviceListLock = sync.Mutex{}
var mainDevice *DeviceInfo
func main() {
log.Println(C.GoString(C.testC(C.CString("testing C binding: this line must be print"))))
C.Jabra_SetAppID(C.CString("linux-busylight"))
init := C.Jabra_InitializeV2((*[0]byte)(C.goFirstscanfordevicesdonefunc), (*[0]byte)(C.goDeviceattachedfunc), (*[0]byte)(C.goDeviceremovedfunc), (*[0]byte)(C.goButtonindatarawhidfunc), (*[0]byte)(nil), true, nil)
if !init {
log.Fatalln("failed to init jabra SDK")
}
for {
time.Sleep(60 * time.Second)
}
}
//export goFirstscanfordevicesdonefunc
func goFirstscanfordevicesdonefunc() {
log.Println("first scan")
}
//export goDeviceattachedfunc
func goDeviceattachedfunc(cdeviceinfo C.Jabra_DeviceInfo) {
deviceInfo := NewDeviceInfo(cdeviceinfo)
log.Println("attach ", deviceInfo.DeviceName)
addDevice(deviceInfo)
}
//export goDeviceremovedfunc
func goDeviceremovedfunc(deviceid uint16) {
if _, ok := deviceList[deviceid]; !ok {
return
}
log.Println("remove ", deviceList[deviceid].DeviceName)
removeDevice(deviceList[deviceid])
}
//export goButtonindatarawhidfunc
func goButtonindatarawhidfunc(deviceid uint16, usagepage uint16, usage uint16, buttonindata bool) {
log.Println(deviceid, usagepage, usage, buttonindata)
if mainDevice != nil && usagepage == 0xff30 && usage == 0x002a {
if buttonindata {
mainDevice.EnableBusylightStatus()
} else {
mainDevice.DisableBusylightStatus()
}
}
}
func addDevice(device *DeviceInfo) {
deviceListLock.Lock()
deviceList[device.DeviceID] = device
if device.IsBusylightSupported {
mainDevice = device
}
defer deviceListLock.Unlock()
}
func removeDevice(device *DeviceInfo) {
deviceListLock.Lock()
if mainDevice != nil && device.SerialNumber == mainDevice.SerialNumber {
mainDevice = nil
}
delete(deviceList, device.DeviceID)
defer deviceListLock.Unlock()
}