Compare commits

...

7 Commits

Author SHA1 Message Date
mini 05d3f456f3 xdr: fix hid loading 3 years ago
mini 8b5637fb14 xdr: fix dumb mistake 3 years ago
mini f3c79bfa6d xdr: panic on error 3 years ago
mini 7940aa2f15 binaries: update generation 3 years ago
mini 23d44a5698 generator: hid use builtin structures 3 years ago
mini ce853a74ab generations: update
vscode: settings.json
devices: close file with function
3 years ago
mini 2b9161a874 xdr: fix imports and readdile 3 years ago

@ -0,0 +1,5 @@
{
"gopls": {
"build.buildFlags": ["xdr"]
}
}

@ -31,10 +31,11 @@ func LoadKeymap(file io.ReadCloser, dev *DeviceDef) *KeyMap {
mapped.Keymap = make([]uint16, dev.NumKeys) mapped.Keymap = make([]uint16, dev.NumKeys)
binary.Read(file, binary.LittleEndian, mapped.Keymap) binary.Read(file, binary.LittleEndian, mapped.Keymap)
binary.Read(file, binary.LittleEndian, mapped.Color) binary.Read(file, binary.LittleEndian, mapped.Color)
file.Close()
return mapped return mapped
} }
//SavePKMKeymap saves an orb after edit //SaveKeymap Saves Orbmap KM structure
func SaveKeymap(file io.WriteCloser, mapped interface{}) { func SaveKeymap(file io.WriteCloser, mapped interface{}) {
binary.Write(file, binary.LittleEndian, mapped) binary.Write(file, binary.LittleEndian, mapped)
file.Close() file.Close()

@ -8,7 +8,6 @@ import (
xdr "github.com/davecgh/go-xdr/xdr2" xdr "github.com/davecgh/go-xdr/xdr2"
"io" "io"
"io/fs" "io/fs"
"os"
"strings" "strings"
) )
@ -21,7 +20,10 @@ func init() {
for _, file := range files { for _, file := range files {
dev := new(DeviceDef) dev := new(DeviceDef)
data, _ := df.ReadFile("xdr/" + file.Name()) data, _ := df.ReadFile("xdr/" + file.Name())
xdr.Unmarshal(bytes.NewReader(data), dev) _, err := xdr.Unmarshal(bytes.NewReader(data), dev)
if err != nil {
panic(err.Error())
}
DeviceTypes[strings.Split(file.Name(), ".")[0]] = dev DeviceTypes[strings.Split(file.Name(), ".")[0]] = dev
} }
} }
@ -29,11 +31,15 @@ func init() {
//LoadKeymap Load Orbmap KM structure //LoadKeymap Load Orbmap KM structure
func LoadKeymap(file io.ReadCloser, dev *DeviceDef) *KeyMap { func LoadKeymap(file io.ReadCloser, dev *DeviceDef) *KeyMap {
mapped := new(KeyMap) mapped := new(KeyMap)
xdr.Unmarshal(of, mapped) _, err := xdr.Unmarshal(file, mapped)
if err != nil {
panic(err.Error())
}
file.Close()
return mapped return mapped
} }
//SavePKMKeymap saves an orb after edit //SaveKeymap Save Orbmap KM struction
func SaveKeymap(file io.WriteCloser, mapped interface{}) { func SaveKeymap(file io.WriteCloser, mapped interface{}) {
xdr.Marshal(file, mapped) xdr.Marshal(file, mapped)
file.Close() file.Close()

Binary file not shown.

@ -2,4 +2,4 @@ module github.com/OrbTools/OrbCommon
go 1.16 go 1.16
require github.com/davecgh/go-xdr v0.0.0-20161123171359-e6a2ba005892 // indirect require github.com/davecgh/go-xdr v0.0.0-20161123171359-e6a2ba005892

Binary file not shown.

@ -2,34 +2,15 @@ package main
import ( import (
"encoding/json" "encoding/json"
"github.com/OrbTools/OrbCommon/hid"
xdr "github.com/davecgh/go-xdr/xdr2"
"io" "io"
"io/fs" "io/fs"
"os" "os"
"regexp" "regexp"
"strconv" "strconv"
xdr "github.com/davecgh/go-xdr/xdr2"
) )
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
}
func main() { func main() {
rege, _ := regexp.Compile("DOM_CODE\\(0x07([0-9a-f]*), 0x([0-9a-f]*), 0x([0-9a-f]*), 0x([0-9a-f]*), 0x([0-9a-f]*), \"?[A-Za-z0-9]*\"?, ([A-Za-z_0-9]*)") rege, _ := regexp.Compile("DOM_CODE\\(0x07([0-9a-f]*), 0x([0-9a-f]*), 0x([0-9a-f]*), 0x([0-9a-f]*), 0x([0-9a-f]*), \"?[A-Za-z0-9]*\"?, ([A-Za-z_0-9]*)")
//DOM_CODE(USB, evdev, XKB, Win, Mac, _, Code) //DOM_CODE(USB, evdev, XKB, Win, Mac, _, Code)
@ -37,22 +18,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 := KeyMaps{ KeyMaps := hid.KeyMaps{
Usb: make(map[uint16]Key), Usb: make(map[uint16]hid.Key),
Evdev: make(map[uint16]Key), Evdev: make(map[uint16]hid.Key),
Xkb: make(map[uint16]Key), Xkb: make(map[uint16]hid.Key),
Win: make(map[uint16]Key), Win: make(map[uint16]hid.Key),
Mac: make(map[uint16]Key), Mac: make(map[uint16]hid.Key),
Code: make(map[string]Key), Code: make(map[string]hid.Key),
} }
Arr := make([]Key, 0) Arr := make([]hid.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 := Key{ Keys := hid.Key{
Usb: uint16(U), Usb: uint16(U),
Evdev: uint16(E), Evdev: uint16(E),
Xkb: uint16(X), Xkb: uint16(X),

@ -12,5 +12,5 @@ import (
var file []byte var file []byte
func init() { func init() {
xdr.Unmarshal(bytes.NewReader(file), Mappings) xdr.Unmarshal(bytes.NewReader(file), &Mappings)
} }

Loading…
Cancel
Save