Skip to content

Commit 2484d55

Browse files
committed
test configs
1 parent 906c87e commit 2484d55

File tree

4 files changed

+72
-18
lines changed

4 files changed

+72
-18
lines changed

serial.go

+12-13
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"strings"
99
"time"
1010

11-
log "github.com/Sirupsen/logrus"
1211
"github.com/arduino/arduino-create-agent/upload"
1312
)
1413

@@ -68,17 +67,17 @@ var sh = serialhub{
6867

6968
func (sh *serialhub) run() {
7069

71-
log.Print("Inside run of serialhub")
70+
//log.Print("Inside run of serialhub")
7271
//cmdIdCtr := 0
7372

7473
for {
7574
select {
7675
case p := <-sh.register:
77-
log.Print("Registering a port: ", p.portConf.Name)
76+
//log.Print("Registering a port: ", p.portConf.Name)
7877
h.broadcastSys <- []byte("{\"Cmd\":\"Open\",\"Desc\":\"Got register/open on port.\",\"Port\":\"" + p.portConf.Name + "\",\"Baud\":" + strconv.Itoa(p.portConf.Baud) + ",\"BufferType\":\"" + p.BufferType + "\"}")
7978
sh.ports[p] = true
8079
case p := <-sh.unregister:
81-
log.Print("Unregistering a port: ", p.portConf.Name)
80+
//log.Print("Unregistering a port: ", p.portConf.Name)
8281
h.broadcastSys <- []byte("{\"Cmd\":\"Close\",\"Desc\":\"Got unregister/close on port.\",\"Port\":\"" + p.portConf.Name + "\",\"Baud\":" + strconv.Itoa(p.portConf.Baud) + "}")
8382
delete(sh.ports, p)
8483
close(p.sendBuffered)
@@ -92,10 +91,10 @@ func (sh *serialhub) run() {
9291

9392
func write(wr writeRequest, id string) {
9493
if wr.buffer {
95-
log.Println("Send was normal send, so sending to wr.p.sendBuffered")
94+
//log.Println("Send was normal send, so sending to wr.p.sendBuffered")
9695
wr.p.sendBuffered <- wr.d
9796
} else {
98-
log.Println("Send was sendnobuf, so sending to wr.p.sendNoBuf")
97+
//log.Println("Send was sendnobuf, so sending to wr.p.sendNoBuf")
9998
wr.p.sendNoBuf <- wr.d
10099
}
101100
}
@@ -110,7 +109,7 @@ func spList(network bool) {
110109
}
111110
ls, err := json.MarshalIndent(list, "", "\t")
112111
if err != nil {
113-
log.Println(err)
112+
//log.Println(err)
114113
h.broadcastSys <- []byte("Error creating json on port list " +
115114
err.Error())
116115
} else {
@@ -146,8 +145,8 @@ func spListDual(network bool) {
146145
// call our os specific implementation of getting the serial list
147146
list, err := GetList(network)
148147

149-
log.Println(list)
150-
log.Println(err)
148+
//log.Println(list)
149+
//log.Println(err)
151150

152151
if err != nil {
153152
// avoid reporting dummy data if an error occurred
@@ -223,7 +222,7 @@ func spListDual(network bool) {
223222
}
224223

225224
func spErr(err string) {
226-
log.Println("Sending err back: ", err)
225+
//log.Println("Sending err back: ", err)
227226
//h.broadcastSys <- []byte(err)
228227
h.broadcastSys <- []byte("{\"Error\" : \"" + err + "\"}")
229228
}
@@ -247,13 +246,13 @@ func spClose(portname string) {
247246

248247
func spWrite(arg string) {
249248
// we will get a string of comXX asdf asdf asdf
250-
log.Println("Inside spWrite arg: " + arg)
249+
//log.Println("Inside spWrite arg: " + arg)
251250
arg = strings.TrimPrefix(arg, " ")
252251
//log.Println("arg after trim: " + arg)
253252
args := strings.SplitN(arg, " ", 3)
254253
if len(args) != 3 {
255254
errstr := "Could not parse send command: " + arg
256-
log.Println(errstr)
255+
//log.Println(errstr)
257256
spErr(errstr)
258257
return
259258
}
@@ -280,7 +279,7 @@ func spWrite(arg string) {
280279
// we were just given a "send" so buffer it
281280
wr.buffer = true
282281
} else {
283-
log.Println("sendnobuf specified so wr.buffer is false")
282+
//log.Println("sendnobuf specified so wr.buffer is false")
284283
wr.buffer = false
285284
}
286285

trayicon.go

+55
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,17 @@
3131
package main
3232

3333
import (
34+
"flag"
35+
"os"
36+
"path/filepath"
3437
"runtime"
3538

3639
log "github.com/Sirupsen/logrus"
3740
"github.com/arduino/arduino-create-agent/icon"
3841
"github.com/getlantern/systray"
42+
"github.com/kardianos/osext"
3943
"github.com/skratchdot/open-golang/open"
44+
"github.com/vharitonsky/iniflags"
4045
"go.bug.st/serial.v1"
4146
)
4247

@@ -61,17 +66,67 @@ func addRebootTrayElement() {
6166
}()
6267
}
6368

69+
type ConfigIni struct {
70+
Name string
71+
Localtion string
72+
}
73+
74+
func getConfigs() []ConfigIni {
75+
// parse all configs in executable folder
76+
// config.ini must be there, so call it Default
77+
src, _ := osext.Executable()
78+
dest := filepath.Dir(src)
79+
80+
var configs []ConfigIni
81+
82+
filepath.Walk(dest, func(path string, f os.FileInfo, _ error) error {
83+
if !f.IsDir() {
84+
if filepath.Ext(path) == ".ini" {
85+
conf := ConfigIni{Name: f.Name(), Localtion: filepath.Join(dest, f.Name())}
86+
configs = append(configs, conf)
87+
}
88+
}
89+
return nil
90+
})
91+
return configs
92+
}
93+
6494
func setupSysTrayReal() {
6595

6696
systray.SetIcon(icon.GetIcon())
6797
mUrl := systray.AddMenuItem("Go to Arduino Create", "Arduino Create")
6898
mDebug := systray.AddMenuItem("Open debug console", "Debug console")
6999
menuVer := systray.AddMenuItem("Agent version "+version+"-"+git_revision, "")
70100
mPause := systray.AddMenuItem("Pause Plugin", "")
101+
var mConfigCheckbox []*systray.MenuItem
102+
103+
configs := getConfigs()
104+
105+
for _, config := range configs {
106+
log.Println("Adding " + config.Name)
107+
mConfigCheckbox = append(mConfigCheckbox, systray.AddMenuItem(config.Name, ""))
108+
}
71109
//mQuit := systray.AddMenuItem("Quit Plugin", "")
72110

73111
menuVer.Disable()
74112

113+
for i, _ := range mConfigCheckbox {
114+
go func(v int) {
115+
for {
116+
<-mConfigCheckbox[v].ClickedCh
117+
flag.Set("config", configs[v].Localtion)
118+
iniflags.UpdateConfig()
119+
mConfigCheckbox[v].SetTitle(" ✓ " + configs[v].Name)
120+
//mConfigCheckbox[v].Check()
121+
for j, _ := range mConfigCheckbox {
122+
if j != v {
123+
mConfigCheckbox[j].SetTitle(" " + configs[j].Name)
124+
}
125+
}
126+
}
127+
}(i)
128+
}
129+
75130
go func() {
76131
<-mPause.ClickedCh
77132
ports, _ := serial.GetPortsList()

vendor/github.com/oleksandr/bonjour/client.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/vharitonsky/iniflags/iniflags.go

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)