Files
dmxconnect/app.go

84 lines
2.0 KiB
Go
Raw Normal View History

2023-08-25 20:33:11 +00:00
package main
import (
2024-12-15 13:45:46 +01:00
"changeme/hardware"
2023-08-25 20:33:11 +00:00
"context"
"fmt"
"io"
"log"
"os"
"strings"
2024-12-15 13:45:46 +01:00
"sync"
2023-08-25 20:33:11 +00:00
)
// App struct
type App struct {
2024-12-15 13:45:46 +01:00
ctx context.Context
hardwareManager *hardware.HardwareManager // For managing all the hardware
wmiMutex sync.Mutex // Avoid some WMI operations at the same time
2024-12-20 17:18:57 +01:00
projectInfo ProjectInfo // The project information structure
projectSave string // The file name of the project
2024-12-15 13:45:46 +01:00
// FOR TESTING PURPOSE ONLY
ftdi *hardware.FTDIPeripheral
2023-08-25 20:33:11 +00:00
}
// NewApp creates a new App application struct
func NewApp() *App {
2024-12-15 13:45:46 +01:00
// Create a new hadware manager
hardwareManager := hardware.NewHardwareManager()
2024-12-23 17:22:37 +01:00
hardwareManager.RegisterDriver(hardware.NewMIDIDriver())
hardwareManager.RegisterDriver(hardware.NewFTDIDriver())
hardwareManager.RegisterDriver(hardware.NewOS2LDriver())
2024-12-15 13:45:46 +01:00
return &App{
hardwareManager: hardwareManager,
2024-12-20 17:18:57 +01:00
projectSave: "",
2024-12-21 13:24:00 +01:00
projectInfo: ProjectInfo{
PeripheralsInfo: make(map[string]hardware.PeripheralInfo),
},
2024-12-15 13:45:46 +01:00
}
2023-08-25 20:33:11 +00:00
}
// startup is called when the app starts. The context is saved
// so we can call the runtime methods
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
2024-12-15 13:45:46 +01:00
err := a.hardwareManager.Start(ctx)
if err != nil {
log.Fatalf("Unable to start the device manager: %s", err)
return
}
}
func formatString(input string) string {
// Convertir en minuscules
lowerCaseString := strings.ToLower(input)
// Remplacer les espaces par des underscores
formattedString := strings.ReplaceAll(lowerCaseString, " ", "_")
return formattedString
}
func copy(src, dst string) (int64, error) {
sourceFileStat, err := os.Stat(src)
if err != nil {
return 0, err
}
if !sourceFileStat.Mode().IsRegular() {
return 0, fmt.Errorf("%s is not a regular file", src)
}
source, err := os.Open(src)
if err != nil {
return 0, err
}
defer source.Close()
destination, err := os.Create(dst)
if err != nil {
return 0, err
}
defer destination.Close()
nBytes, err := io.Copy(destination, source)
return nBytes, err
2023-08-25 20:33:11 +00:00
}