diff --git a/.gitignore b/.gitignore index 59ad4c4..408a58b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,6 @@ frontend/dist frontend/wailsjs */package-lock.json */package.json.md5 -*.exe \ No newline at end of file +*.exe +*.o +*.rc \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..4396ea7 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,63 @@ +{ + "files.associations": { + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "charconv": "cpp", + "chrono": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "compare": "cpp", + "concepts": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "ratio": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "format": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "new": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "semaphore": "cpp", + "span": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "thread": "cpp", + "typeinfo": "cpp", + "variant": "cpp" + } +} \ No newline at end of file diff --git a/app.go b/app.go index 64211c3..e99339e 100644 --- a/app.go +++ b/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() +} diff --git a/frontend/src/App.svelte b/frontend/src/App.svelte index 23b0f57..a554ef0 100644 --- a/frontend/src/App.svelte +++ b/frontend/src/App.svelte @@ -9,9 +9,28 @@ import Show from './components/Show/Show.svelte'; import GeneralConsole from './components/Console/GeneralConsole.svelte'; import RoundIconButton from './components/General/RoundIconButton.svelte'; - import { currentProject, needProjectSave } from './stores'; + import { currentProject, needProjectSave, peripherals } from './stores'; import { SaveProject } from '../wailsjs/go/main/App.js'; - import { construct_svelte_component } from 'svelte/internal'; + import { construct_svelte_component } from 'svelte/internal'; + import { EventsOn } from '../wailsjs/runtime' + import { GetPeripherals } from "../wailsjs/go/main/App"; + + // When the list of hardware changed, update the store + EventsOn('PERIPHERAL_ARRIVAL', function(peripheralInfo){ + console.log("Hardware has been added to the system"); + console.log(peripheralInfo) + $peripherals = [...$peripherals, peripheralInfo]; + }) + + EventsOn('PERIPHERAL_REMOVAL', function(peripheralInfo){ + console.log("Hardware has been removed from the system"); + console.log(peripheralInfo) + $peripherals = $peripherals.filter(item => JSON.stringify(item) !== JSON.stringify(peripheralInfo)) + console.log($peripherals) + + // $peripherals = devicesList + // console.log(devicesList) + }) let selectedMenu = "settings" // When the navigation menu changed, update the selected menu @@ -50,6 +69,9 @@ SaveFile: "", }); + // Request the list of peripherals + GetPeripherals() +
diff --git a/frontend/src/components/General/DropdownList.svelte b/frontend/src/components/General/DropdownList.svelte index 3df0136..3ab7c07 100644 --- a/frontend/src/components/General/DropdownList.svelte +++ b/frontend/src/components/General/DropdownList.svelte @@ -10,10 +10,18 @@ export let active = false; export let style = ''; + let tooltipPosition = {top: 0, left: 0} + // Show a tooltip on mouse hover let tooltipShowing = false - function toggleTooltip(){ - tooltipShowing = !tooltipShowing + let buttonRef + function toggleTooltip(active){ + const rect = buttonRef.getBoundingClientRect(); + tooltipPosition = { + top: rect.bottom + 5, // Ajouter une marge en bas + left: rect.left, // Centrer horizontalement + }; + tooltipShowing = active } // Emit a click event when the button is clicked @@ -39,13 +47,13 @@
- - +
{#each Array.from(choices) as [key, value]} diff --git a/frontend/src/components/General/InfoButton.svelte b/frontend/src/components/General/InfoButton.svelte index dcb4132..6ec350b 100644 --- a/frontend/src/components/General/InfoButton.svelte +++ b/frontend/src/components/General/InfoButton.svelte @@ -1,5 +1,6 @@
-
+ on:mouseenter={() => { toggleTooltip(true) }} + on:mouseleave={() => { toggleTooltip(false) }}>
{#if message} - + {/if}
@@ -50,7 +59,5 @@ align-items: center; padding: 0; } - - diff --git a/frontend/src/components/General/Input.svelte b/frontend/src/components/General/Input.svelte index bf9572f..d695018 100644 --- a/frontend/src/components/General/Input.svelte +++ b/frontend/src/components/General/Input.svelte @@ -23,13 +23,13 @@
-

{label}

+

{label}

{#if type === 'large'} -