2
0
mirror of https://github.com/OrbTools/OrbCommon synced 2024-11-18 03:25:32 +00:00

Merge branch 'main' of github.com:OrbTools/OrbCommon

This commit is contained in:
Minizbot2012 2021-07-28 01:24:09 -04:00
commit 51b008b4ec
No known key found for this signature in database
GPG Key ID: 977C8ADE12361917
6 changed files with 239 additions and 8434 deletions

79
devices/devices.go Normal file
View File

@ -0,0 +1,79 @@
package devices
import (
"embed"
"encoding/binary"
"encoding/json"
"io"
"io/fs"
"os"
"strings"
)
//KeyMap singular keymap
type KeyMap struct {
Keymap []uint16
Color [3]byte
}
//KeyMaps a set of keymaps
type KeyMaps struct {
Maps []*KeyMap
Currentmap int
MCount int
}
//go:embed json/*
var jsons embed.FS
type DeviceDef struct {
Backend string
IsColor bool
MaxMappings int
NumKeys int
Binding []byte
Device struct {
SystemFile string
VendorID int
ProdID int
}
GuiPages []struct {
Hive string
Name string
Type string
Keys []struct {
KeyID int
KeyName string
}
}
}
var DeviceTypes map[string]*DeviceDef
func init() {
DeviceTypes = make(map[string]*DeviceDef)
files, _ := fs.ReadDir(jsons, "json")
for _, file := range files {
dev := new(DeviceDef)
data, _ := jsons.ReadFile("json/" + file.Name())
json.Unmarshal(data, dev)
DeviceTypes[strings.Split(file.Name(), ".")[0]] = dev
}
}
//LoadKM Load Orbmap KM structure
func LoadKeymap(file string, dev *DeviceDef) *KeyMap {
mapped := new(KeyMap)
of, _ := os.Open(file)
defer of.Close()
mapped.Keymap = make([]uint16, dev.NumKeys)
binary.Read(of, binary.LittleEndian, mapped.Keymap)
binary.Read(of, binary.LittleEndian, mapped.Color)
return mapped
}
//SavePKMKeymap saves an orb after edit
func SaveKeymap(mapped interface{}, file io.WriteCloser) {
binary.Write(file, binary.LittleEndian, mapped)
file.Close()
}

159
devices/json/orbweaver.json Normal file
View File

@ -0,0 +1,159 @@
{
"Backend": "keypad",
"IsColor": true,
"MaxMappings": -1,
"NumKeys": 26,
"Device": {
"SystemFile": "/dev/input/by-id/usb-Razer_Razer_Orbweaver_Chroma-event-kbd",
"VendorID": 5426,
"ProdID": 519
},
"Binding": [
41,
2,
3,
4,
5,
15,
16,
17,
18,
19,
58,
30,
31,
32,
33,
42,
44,
45,
46,
47,
56,
103,
106,
108,
105,
57
],
"GuiPages": [
{
"Hive": "MIP",
"Name": "Grid",
"Type": "PGrid",
"Keys": [
{
"KeyID": 0,
"KeyName": "01"
},
{
"KeyID": 1,
"KeyName": "02"
},
{
"KeyID": 2,
"KeyName": "03"
},
{
"KeyID": 3,
"KeyName": "04"
},
{
"KeyID": 4,
"KeyName": "05"
},
{
"KeyID": 5,
"KeyName": "06"
},
{
"KeyID": 6,
"KeyName": "07"
},
{
"KeyID": 7,
"KeyName": "08"
},
{
"KeyID": 8,
"KeyName": "09"
},
{
"KeyID": 9,
"KeyName": "10"
},
{
"KeyID": 10,
"KeyName": "11"
},
{
"KeyID": 11,
"KeyName": "12"
},
{
"KeyID": 12,
"KeyName": "13"
},
{
"KeyID": 13,
"KeyName": "14"
},
{
"KeyID": 14,
"KeyName": "15"
},
{
"KeyID": 15,
"KeyName": "16"
},
{
"KeyID": 16,
"KeyName": "17"
},
{
"KeyID": 17,
"KeyName": "18"
},
{
"KeyID": 18,
"KeyName": "19"
},
{
"KeyID": 19,
"KeyName": "20"
}
]
},
{
"Hive": "SIP",
"Name": "Side Keys",
"Type": "PList",
"Keys": [
{
"KeyID": 20,
"KeyName": "Upper Button"
},
{
"KeyID": 21,
"KeyName": "DPad Up"
},
{
"KeyID": 22,
"KeyName": "DPad Right"
},
{
"KeyID": 23,
"KeyName": "DPad Left"
},
{
"KeyID": 24,
"KeyName": "DPad Down"
},
{
"KeyID": 25,
"KeyName": "Lower Button"
}
]
}
]
}

