Modularization support

Should allow future devices to be easily added
main
Minizbot2012 3 years ago
parent 017340280e
commit 3f74942458
No known key found for this signature in database
GPG Key ID: 977C8ADE12361917

@ -0,0 +1,5 @@
package main
import (
_ "github.com/OrbTools/OrbMap/devices/orbweaver"
)

@ -3,34 +3,41 @@ package orbweaver
import (
"fmt"
"path/filepath"
"strings"
morb "github.com/OrbTools/OrbCommon/devices/orbweaver"
"github.com/OrbTools/OrbMap/registry"
)
var eventcodes []byte
var ecm map[uint16]int
func init() {
ecm = make(map[uint16]int)
type Orbweaver struct {
eventcodes []byte
ecm map[uint16]int
keymaps *morb.KeyMaps
}
//ProcOrbFiles processes orbs
func ProcOrbFiles(orbs string) *morb.KeyMaps {
keymaps := &morb.KeyMaps{Currentmap: 0}
//ProbcOrbFiles processes orbs
func (p Orbweaver) ProcOrbs(orbs []string) {
p.keymaps = &morb.KeyMaps{Currentmap: 0}
if len(orbs) > 0 {
for idx, orb := range strings.Split(orbs, ";") {
for idx, orb := range orbs {
abs, err := filepath.Abs(orb)
if err != nil {
panic(err)
}
fmt.Println("Loading Orb " + abs)
KMap := morb.LoadKM(abs)
keymaps.Maps[idx] = KMap
p.keymaps.Maps[idx] = KMap
}
keymaps.MCount = len(orbs)
p.keymaps.MCount = len(orbs)
} else {
panic("No orbs")
}
return keymaps
p.ecm = make(map[uint16]int)
p.eventcodes = morb.BINDING[:]
for i := 0; i < len(p.eventcodes); i++ {
p.ecm[uint16(p.eventcodes[i])] = i
}
}
func init() {
registry.Systems["orbweaver"] = registry.Device(&Orbweaver{})
}

@ -7,17 +7,12 @@ import (
"encoding/binary"
"unsafe"
morb "github.com/OrbTools/OrbCommon/devices/orbweaver"
"github.com/OrbTools/OrbMap/keyevents"
evdev "github.com/gvalkov/golang-evdev"
)
//OrbLoop Main loop for this device
func OrbLoop(km *morb.KeyMaps, KeyBus chan *keyevents.KeyEvent) {
eventcodes = morb.BINDING[:]
for i := 0; i < len(eventcodes); i++ {
ecm[uint16(eventcodes[i])] = i
}
func (p Orbweaver) OrbLoop(KeyBus chan *keyevents.KeyEvent) {
println("UnixLoop starting")
f, err := evdev.Open("/dev/input/by-id/usb-Razer_Razer_Orbweaver_Chroma-event-kbd")
if err != nil {
@ -30,7 +25,7 @@ func OrbLoop(km *morb.KeyMaps, KeyBus chan *keyevents.KeyEvent) {
f.File.Read(b)
KeyEv := &keyevents.KeyEvent{}
binary.Read(bytes.NewBuffer(b), binary.LittleEndian, KeyEv)
KeyEv.Code = km.Maps[km.Currentmap].Keymap[ecm[KeyEv.Code]]
KeyEv.Code = p.keymaps.Maps[p.keymaps.Currentmap].Keymap[p.ecm[KeyEv.Code]]
if KeyEv.Code != 0 && KeyEv.Type != 4 {
KeyBus <- KeyEv
}

@ -101,11 +101,7 @@ func (s *swapInt) Differ(s2 *swapInt) []byte {
}
//OrbLoop Main loop for this device
func OrbLoop(km *morb.KeyMaps, KeyBus chan *keyevents.KeyEvent) {
eventcodes = morb.BINDING[:]
for i := 0; i < len(eventcodes); i++ {
ecm[uint16(eventcodes[i])] = i
}
func (p Orbweaver) OrbLoop(KeyBus chan *keyevents.KeyEvent) {
fmt.Println("Windows Loop Init")
ctx := gousb.NewContext()
dev, err := ctx.OpenDeviceWithVIDPID(vendor, prod)
@ -146,7 +142,7 @@ func OrbLoop(km *morb.KeyMaps, KeyBus chan *keyevents.KeyEvent) {
for i := 0; i < len(dat); i++ {
if dat[i] != 0 {
dat[i] = byte(hid.GetLinuxFromHid(uint16(dat[i])))
dat[i] = byte(km.Maps[km.Currentmap].Keymap[ecm[uint16(dat[i])]])
dat[i] = byte(p.keymaps.Maps[p.keymaps.Currentmap].Keymap[p.ecm[uint16(dat[i])]])
dat[i] = byte(hid.GetHidFromLinux(uint16(dat[i])))
dat[i] = byte(hid.GetWindowsFromHid(uint16(dat[i])))
}

@ -0,0 +1,19 @@
package main
import (
"io/ioutil"
"os"
)
func main() {
out, _ := os.Create("boot.go")
out.Write([]byte("package main\n\nimport (\n"))
files, _ := ioutil.ReadDir("./devices/")
BasePkg := "github.com/OrbTools/OrbMap/devices/"
for _, fil := range files {
if fil.IsDir() {
out.Write([]byte("\t_ \"" + BasePkg + fil.Name() + "\"\n"))
}
}
out.Write([]byte(")"))
}

@ -3,17 +3,26 @@ package main
import (
"flag"
"strings"
"github.com/OrbTools/OrbMap/devices/orbweaver"
"github.com/OrbTools/OrbMap/emu"
"github.com/OrbTools/OrbMap/keyevents"
"github.com/OrbTools/OrbMap/registry"
)
//go:generate go run generators/devices.go
func main() {
orbs := flag.String("orbweaver", "", "Comma seperated string of orbs for the orbweaver")
str := make(map[string]*string)
for d := range registry.Systems {
str[d] = flag.String(d, "", "Comma seperated list of orb files for "+d)
}
flag.Parse()
KeyBus := make(chan *keyevents.KeyEvent, 128)
Maps := orbweaver.ProcOrbFiles(*orbs)
go orbweaver.OrbLoop(Maps, KeyBus)
for sys, orbs := range str {
if len(*orbs) > 0 {
registry.Systems[sys].ProcOrbs(strings.Split(*orbs, ","))
go registry.Systems[sys].OrbLoop(KeyBus)
}
}
emu.ProcKey(KeyBus)
}

@ -0,0 +1,18 @@
package registry
import (
"github.com/OrbTools/OrbMap/keyevents"
)
var (
Systems map[string]Device
)
type Device interface {
OrbLoop(chan *keyevents.KeyEvent)
ProcOrbs([]string)
}
func init() {
Systems = make(map[string]Device)
}
Loading…
Cancel
Save