generated from thinkode/modelRepository
fixed tooltip
This commit is contained in:
54
app.go
54
app.go
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"changeme/hardware"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -8,6 +9,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
|
||||
@@ -22,18 +24,38 @@ const (
|
||||
|
||||
// App struct
|
||||
type App struct {
|
||||
ctx context.Context
|
||||
ctx context.Context
|
||||
hardwareManager *hardware.HardwareManager // For managing all the hardware
|
||||
wmiMutex sync.Mutex // Avoid some WMI operations at the same time
|
||||
// FOR TESTING PURPOSE ONLY
|
||||
ftdi *hardware.FTDIPeripheral
|
||||
}
|
||||
|
||||
// NewApp creates a new App application struct
|
||||
func NewApp() *App {
|
||||
return &App{}
|
||||
// Create a new hadware manager
|
||||
hardwareManager := hardware.NewHardwareManager()
|
||||
hardwareManager.RegisterFinder(hardware.NewMIDIFinder())
|
||||
hardwareManager.RegisterFinder(hardware.NewFTDIFinder())
|
||||
return &App{
|
||||
hardwareManager: hardwareManager,
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
err := a.hardwareManager.Start(ctx)
|
||||
if err != nil {
|
||||
log.Fatalf("Unable to start the device manager: %s", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// GetPeripherals gets all the peripherals connected
|
||||
func (a *App) GetPeripherals() {
|
||||
a.hardwareManager.Scan(a.ctx)
|
||||
}
|
||||
|
||||
// GetProjects gets all the projects in the projects directory
|
||||
@@ -180,3 +202,31 @@ func copy(src, dst string) (int64, error) {
|
||||
nBytes, err := io.Copy(destination, source)
|
||||
return nBytes, err
|
||||
}
|
||||
|
||||
// FOR TESTING PURPOSE ONLY
|
||||
|
||||
func (a *App) ConnectFTDI() error {
|
||||
// Create a new FTDI object
|
||||
var err error
|
||||
a.ftdi, err = hardware.NewFTDIPeripheral("FTDI TEST INTERFACE", "A50825I", 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return a.ftdi.Connect()
|
||||
}
|
||||
|
||||
func (a *App) ActivateFTDI() error {
|
||||
return a.ftdi.Activate()
|
||||
}
|
||||
|
||||
func (a *App) SetDeviceFTDI(channelValue byte) error {
|
||||
return a.ftdi.SetDeviceProperty(0, 0, channelValue)
|
||||
}
|
||||
|
||||
func (a *App) DeactivateFTDI() error {
|
||||
return a.ftdi.Deactivate()
|
||||
}
|
||||
|
||||
func (a *App) DisconnectFTDI() error {
|
||||
return a.ftdi.Disconnect()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user