diff --git a/devices/compiller/compile.go b/devices/compiler/compile.go similarity index 82% rename from devices/compiller/compile.go rename to devices/compiler/compile.go index 33ef2d4..e29f7fc 100755 --- a/devices/compiller/compile.go +++ b/devices/compiler/compile.go @@ -6,14 +6,14 @@ import ( "strings" "github.com/Minizbot2012/minxdr" - "github.com/OrbTools/OrbCommon/devices" + "github.com/OrbTools/OrbCommon/devices/structs" ) func main() { files, _ := os.ReadDir("devices/json/") for _, file := range files { data, _ := os.ReadFile("devices/json/" + file.Name()) - DevDef := &devices.DeviceDef{} + DevDef := &structs.DeviceDef{} json.Unmarshal(data, DevDef) xdo, _ := os.Create("devices/xdr/" + strings.Split(file.Name(), ".")[0] + ".bin") minxdr.Marshal(xdo, DevDef) diff --git a/devices/devices.go b/devices/devices.go index 22c380e..3163160 100755 --- a/devices/devices.go +++ b/devices/devices.go @@ -4,6 +4,7 @@ import ( "bytes" "embed" "github.com/Minizbot2012/minxdr" + _ "github.com/OrbTools/OrbCommon/devices/structs" "io" "io/fs" "strings" @@ -14,42 +15,6 @@ var DeviceTypes map[string]*DeviceDef //go:embed xdr/* var df embed.FS -//KeyMap singular keymap -type KeyMap struct { - Device string - Keymap []uint16 - Color []byte -} - -//KeyMaps a set of keymaps -type KeyMaps struct { - Maps []*KeyMap - Currentmap int - MCount int -} - -type DeviceDef struct { - Backend string - IsColor bool - MaxMappings int - NumKeys int - NumColor int - Binding []byte - Device struct { - SystemFile string - VendorID int - ProdID int - } - GuiPages []struct { - Name string - Type string - Keys []struct { - KeyID int - KeyName string - } - } -} - func init() { DeviceTypes = make(map[string]*DeviceDef) files, _ := fs.ReadDir(df, "xdr") diff --git a/devices/structs/structs.go b/devices/structs/structs.go new file mode 100755 index 0000000..2231fa7 --- /dev/null +++ b/devices/structs/structs.go @@ -0,0 +1,37 @@ +package structs + +//KeyMap singular keymap +type KeyMap struct { + Device string + Keymap []uint16 + Color []byte +} + +//KeyMaps a set of keymaps +type KeyMaps struct { + Maps []*KeyMap + Currentmap int + MCount int +} + +type DeviceDef struct { + Backend string + IsColor bool + MaxMappings int + NumKeys int + NumColor int + Binding []byte + Device struct { + SystemFile string + VendorID int + ProdID int + } + GuiPages []struct { + Name string + Type string + Keys []struct { + KeyID int + KeyName string + } + } +} diff --git a/devices/xdr/orbweaver.bin b/devices/xdr/orbweaver.bin index fe77bfa..e4ae31a 100755 Binary files a/devices/xdr/orbweaver.bin and b/devices/xdr/orbweaver.bin differ diff --git a/hid/generated.bin b/hid/generated.bin index a429c56..e238182 100755 Binary files a/hid/generated.bin and b/hid/generated.bin differ diff --git a/hid/generator/gen.go b/hid/generator/gen.go index dde67db..85f40df 100755 --- a/hid/generator/gen.go +++ b/hid/generator/gen.go @@ -2,7 +2,7 @@ package main import ( "github.com/Minizbot2012/minxdr" - "github.com/OrbTools/OrbCommon/hid" + "github.com/OrbTools/OrbCommon/hid/structs" "io" "io/fs" "os" @@ -17,22 +17,22 @@ func main() { byts, _ := io.ReadAll(fil) fil.Close() matches := rege.FindAllSubmatch(byts, -1) - KeyMaps := hid.KeyMaps{ - Usb: make(map[uint16]hid.Key), - Evdev: make(map[uint16]hid.Key), - Xkb: make(map[uint16]hid.Key), - Win: make(map[uint16]hid.Key), - Mac: make(map[uint16]hid.Key), - Code: make(map[string]hid.Key), + KeyMaps := structs.KeyMaps{ + Usb: make(map[uint16]structs.Key), + Evdev: make(map[uint16]structs.Key), + Xkb: make(map[uint16]structs.Key), + Win: make(map[uint16]structs.Key), + Mac: make(map[uint16]structs.Key), + Code: make(map[string]structs.Key), } - Arr := make([]hid.Key, 0) + Arr := make([]structs.Key, 0) for _, bar := range matches { U, _ := strconv.ParseUint(string(bar[1]), 16, 16) E, _ := strconv.ParseUint(string(bar[2]), 16, 16) X, _ := strconv.ParseUint(string(bar[3]), 16, 16) W, _ := strconv.ParseUint(string(bar[4]), 16, 16) M, _ := strconv.ParseUint(string(bar[5]), 16, 16) - Keys := hid.Key{ + Keys := structs.Key{ Usb: uint16(U), Evdev: uint16(E), Xkb: uint16(X), diff --git a/hid/hid.go b/hid/hid.go index b0f9b15..6597b48 100755 --- a/hid/hid.go +++ b/hid/hid.go @@ -4,27 +4,9 @@ import ( "bytes" _ "embed" "github.com/Minizbot2012/minxdr" + structs "github.com/OrbTools/OrbCommon/hid/structs" ) -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 -} - //go:embed generated.bin var file []byte @@ -32,24 +14,24 @@ func init() { minxdr.Unmarshal(bytes.NewReader(file), &Mappings) } -var Mappings KeyMaps = KeyMaps{} +var Mappings KeyMaps = structs.KeyMaps{} -func GetMappingFromHID(uv uint16) Key { +func GetMappingFromHID(uv uint16) structs.Key { return Mappings.Usb[uv] } -func GetMappingFromWindows(uv uint16) Key { +func GetMappingFromWindows(uv uint16) structs.Key { return Mappings.Win[uv] } -func GetMappingFromLinux(uv uint16) Key { +func GetMappingFromLinux(uv uint16) structs.Key { return Mappings.Evdev[uv] } -func GetMappingFromName(name string) Key { +func GetMappingFromName(name string) structs.Key { return Mappings.Code[name] } -func GetMappingFromX(code uint16) Key { +func GetMappingFromX(code uint16) structs.Key { return Mappings.Xkb[code] } diff --git a/hid/structs/structs.go b/hid/structs/structs.go new file mode 100755 index 0000000..a26ad8f --- /dev/null +++ b/hid/structs/structs.go @@ -0,0 +1,20 @@ +package structs + +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 +}