mirror of https://github.com/OrbTools/OrbCommon
XDR: now enabled by default
parent
1bd96d85d7
commit
5f2d65e321
@ -1,43 +0,0 @@
|
||||
//go:build !xdr
|
||||
// +build !xdr
|
||||
|
||||
package devices
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"io/fs"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//go:embed json/*
|
||||
var df embed.FS
|
||||
|
||||
func init() {
|
||||
DeviceTypes = make(map[string]*DeviceDef)
|
||||
files, _ := fs.ReadDir(df, "json")
|
||||
for _, file := range files {
|
||||
dev := new(DeviceDef)
|
||||
data, _ := df.ReadFile("json/" + file.Name())
|
||||
json.Unmarshal(data, dev)
|
||||
DeviceTypes[strings.Split(file.Name(), ".")[0]] = dev
|
||||
}
|
||||
}
|
||||
|
||||
//LoadKM Load Orbmap KM structure
|
||||
func LoadKeymap(file io.ReadCloser, dev *DeviceDef) *KeyMap {
|
||||
mapped := new(KeyMap)
|
||||
mapped.Keymap = make([]uint16, dev.NumKeys)
|
||||
binary.Read(file, binary.LittleEndian, mapped.Keymap)
|
||||
binary.Read(file, binary.LittleEndian, mapped.Color)
|
||||
file.Close()
|
||||
return mapped
|
||||
}
|
||||
|
||||
//SaveKeymap Saves Orbmap KM structure
|
||||
func SaveKeymap(file io.WriteCloser, mapped interface{}) {
|
||||
binary.Write(file, binary.LittleEndian, mapped)
|
||||
file.Close()
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
//go:build xdr
|
||||
// +build xdr
|
||||
|
||||
package devices
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"embed"
|
||||
xdr "github.com/Minizbot2012/minxdr"
|
||||
"io"
|
||||
"io/fs"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//go:embed xdr/*
|
||||
var df embed.FS
|
||||
|
||||
func init() {
|
||||
DeviceTypes = make(map[string]*DeviceDef)
|
||||
files, _ := fs.ReadDir(df, "xdr")
|
||||
for _, file := range files {
|
||||
dev := new(DeviceDef)
|
||||
data, _ := df.ReadFile("xdr/" + file.Name())
|
||||
_, err := xdr.Unmarshal(bytes.NewReader(data), dev)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
DeviceTypes[strings.Split(file.Name(), ".")[0]] = dev
|
||||
}
|
||||
}
|
||||
|
||||
//LoadKeymap Load Orbmap KM structure
|
||||
func LoadKeymap(file io.ReadCloser, dev *DeviceDef) *KeyMap {
|
||||
mapped := new(KeyMap)
|
||||
_, err := xdr.Unmarshal(file, mapped)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
file.Close()
|
||||
return mapped
|
||||
}
|
||||
|
||||
//SaveKeymap Save Orbmap KM struction
|
||||
func SaveKeymap(file io.WriteCloser, mapped interface{}) {
|
||||
xdr.Marshal(file, mapped)
|
||||
file.Close()
|
||||
}
|
Binary file not shown.
File diff suppressed because one or more lines are too long
@ -1,16 +0,0 @@
|
||||
//go:build !xdr
|
||||
// +build !xdr
|
||||
|
||||
package hid
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
//go:embed generated.json
|
||||
var file []byte
|
||||
|
||||
func init() {
|
||||
json.Unmarshal(file, &Mappings)
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
//go:build xdr
|
||||
// +build xdr
|
||||
|
||||
package hid
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
_ "embed"
|
||||
xdr "github.com/Minizbot2012/minxdr"
|
||||
)
|
||||
|
||||
//go:embed generated.bin
|
||||
var file []byte
|
||||
|
||||
func init() {
|
||||
xdr.Unmarshal(bytes.NewReader(file), &Mappings)
|
||||
}
|
Loading…
Reference in New Issue