Skip to content

Commit 1bdebed

Browse files
authored
fix: new config load (#46)
1 parent 3d4678a commit 1bdebed

3 files changed

Lines changed: 34 additions & 6 deletions

File tree

.vscode/launch.json

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,24 @@
1313
],
1414
"configurations": [
1515
{
16-
"name": "Launch Notecard CLI",
16+
"name": "Launch Notecard CLI (empty)",
17+
"type": "go",
18+
"request": "launch",
19+
"mode": "auto",
20+
"program": "${workspaceFolder}/notecard",
21+
"env": {
22+
"BLUES": ""
23+
}
24+
},
25+
{
26+
"name": "Launch Notecard CLI (with request)",
1727
"type": "go",
1828
"request": "launch",
1929
"mode": "auto",
2030
"program": "${workspaceFolder}/notecard",
2131
"args": ["-req", "${input:requestJson}"],
2232
"env": {
23-
"BLUES": "abucknall@blues.com"
33+
"BLUES": ""
2434
}
2535
},
2636
{
@@ -29,7 +39,10 @@
2939
"request": "launch",
3040
"mode": "auto",
3141
"program": "${workspaceFolder}/notehub",
32-
"args": ["-req", "${input:requestJson}"]
42+
"args": ["-req", "${input:requestJson}"],
43+
"env": {
44+
"BLUES": ""
45+
}
3346
}
3447
]
3548
}

lib/config.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"time"
1616

1717
"github.com/blues/note-go/note"
18+
"github.com/blues/note-go/notecard"
1819
"github.com/blues/note-go/notehub"
1920
)
2021

@@ -56,7 +57,16 @@ func ConfigRead() error {
5657
// Read the config file
5758
contents, err := os.ReadFile(configSettingsPath())
5859
if os.IsNotExist(err) {
59-
ConfigReset()
60+
// If no interface has been provided and no saved config, set defaults
61+
if Config.Interface == "" {
62+
ConfigReset()
63+
newConfigPort := Config.IPort[Config.Interface]
64+
Config.Interface, newConfigPort.Port, newConfigPort.PortConfig = notecard.Defaults()
65+
Config.IPort[Config.Interface] = newConfigPort
66+
ConfigWrite()
67+
} else {
68+
ConfigReset()
69+
}
6070
err = nil
6171
} else if err == nil {
6272
err = note.JSONUnmarshal(contents, &Config)

notecard/main.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,12 @@ func main() {
261261
fmt.Printf("Ports on '%s':\n", nInterface)
262262
for _, port := range ports {
263263
if port == nPort {
264-
fmt.Printf(" %s ***\n", port)
264+
nPortConfig := lib.Config.IPort[lib.Config.Interface].PortConfig
265+
if nPortConfig == 0 {
266+
fmt.Printf(" %s ***\n", port)
267+
} else {
268+
fmt.Printf(" %s (%d) ***\n", port, nPortConfig)
269+
}
265270
} else {
266271
fmt.Printf(" %s\n", port)
267272
}
@@ -300,7 +305,7 @@ func main() {
300305
// Process non-config commands
301306
var rsp notecard.Request
302307

303-
// The timouts in the note-go library are set under the assumption that
308+
// The timeouts in the note-go library are set under the assumption that
304309
// the device is connected with long header wires that have significant
305310
// capacitance and resistance, and where there may be arbitrary activity
306311
// on the Notecard. This switch uses a larger buffer and shorter inter-segment

0 commit comments

Comments
 (0)