Skip to content

Migrate to nugafile dumps format #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/quality-assurance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
- name: Check code style with revive
uses: docker://morphy/revive-action:v2
with:
exclude: "./examples/..."
config: revive.toml
path: "./..."
test:
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ GOLANGCI_LINT_VERSION = v1.56.2
REVIVE_VERSION = v1.3.7
GIT_CHGLOG_VERSION = v0.15.4
GO_BIN_PATH := $(shell go env GOPATH)/bin
TEST_MODULES := $(shell go list ./... | grep -v /cmd/)
TEST_MODULES := $(shell go list ./... | grep -v /examples/)

define build_app
cd "cmd/$1"; go build -o "../../build/nuga-$1"
cd "examples/$1"; go build -o "../../build/nuga-$1"
endef

.PHONY: setup
Expand All @@ -18,8 +18,8 @@ setup:

.PHONY: lint
lint:
golangci-lint run ./...
revive -config ./revive.toml ./...
golangci-lint run --skip-dirs ./examples ./...
revive -exclude ./examples/... -config ./revive.toml ./...

.PHONY: test
test:
Expand Down
71 changes: 0 additions & 71 deletions cmd/dump/main.go

This file was deleted.

70 changes: 15 additions & 55 deletions dump/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,68 +3,28 @@ package dump

import (
"github.com/mishamyrt/nuga-lib/device"
"github.com/mishamyrt/nuga-lib/features/keys"
"github.com/mishamyrt/nuga-lib/features/light"
"github.com/mishamyrt/nuga-lib/features"
"github.com/mishamyrt/nuga-lib/hid"
"github.com/mishamyrt/nuga-lib/internal/slices"
)

// Collect device state
func Collect(h hid.Handler) (State, error) {
lightsState, err := collectLights(h)
func Collect(dev *hid.Device) (*State, error) {
model := device.Model(dev.Info.Model)
f := features.New(dev, model)
lights, err := f.Light.GetStateData()
if err != nil {
return State{}, err
return nil, err
}
keysState, err := collectKeys(h)
keys, err := f.Keys.GetStateData()
if err != nil {
return State{}, err
return nil, err
}
info := h.GetInfo()
return State{
Name: device.Model(info.Model),
Firmware: info.Firmware,
Lights: lightsState,
Keys: keysState,
return &State{
Model: model,
Firmware: dev.Info.Firmware,
Data: features.StateData{
Lights: lights,
Keys: keys,
},
}, nil
}

func collectLights(h hid.Handler) (light.State, error) {
var state light.State
var err error
lightsFeature := light.New(h, nil)
params, err := lightsFeature.GetRawEffects()
if err != nil {
return state, err
}
colors, err := lightsFeature.GetRawColors()
if err != nil {
return state, err
}
state.Params = slices.Cast[byte, int](params)
state.Colors = slices.Cast[byte, int](colors)
return state, nil
}

func collectKeys(h hid.Handler) (keys.State, error) {
var state keys.State
var err error
keysFeature := keys.New(h, nil)
state.Mac, err = keysFeature.GetMacCodes()
if err != nil {
return state, err
}
state.Win, err = keysFeature.GetWinCodes()
if err != nil {
return state, err
}
macros, err := keysFeature.GetMacros()
if err != nil {
return state, err
}
macrosData, err := macros.Bytes()
if err != nil {
return state, err
}
state.Macros = macrosData
return state, nil
}
2 changes: 1 addition & 1 deletion dump/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var defaults embed.FS

// GetDefaults returns default state for given model
func GetDefaults(model device.Model) (*State, error) {
filePath := fmt.Sprintf("defaults/%v.json", string(model))
filePath := fmt.Sprintf("defaults/%v.nugafile", string(model))
data, err := defaults.ReadFile(filePath)
if err != nil {
return nil, err
Expand Down
1 change: 0 additions & 1 deletion dump/defaults/Halo65.json

This file was deleted.

Loading
Loading