peripheral optimizations

This commit is contained in:
2025-01-04 00:36:29 +01:00
parent 556f24991e
commit e4392c8902
10 changed files with 408 additions and 342 deletions

33
app.go
View File

@@ -1,10 +1,11 @@
package main
import (
"changeme/hardware"
"context"
"dmxconnect/hardware"
"fmt"
"io"
"time"
"github.com/rs/zerolog/log"
@@ -16,6 +17,7 @@ import (
// App struct
type App struct {
ctx context.Context
cancelFunc context.CancelFunc
hardwareManager *hardware.HardwareManager // For managing all the hardware
wmiMutex sync.Mutex // Avoid some WMI operations at the same time
projectInfo ProjectInfo // The project information structure
@@ -26,9 +28,9 @@ type App struct {
func NewApp() *App {
// Create a new hadware manager
hardwareManager := hardware.NewHardwareManager()
hardwareManager.RegisterDriver(hardware.NewMIDIDriver())
hardwareManager.RegisterDriver(hardware.NewFTDIDriver())
hardwareManager.RegisterDriver(hardware.NewOS2LDriver())
hardwareManager.RegisterDriver(hardware.NewMIDIFinder(5 * time.Second))
hardwareManager.RegisterDriver(hardware.NewFTDIFinder(5 * time.Second))
// hardwareManager.RegisterDriver(hardware.NewOS2LDriver())
return &App{
hardwareManager: hardwareManager,
projectSave: "",
@@ -41,8 +43,8 @@ func NewApp() *App {
// startup is called when the app starts. The context is saved
// so we can call the runtime methods
func (a *App) onStartup(ctx context.Context) {
a.ctx = ctx
err := a.hardwareManager.Start(ctx)
a.ctx, a.cancelFunc = context.WithCancel(ctx)
err := a.hardwareManager.Start(a.ctx)
if err != nil {
log.Err(err).Str("file", "app").Msg("unable to start the hardware manager")
return
@@ -52,18 +54,25 @@ func (a *App) onStartup(ctx context.Context) {
// onReady is called when the DOM is ready
// We get the current peripherals connected
func (a *App) onReady(ctx context.Context) {
log.Debug().Str("file", "peripherals").Msg("getting peripherals...")
err := a.hardwareManager.Scan(a.ctx)
if err != nil {
log.Err(err).Str("file", "app").Msg("unable to get the peripherals")
}
// log.Debug().Str("file", "peripherals").Msg("getting peripherals...")
// err := a.hardwareManager.Scan()
// if err != nil {
// log.Err(err).Str("file", "app").Msg("unable to get the peripherals")
// }
return
}
// onShutdown is called when the app is closing
// We stop all the pending processes
func (a *App) onShutdown(ctx context.Context) {
log.Warn().Str("file", "app").Msg("app is closing")
// Close the application properly
log.Trace().Str("file", "app").Msg("app is closing")
// Explicitly close the context
a.cancelFunc()
err := a.hardwareManager.Stop()
if err != nil {
log.Err(err).Str("file", "app").Msg("unable to stop the hardware manager")
}
return
}