Compare commits

...

7 Commits

Author SHA1 Message Date
Minizbot2012 a7fbba49e0
devices: move "Device" string to end of struct 2 years ago
Minizbot2012 5d11e7ec76
hid: Fix? 2 years ago
Minizbot2012 37b922c27e
hid: fix? 2 years ago
Minizbot2012 554f3fa8fb
devices: Fix names 2 years ago
Minizbot2012 6eae660f74
ALL: Compartimentalize 2 years ago
Minizbot2012 32db943392
Sync 2 years ago
Minizbot2012 cb472d6f29
XDR: now enabled by default 2 years ago

@ -5,18 +5,18 @@ import (
"os" "os"
"strings" "strings"
xdr "github.com/Minizbot2012/minxdr" "github.com/Minizbot2012/minxdr"
"github.com/OrbTools/OrbCommon/devices" "github.com/OrbTools/OrbCommon/devices/structs"
) )
func main() { func main() {
files, _ := os.ReadDir("devices/json/") files, _ := os.ReadDir("devices/json/")
for _, file := range files { for _, file := range files {
data, _ := os.ReadFile("devices/json/" + file.Name()) data, _ := os.ReadFile("devices/json/" + file.Name())
DevDef := &devices.DeviceDef{} DevDef := &structs.DeviceDef{}
json.Unmarshal(data, DevDef) json.Unmarshal(data, DevDef)
xdo, _ := os.Create("devices/xdr/" + strings.Split(file.Name(), ".")[0] + ".bin") xdo, _ := os.Create("devices/xdr/" + strings.Split(file.Name(), ".")[0] + ".bin")
xdr.Marshal(xdo, DevDef) minxdr.Marshal(xdo, DevDef)
xdo.Close() xdo.Close()
} }
} }

