XDR: now enabled by default

main
Minizbot2012 2 years ago
parent 1bd96d85d7
commit 5f2d65e321
No known key found for this signature in database
GPG Key ID: 977C8ADE12361917

@ -1,9 +1,20 @@
package devices
import (
_ "embed"
"github.com/Minizbot2012/minxdr"
)
var DeviceTypes map[string]*DeviceDef
//go:embed xdr/*
var df embed.FS
//KeyMap singular keymap
type KeyMap struct {
Device string
Keymap []uint16
Color [3]byte
Color []byte
}
//KeyMaps a set of keymaps
@ -18,6 +29,7 @@ type DeviceDef struct {
IsColor bool
MaxMappings int
NumKeys int
NumColor int
Binding []byte
Device struct {
SystemFile string
@ -34,4 +46,33 @@ type DeviceDef struct {
}
}
var DeviceTypes map[string]*DeviceDef
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 := mindxdr.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) *KeyMap {
mapped := new(KeyMap)
_, err := minxdr.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{}) {
minxdr.Marshal(file, mapped)
file.Close()
}

@ -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()
}

@ -3,6 +3,7 @@
"IsColor": true,
"MaxMappings": -1,
"NumKeys": 26,
"NumColor": 3,
"Device": {
"SystemFile": "/dev/input/by-id/usb-Razer_Razer_Orbweaver_Chroma-event-kbd",
"VendorID": 5426,
@ -36,12 +37,10 @@
105,
57
],
"GuiPages": [
{
"GuiPages": [{
"Name": "Grid",
"Type": "PGrid",
"Keys": [
{
"Keys": [{
"KeyID": 0,
"KeyName": "01"
},
@ -126,8 +125,7 @@
{
"Name": "Side Keys",
"Type": "PList",
"Keys": [
{
"Keys": [{
"KeyID": 20,
"KeyName": "Upper Button"
},

@ -2,7 +2,4 @@ module github.com/OrbTools/OrbCommon
go 1.17
require (
github.com/Minizbot2012/minxdr v0.0.0-20211128051657-16f8bd94f749
github.com/minizbot2012/minxdr v0.0.0-20210801163755-568fb466e98d
)
require github.com/Minizbot2012/minxdr v0.0.0-20211128051657-16f8bd94f749

@ -1,4 +1,2 @@
github.com/Minizbot2012/minxdr v0.0.0-20211128051657-16f8bd94f749 h1:x7qoX7Lh5AFaYDsbQZKNFHpixY6ek2X1ud+j4qK7R6c=
github.com/Minizbot2012/minxdr v0.0.0-20211128051657-16f8bd94f749/go.mod h1:Qtnd0s9q5lVY7qtAGJPYVsRsfNLsIMVhxYqm01ohZJk=
github.com/minizbot2012/minxdr v0.0.0-20210801163755-568fb466e98d h1:DU2lr4XDQnWR//L3rDlyqF8hPjy78NAUU/dYIHix1So=
github.com/minizbot2012/minxdr v0.0.0-20210801163755-568fb466e98d/go.mod h1:/f3HTVitNhL2hl4VdOCar3rLHlLc5pSogj2Yp4OQRY0=

Binary file not shown.

File diff suppressed because one or more lines are too long

@ -1,9 +1,8 @@
package main
import (
"encoding/json"
"github.com/Minizbot2012/minxdr"
"github.com/OrbTools/OrbCommon/hid"
xdr "github.com/minizbot2012/minxdr"
"io"
"io/fs"
"os"
@ -60,11 +59,7 @@ func main() {
Arr = append(Arr, Keys)
}
KeyMaps.Arr = Arr
out, _ := os.Create("hid/generated.json")
xdo, _ := os.Create("hid/generated.bin")
defer xdo.Close()
defer out.Close()
jso, _ := json.Marshal(KeyMaps)
xdr.Marshal(xdo, KeyMaps)
out.Write(jso)
minxdr.Marshal(xdo, KeyMaps)
}

@ -1,5 +1,11 @@
package hid
import (
"bytes"
_ "embed"
"github.com/Minizbot2012/minxdr"
)
type KeyMaps struct {
Usb map[uint16]Key
Evdev map[uint16]Key
@ -19,6 +25,13 @@ type Key struct {
Code string
}
//go:embed generated.bin
var file []byte
func init() {
minxdr.Unmarshal(bytes.NewReader(file), &Mappings)
}
var Mappings KeyMaps = KeyMaps{}
func GetMappingFromHID(uv uint16) Key {

@ -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)
}

@ -1,4 +1,4 @@
package OrbCommon
//go:generate go run hid/generator/gen.go
//go:generate go run devices/translator/jsoxdr.go
//go:generate go run devices/compiler/compile.go

Loading…
Cancel
Save