mirror of https://github.com/OrbTools/OrbCommon
XDR compatible build mode (changes orb format)
parent
51b008b4ec
commit
39f4e73573
@ -0,0 +1,44 @@
|
|||||||
|
// +build !xdr
|
||||||
|
|
||||||
|
package devices
|
||||||
|
|
||||||
|
import (
|
||||||
|
"embed"
|
||||||
|
"encoding/binary"
|
||||||
|
"encoding/json"
|
||||||
|
"io"
|
||||||
|
"io/fs"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:embed json/*
|
||||||
|
var data embed.FS
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
DeviceTypes = make(map[string]*DeviceDef)
|
||||||
|
files, _ := fs.ReadDir(data, "json")
|
||||||
|
for _, file := range files {
|
||||||
|
dev := new(DeviceDef)
|
||||||
|
data, _ := data.ReadFile("json/" + file.Name())
|
||||||
|
json.Unmarshal(data, dev)
|
||||||
|
DeviceTypes[strings.Split(file.Name(), ".")[0]] = dev
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//LoadKM Load Orbmap KM structure
|
||||||
|
func LoadKeymap(file string, dev *DeviceDef) *KeyMap {
|
||||||
|
mapped := new(KeyMap)
|
||||||
|
of, _ := os.Open(file)
|
||||||
|
defer of.Close()
|
||||||
|
mapped.Keymap = make([]uint16, dev.NumKeys)
|
||||||
|
binary.Read(of, binary.LittleEndian, mapped.Keymap)
|
||||||
|
binary.Read(of, binary.LittleEndian, mapped.Color)
|
||||||
|
return mapped
|
||||||
|
}
|
||||||
|
|
||||||
|
//SavePKMKeymap saves an orb after edit
|
||||||
|
func SaveKeymap(mapped interface{}, file io.WriteCloser) {
|
||||||
|
binary.Write(file, binary.LittleEndian, mapped)
|
||||||
|
file.Close()
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
// +build xdr
|
||||||
|
|
||||||
|
package devices
|
||||||
|
|
||||||
|
import (
|
||||||
|
"embed"
|
||||||
|
"github.com/davecgh/go-xdr/xdr2"
|
||||||
|
"io"
|
||||||
|
"io/fs"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:embed xdr/*
|
||||||
|
var data embed.FS
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
DeviceTypes = make(map[string]*DeviceDef)
|
||||||
|
files, _ := fs.ReadDir(data, "xdr")
|
||||||
|
for _, file := range files {
|
||||||
|
dev := new(DeviceDef)
|
||||||
|
data, _ := jsons.ReadFile("xdr/" + file.Name())
|
||||||
|
xdr2.Unmarshal(data, dev)
|
||||||
|
DeviceTypes[strings.Split(file.Name(), ".")[0]] = dev
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//LoadKM Load Orbmap KM structure
|
||||||
|
func LoadKeymap(file string, dev *DeviceDef) *KeyMap {
|
||||||
|
mapped := new(KeyMap)
|
||||||
|
of, _ := os.Open(file)
|
||||||
|
xdr.Unmarshal(of, KeyMap)
|
||||||
|
return mapped
|
||||||
|
}
|
||||||
|
|
||||||
|
//SavePKMKeymap saves an orb after edit
|
||||||
|
func SaveKeymap(mapped interface{}, file io.WriteCloser) {
|
||||||
|
xdr.Marshal(file, mapped)
|
||||||
|
file.Close()
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/OrbTools/OrbCommon/devices"
|
||||||
|
xdr "github.com/davecgh/go-xdr/xdr2"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
files, _ := os.ReadDir("devices/json/")
|
||||||
|
for _, file := range files {
|
||||||
|
data, _ := os.ReadFile("devices/json/" + file.Name())
|
||||||
|
DevDef := &devices.DeviceDef{}
|
||||||
|
json.Unmarshal(data, DevDef)
|
||||||
|
xdo, _ := os.Create("devices/xdr/" + strings.Split(file.Name(), ".")[0] + ".bin")
|
||||||
|
xdr.Marshal(xdo, DevDef)
|
||||||
|
xdo.Close()
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
@ -1,3 +1,5 @@
|
|||||||
module github.com/OrbTools/OrbCommon
|
module github.com/OrbTools/OrbCommon
|
||||||
|
|
||||||
go 1.16
|
go 1.16
|
||||||
|
|
||||||
|
require github.com/davecgh/go-xdr v0.0.0-20161123171359-e6a2ba005892 // indirect
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
github.com/davecgh/go-xdr v0.0.0-20161123171359-e6a2ba005892 h1:qg9VbHo1TlL0KDM0vYvBG9EY0X0Yku5WYIPoFWt8f6o=
|
||||||
|
github.com/davecgh/go-xdr v0.0.0-20161123171359-e6a2ba005892/go.mod h1:CTDl0pzVzE5DEzZhPfvhY/9sPFMQIxaJ9VAMs9AagrE=
|
Binary file not shown.
@ -1,3 +1,5 @@
|
|||||||
|
// +build !xdr
|
||||||
|
|
||||||
package hid
|
package hid
|
||||||
|
|
||||||
import (
|
import (
|
@ -0,0 +1,57 @@
|
|||||||
|
// +build xdr
|
||||||
|
|
||||||
|
package hid
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
_ "embed"
|
||||||
|
xdr "github.com/davecgh/go-xdr/xdr2"
|
||||||
|
)
|
||||||
|
|
||||||
|
type KeyMaps struct {
|
||||||
|
Usb map[uint16]Key
|
||||||
|
Evdev map[uint16]Key
|
||||||
|
Xkb map[uint16]Key
|
||||||
|
Win map[uint16]Key
|
||||||
|
Mac map[uint16]Key
|
||||||
|
Code map[string]Key
|
||||||
|
Arr []Key
|
||||||
|
}
|
||||||
|
|
||||||
|
type Key struct {
|
||||||
|
Usb uint16
|
||||||
|
Evdev uint16
|
||||||
|
Xkb uint16
|
||||||
|
Win uint16
|
||||||
|
Mac uint16
|
||||||
|
Code string
|
||||||
|
}
|
||||||
|
|
||||||
|
var Mappings KeyMaps = KeyMaps{}
|
||||||
|
|
||||||
|
//go:embed generated.bin
|
||||||
|
var file []byte
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
xdr.Unmarshal(bytes.NewReader(file), Mappings)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetMappingFromHID(uv uint16) Key {
|
||||||
|
return Mappings.Usb[uv]
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetMappingFromWindows(uv uint16) Key {
|
||||||
|
return Mappings.Win[uv]
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetMappingFromLinux(uv uint16) Key {
|
||||||
|
return Mappings.Evdev[uv]
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetMappingFromName(name string) Key {
|
||||||
|
return Mappings.Code[name]
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetMappingFromX(code uint16) Key {
|
||||||
|
return Mappings.Xkb[code]
|
||||||
|
}
|
Loading…
Reference in New Issue