@ -1,37 +1,47 @@
package devices package devices
//KeyMap singular keymap import (
type KeyMap struct { "bytes"
Keymap []uint16 "embed"
Color [3]byte "github.com/Minizbot2012/minxdr"
} "github.com/OrbTools/OrbCommon/devices/structs"
"io"
"io/fs"
"strings"
)
//KeyMaps a set of keymaps var DeviceTypes map[string]*structs.DeviceDef
type KeyMaps struct {
Maps []*KeyMap
Currentmap int
MCount int
}
type DeviceDef struct { //go:embed xdr/*
Backend string var df embed.FS
IsColor bool
MaxMappings int func init() {
NumKeys int DeviceTypes = make(map[string]*structs.DeviceDef)
Binding []byte files, _ := fs.ReadDir(df, "xdr")
Device struct { for _, file := range files {
SystemFile string dev := new(structs.DeviceDef)
VendorID int data, _ := df.ReadFile("xdr/" + file.Name())
ProdID int _, err := minxdr.Unmarshal(bytes.NewReader(data), dev)
} if err != nil {
GuiPages []struct { panic(err.Error())
Name string
Type string
Keys []struct {
KeyID int
KeyName string
} }
DeviceTypes[strings.Split(file.Name(), ".")[0]] = dev
} }
} }
var DeviceTypes map[string]*DeviceDef //LoadKeymap Load Orbmap KM structure
func LoadKeymap(file io.ReadCloser) *structs.KeyMap {
mapped := new(structs.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, "IsColor": true,
"MaxMappings": -1, "MaxMappings": -1,
"NumKeys": 26, "NumKeys": 26,
"NumColor": 3,
"Device": { "Device": {
"SystemFile": "/dev/input/by-id/usb-Razer_Razer_Orbweaver_Chroma-event-kbd", "SystemFile": "/dev/input/by-id/usb-Razer_Razer_Orbweaver_Chroma-event-kbd",
"VendorID": 5426, "VendorID": 5426,
@ -36,12 +37,10 @@
105, 105,
57 57
], ],
"GuiPages": [ "GuiPages": [{
{
"Name": "Grid", "Name": "Grid",
"Type": "PGrid", "Type": "PGrid",
"Keys": [ "Keys": [{
{
"KeyID": 0, "KeyID": 0,
"KeyName": "01" "KeyName": "01"
}, },
@ -126,8 +125,7 @@
{ {
"Name": "Side Keys", "Name": "Side Keys",
"Type": "PList", "Type": "PList",
"Keys": [ "Keys": [{
{
"KeyID": 20, "KeyID": 20,
"KeyName": "Upper Button" "KeyName": "Upper Button"
}, },

@ -0,0 +1,37 @@
package structs
//KeyMap singular keymap
type KeyMap struct {
Keymap []uint16
Color []byte
Device string
}
//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
}
}
}

Binary file not shown.

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

@ -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 h1:x7qoX7Lh5AFaYDsbQZKNFHpixY6ek2X1ud+j4qK7R6c=
github.com/Minizbot2012/minxdr v0.0.0-20211128051657-16f8bd94f749/go.mod h1:Qtnd0s9q5lVY7qtAGJPYVsRsfNLsIMVhxYqm01ohZJk= 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 package main
import ( import (
"encoding/json" "github.com/Minizbot2012/minxdr"
"github.com/OrbTools/OrbCommon/hid" "github.com/OrbTools/OrbCommon/hid/structs"
xdr "github.com/minizbot2012/minxdr"
"io" "io"
"io/fs" "io/fs"
"os" "os"
@ -18,22 +17,22 @@ func main() {
byts, _ := io.ReadAll(fil) byts, _ := io.ReadAll(fil)
fil.Close() fil.Close()
matches := rege.FindAllSubmatch(byts, -1) matches := rege.FindAllSubmatch(byts, -1)
KeyMaps := hid.KeyMaps{ KeyMaps := structs.KeyMaps{
Usb: make(map[uint16]hid.Key), Usb: make(map[uint16]structs.Key),
Evdev: make(map[uint16]hid.Key), Evdev: make(map[uint16]structs.Key),
Xkb: make(map[uint16]hid.Key), Xkb: make(map[uint16]structs.Key),
Win: make(map[uint16]hid.Key), Win: make(map[uint16]structs.Key),
Mac: make(map[uint16]hid.Key), Mac: make(map[uint16]structs.Key),
Code: make(map[string]hid.Key), Code: make(map[string]structs.Key),
} }
Arr := make([]hid.Key, 0) Arr := make([]structs.Key, 0)
for _, bar := range matches { for _, bar := range matches {
U, _ := strconv.ParseUint(string(bar[1]), 16, 16) U, _ := strconv.ParseUint(string(bar[1]), 16, 16)
E, _ := strconv.ParseUint(string(bar[2]), 16, 16) E, _ := strconv.ParseUint(string(bar[2]), 16, 16)
X, _ := strconv.ParseUint(string(bar[3]), 16, 16) X, _ := strconv.ParseUint(string(bar[3]), 16, 16)
W, _ := strconv.ParseUint(string(bar[4]), 16, 16) W, _ := strconv.ParseUint(string(bar[4]), 16, 16)
M, _ := strconv.ParseUint(string(bar[5]), 16, 16) M, _ := strconv.ParseUint(string(bar[5]), 16, 16)
Keys := hid.Key{ Keys := structs.Key{
Usb: uint16(U), Usb: uint16(U),
Evdev: uint16(E), Evdev: uint16(E),
Xkb: uint16(X), Xkb: uint16(X),
@ -60,11 +59,7 @@ func main() {
Arr = append(Arr, Keys) Arr = append(Arr, Keys)
} }
KeyMaps.Arr = Arr KeyMaps.Arr = Arr
out, _ := os.Create("hid/generated.json")
xdo, _ := os.Create("hid/generated.bin") xdo, _ := os.Create("hid/generated.bin")
defer xdo.Close() defer xdo.Close()
defer out.Close() minxdr.Marshal(xdo, KeyMaps)
jso, _ := json.Marshal(KeyMaps)
xdr.Marshal(xdo, KeyMaps)
out.Write(jso)
} }

@ -1,42 +1,37 @@
package hid package hid
type KeyMaps struct { import (
Usb map[uint16]Key "bytes"
Evdev map[uint16]Key _ "embed"
Xkb map[uint16]Key "github.com/Minizbot2012/minxdr"
Win map[uint16]Key "github.com/OrbTools/OrbCommon/hid/structs"
Mac map[uint16]Key )
Code map[string]Key
Arr []Key //go:embed generated.bin
var file []byte
func init() {
minxdr.Unmarshal(bytes.NewReader(file), &Mappings)
} }
type Key struct { var Mappings structs.KeyMaps
Usb uint16
Evdev uint16
Xkb uint16
Win uint16
Mac uint16
Code string
}
var Mappings KeyMaps = KeyMaps{}
func GetMappingFromHID(uv uint16) Key { func GetMappingFromHID(uv uint16) structs.Key {
return Mappings.Usb[uv] return Mappings.Usb[uv]
} }
func GetMappingFromWindows(uv uint16) Key { func GetMappingFromWindows(uv uint16) structs.Key {
return Mappings.Win[uv] return Mappings.Win[uv]
} }
func GetMappingFromLinux(uv uint16) Key { func GetMappingFromLinux(uv uint16) structs.Key {
return Mappings.Evdev[uv] return Mappings.Evdev[uv]
} }
func GetMappingFromName(name string) Key { func GetMappingFromName(name string) structs.Key {
return Mappings.Code[name] return Mappings.Code[name]
} }
func GetMappingFromX(code uint16) Key { func GetMappingFromX(code uint16) structs.Key {
return Mappings.Xkb[code] return Mappings.Xkb[code]
} }

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

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

@ -1,4 +1,4 @@
package OrbCommon package OrbCommon
//go:generate go run hid/generator/gen.go //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