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"
"strings"
xdr "github.com/Minizbot2012/minxdr"
"github.com/OrbTools/OrbCommon/devices"
"github.com/Minizbot2012/minxdr"
"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")
xdr.Marshal(xdo, DevDef)
minxdr.Marshal(xdo, DevDef)
xdo.Close()
}
}

@ -1,37 +1,47 @@
package devices
//KeyMap singular keymap
type KeyMap struct {
Keymap []uint16
Color [3]byte
}
import (
"bytes"
"embed"
"github.com/Minizbot2012/minxdr"
"github.com/OrbTools/OrbCommon/devices/structs"
"io"
"io/fs"
"strings"
)
//KeyMaps a set of keymaps
type KeyMaps struct {
Maps []*KeyMap
Currentmap int
MCount int
}
var DeviceTypes map[string]*structs.DeviceDef
type DeviceDef struct {
Backend string
IsColor bool
MaxMappings int
NumKeys int
Binding []byte
Device struct {
SystemFile string
VendorID int
ProdID int
}
GuiPages []struct {
Name string
Type string
Keys []struct {
KeyID int
KeyName string
//go:embed xdr/*
var df embed.FS
func init() {
DeviceTypes = make(map[string]*structs.DeviceDef)
files, _ := fs.ReadDir(df, "xdr")
for _, file := range files {
dev := new(structs.DeviceDef)
data, _ := df.ReadFile("xdr/" + file.Name())
_, err := minxdr.Unmarshal(bytes.NewReader(data), dev)
if err != nil {
panic(err.Error())
}
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,
"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"
},

@ -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
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/OrbTools/OrbCommon/hid"
xdr "github.com/minizbot2012/minxdr"
"github.com/Minizbot2012/minxdr"
"github.com/OrbTools/OrbCommon/hid/structs"
"io"
"io/fs"
"os"
@ -18,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),
@ -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,42 +1,37 @@
package hid
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
import (
"bytes"
_ "embed"
"github.com/Minizbot2012/minxdr"
"github.com/OrbTools/OrbCommon/hid/structs"
)
//go:embed generated.bin
var file []byte
func init() {
minxdr.Unmarshal(bytes.NewReader(file), &Mappings)
}
type Key struct {
Usb uint16
Evdev uint16
Xkb uint16
Win uint16
Mac uint16
Code string
}
var Mappings KeyMaps = KeyMaps{}
var Mappings 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]
}

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