-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
78 lines (73 loc) · 2.07 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*******************************************************************************
* Audio Morse Decoder 'CW4ISR' (forked from Project ZyLO since 2023 July 15th)
* Released under the MIT License (or GPL v3 until 2021 Oct 28th) (see LICENSE)
* Univ. Tokyo Amateur Radio Club Development Task Force (https://nextzlog.dev)
*******************************************************************************/
package main
import (
"fmt"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/theme"
"github.com/dop251/goja"
"github.com/gen2brain/malgo"
"github.com/nextzlog/cw4i/core"
"github.com/nextzlog/cw4i/util"
"github.com/nextzlog/cw4i/view"
"os"
)
const (
DEV = "dev"
SQL = "sql"
)
func main() {
app := app.NewWithID("cw4i")
cfg := malgo.ContextConfig{}
app.Settings().SetTheme(theme.DarkTheme())
ctx, _ := malgo.InitContext(nil, cfg, nil)
win := app.NewWindow("CW4ISR Morse Decoder")
decoder := view.Decoder{
Initial: Script,
}
capture := view.Capture{
Context: ctx.Context,
Restart: decoder.Update,
Handler: decoder.Decode,
Initial: app.Preferences().String(DEV),
}
squelch := view.Squelch{
Handler: decoder.Resquelch,
Initial: app.Preferences().Float(SQL),
}
restart := view.Restart{
Handler: decoder.Restart,
}
sel := capture.CanvasObject()
his := decoder.CanvasObject()
sql := squelch.CanvasObject()
btn := restart.CanvasObject()
bar := container.NewBorder(nil, nil, nil, btn, sql)
out := container.NewBorder(sel, bar, nil, nil, his)
win.Resize(fyne.NewSize(640, 480))
win.SetContent(out)
win.ShowAndRun()
ctx.Uninit()
app.Preferences().SetFloat(SQL, sql.Value)
app.Preferences().SetString(DEV, sel.Selected)
return
}
func Script(rate int) (decoder core.Decoder, err error) {
decoder = core.DefaultDecoder(rate)
vm := goja.New()
vm.Set("call", util.Call)
vm.Set("plot", util.Plot)
vm.Set("decoder", decoder)
vm.Set("printf", fmt.Printf)
vm.Set("sprintf", fmt.Sprintf)
code, _ := os.ReadFile("cw4i.js")
if _, err = vm.RunString(string(code)); err == nil {
err = vm.ExportTo(vm.Get("decoder"), &decoder)
}
return
}