View File

@ -1,153 +0,0 @@
package orbweaver
import (
"encoding/binary"
"io"
"os"
"github.com/OrbTools/OrbCommon/gui"
)
//BINDING Map of Default Keys
var BINDING = [...]byte{41, 2, 3, 4, 5, 15, 16, 17, 18, 19, 58, 30, 31, 32, 33, 42, 44, 45, 46, 47, 56, 103, 106, 108, 105, 57}
//GUI gui definition for an orbweaver
var GUI = &gui.GUI{
Pages: []*gui.Page{
{
Hive: "MIP",
Name: "Grid",
Type: gui.PGrid,
Keys: []*gui.Key{
{
KeyID: 0,
KeyName: "01",
}, {
KeyID: 1,
KeyName: "02",
}, {
KeyID: 2,
KeyName: "03",
}, {
KeyID: 3,
KeyName: "04",
}, {
KeyID: 4,
KeyName: "05",
}, {
KeyID: 5,
KeyName: "06",
}, {
KeyID: 6,
KeyName: "07",
}, {
KeyID: 7,
KeyName: "08",
}, {
KeyID: 8,
KeyName: "09",
}, {
KeyID: 9,
KeyName: "10",
}, {
KeyID: 10,
KeyName: "11",
}, {
KeyID: 11,
KeyName: "12",
}, {
KeyID: 12,
KeyName: "13",
}, {
KeyID: 13,
KeyName: "14",
}, {
KeyID: 14,
KeyName: "15",
}, {
KeyID: 15,
KeyName: "16",
}, {
KeyID: 16,
KeyName: "17",
}, {
KeyID: 17,
KeyName: "18",
}, {
KeyID: 18,
KeyName: "19",
}, {
KeyID: 19,
KeyName: "20",
},
},
}, {
Hive: "SIP",
Name: "Side Keys",
Type: gui.PList,
Keys: []*gui.Key{
{
KeyID: 0,
KeyName: "Upper Button",
}, {
KeyID: 1,
KeyName: "DPad Up",
}, {
KeyID: 2,
KeyName: "DPad Right",
}, {
KeyID: 3,
KeyName: "DPad Left",
}, {
KeyID: 4,
KeyName: "DPad Down",
}, {
KeyID: 5,
KeyName: "Lower Button",
},
},
},
},
}
//KeyMap singular keymap
type KeyMap struct {
Keymap [26]uint16
Color [3]byte
}
//KeyMaps a set of keymaps
type KeyMaps struct {
Maps [7]*KeyMap
Currentmap int
MCount int
}
//PKM format for altering the keymap
type PKM struct {
MIP [20]uint16
SIP [6]uint16
COL [3]byte
}
//LoadKM Load Orbmap KM structure
func LoadKM(file string) *KeyMap {
mapped := new(KeyMap)
of, _ := os.Open(file)
binary.Read(of, binary.LittleEndian, mapped)
return mapped
}
//SavePKMKeymap saves an orb after edit
func SavePKMKeymap(mapped interface{}, file io.WriteCloser) {
binary.Write(file, binary.LittleEndian, mapped)
file.Close()
}
//LoadPKMKeymap loads an orb for editing
func LoadPKMKeymap(file io.ReadCloser) interface{} {
mapped := new(PKM)
binary.Read(file, binary.LittleEndian, mapped)
file.Close()
return mapped
}

0
go.sum
View File

View File

@ -1,33 +0,0 @@
package gui
//PageType PGrid, PCircle or PList
type PageType int
const (
//PGrid Grid type (keypads)
PGrid PageType = iota
//PCircle type (joysticks)
PCircle
//PList List Type
PList
)
//GUI a GUI tree
type GUI struct {
Pages []*Page
}
//Page A page of a binding GUI
type Page struct {
Hive string
Name string
Keys []*Key
Type PageType
}
//Key a keybind
type Key struct {
KeyID int
KeyName string
Default uint16
}

File diff suppressed because one or more lines are too long