mirror of https://github.com/OrbTools/OrbCommon
Compare commits
7 Commits
693719e66a
...
a7fbba49e0
Author | SHA1 | Date |
---|---|---|
Minizbot2012 | a7fbba49e0 | 2 years ago |
Minizbot2012 | 5d11e7ec76 | 2 years ago |
Minizbot2012 | 37b922c27e | 2 years ago |
Minizbot2012 | 554f3fa8fb | 2 years ago |
Minizbot2012 | 6eae660f74 | 2 years ago |
Minizbot2012 | 32db943392 | 2 years ago |
Minizbot2012 | cb472d6f29 | 2 years ago |
@ -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()
|
|
||||||
}
|
|
@ -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.
Binary file not shown.
File diff suppressed because one or more lines are too long
@ -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
|
||||||
|
}
|
Loading…
Reference in New Issue