-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmain.go
More file actions
63 lines (53 loc) · 2.03 KB
/
main.go
File metadata and controls
63 lines (53 loc) · 2.03 KB
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
package main
/*
#cgo CFLAGS: -Iheaders
#cgo LDFLAGS: -Llib -ljabra
#include "Common.h"
#include "GoWrapper.h"
#include <stdlib.h>
*/
import "C"
import (
"fmt"
"log"
"os"
"unsafe"
)
// sudo apt install libasound2 libcurl4
func main() {
oldSettings, err := enableRawMode()
if err != nil {
fmt.Fprintln(os.Stderr, "Failed to enable raw mode:", err)
return
}
defer restoreTerminal(oldSettings)
go startKeysPressedListener()
appId := C.CString("JabraLink")
C.Jabra_SetAppID(appId)
defer C.free(unsafe.Pointer(appId))
// Callback parameters: FirstScanForDevicesDoneFunc, DeviceAttachedFunc, DeviceRemovedFunc,
// ButtonInDataRawHidFunc, ButtonInDataTranslatedFunc, nonJabraDeviceDetection, configParams
if init := C.Jabra_InitializeV2(
nil, // FirstScanForDevicesDoneFunc (not used here)
(*[0]byte)(C.deviceAttachedFunc), // Callback for when a device is attached
(*[0]byte)(C.deviceRemovedFunc), // Callback for when a device is removed
nil, // Callback for raw HID button input (not used here)
nil, // Callback for translated button input (not used here)
false, // nonJabraDeviceDetection (not used here)
nil, // Additional configuration parameters (not used here)
); !init {
log.Fatalln("Failed to initialize Jabra SDK")
}
defer uninitialize()
// The current callback behavior is inconsistent. While the charging status updates as expected,
// the `levelInPercent` callback is sometimes delayed. This causes issues with timely updates.
// We need to ensure that the callback is triggered in a more predictable and consistent manner.
// C.Jabra_RegisterBatteryStatusUpdateCallbackV2((*[0]byte)(unsafe.Pointer(C.batteryStatusUpdate)))
defer close(stopUpdateBattery)
defer close(stopUpdatePairingList)
fmt.Print("\x1b[?25l") // Hide cursor
defer fmt.Print("\x1b[?25h") // Show cursor again
clearScreen()
startUi()
fmt.Println("\n\nThank you for using jlink! (ʘ‿ʘ)╯")
}