Skip to content

Commit 1cf8a70

Browse files
authored
Merge pull request #286 from Z-Bolt/2.7.1-dev
merge 2.7.1-dev into master
2 parents 1f40974 + 2f67f64 commit 1cf8a70

File tree

8 files changed

+90
-50
lines changed

8 files changed

+90
-50
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ JESSIE_GO_TAGS := gtk_3_14
3232

3333
# Build information
3434
#GIT_COMMIT = $(shell git rev-parse HEAD | cut -c1-7)
35-
VERSION := 2.7.0
35+
VERSION := 2.7.1
3636
BUILD_DATE ?= $(shell date --utc +%Y%m%d-%H:%M:%S)
3737
#BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
3838

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ There are two ways to install OctoScreen: the recommended and supported way is t
8383

8484
For example, to install on a new RaspberryPi with OctoPi:
8585
```sh
86-
wget https://github.com/Z-Bolt/OctoScreen/releases/download/2.6.1/octoscreen_2.6.1_armhf.deb
87-
sudo dpkg -i octoscreen_2.6.1_armhf.deb
86+
wget https://github.com/Z-Bolt/OctoScreen/releases/download/v2.7.1/octoscreen_2.7.1_armhf.deb
87+
sudo dpkg -i octoscreen_2.7.1_armhf.deb
8888
```
8989

9090
Or to update an existing version of OctoScreen:
9191
```sh
92-
wget https://github.com/Z-Bolt/OctoScreen/releases/download/2.6.1/octoscreen_2.6.1_armhf.deb
92+
wget https://github.com/Z-Bolt/OctoScreen/releases/download/v2.7.1/octoscreen_2.7.1_armhf.deb
9393
sudo dpkg -r octoscreen
94-
sudo dpkg -i octoscreen_2.6.1_armhf.deb
94+
sudo dpkg -i octoscreen_2.7.1_armhf.deb
9595
sudo reboot now
9696
```
9797

octoprintApis/client.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,13 @@ func (this *Client) doRequest(
8181
) ([]byte, error) {
8282
logger.TraceEnter("Client.doRequest()")
8383
logger.Debugf("method: %s", method)
84-
logger.Debugf("target: %s",target)
84+
logger.Debugf("target: %s", target)
85+
logger.Debugf("contentType: %s", contentType)
8586

87+
url := joinUrl(this.Endpoint, target)
88+
logger.Debugf("url: %s", url)
8689

87-
req, err := http.NewRequest(method, joinUrl(this.Endpoint, target), body)
90+
req, err := http.NewRequest(method, url, body)
8891
if err != nil {
8992
logger.LogError("Client.doRequest()", "http.NewRequest()", err)
9093
logger.TraceLeave("Client.doRequest()")
@@ -93,12 +96,19 @@ func (this *Client) doRequest(
9396

9497
req.Header.Add("Host", "localhost:5000")
9598
req.Header.Add("Accept", "*/*")
96-
req.Header.Add("User-Agent", fmt.Sprintf("go-octoprint/%s", Version))
99+
100+
userAgent := fmt.Sprintf("go-octoprint/%s", Version)
101+
logger.Debugf("userAgent: %s", userAgent)
102+
req.Header.Add("User-Agent", userAgent)
103+
97104
if contentType != "" {
98105
req.Header.Add("Content-Type", contentType)
99106
}
100107

108+
// Don't log APIKey due to privacy & security.
109+
// logger.Debugf("API key: %s", this.APIKey)
101110
req.Header.Add("X-Api-Key", this.APIKey)
111+
102112
resp, err := this.httpClient.Do(req)
103113
if err != nil {
104114
logger.LogError("Client.doRequest()", "this.httpClient.Do()", err)

ui/CommonPanel.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
)
1717

1818
// OctoScreenVersion - set at compilation time.
19-
var OctoScreenVersion = "2.7.0"
19+
var OctoScreenVersion = "2.7.1"
2020

2121
type CommonPanel struct {
2222
UI *UI

ui/HttpRequestTestWindow.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func (this *HttpRequestTestWindow) sdNotify(state string) {
135135

136136
_, err := daemon.SdNotify(false, state)
137137
if err != nil {
138-
logger.Errorf("sdNotify()", "SdNotify()", err)
138+
logger.LogError("sdNotify()", "daemon.SdNotify()", err)
139139
logger.TraceLeave("sdNotify()")
140140
return
141141
}

ui/ui.go

+28-27
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,17 @@ func (this *UI) verifyConnection() {
164164
logger.Debug("ui.verifyConnection() - ConnectionRequest.Do() succeeded")
165165
jsonResponse, err := utils.StructToJson(connectionResponse)
166166
if err != nil {
167-
logger.Debug("ui.verifyConnection() - utils.StructToJson() failed")
167+
logger.LogError("ui.verifyConnection()", "utils.StructToJson()", err)
168168
} else {
169169
logger.Debugf("ui.verifyConnection() - connectionResponse is: %s", jsonResponse)
170170
}
171171

172172
this.ConnectionState = connectionResponse.Current.State
173173
newUIState, splashMessage = this.getUiStateAndMessageFromConnectionResponse(connectionResponse, newUIState, splashMessage)
174+
175+
if this.Settings == nil {
176+
this.loadSettings()
177+
}
174178
} else {
175179
logger.LogError("ui.verifyConnection()", "Broke into the else condition because Do(ConnectionRequest) returned an error", err)
176180
newUIState, splashMessage = this.getUiStateAndMessageFromError(err, newUIState, splashMessage)
@@ -341,6 +345,12 @@ func (this *UI) checkNotification() {
341345
func (this *UI) loadSettings() {
342346
logger.TraceEnter("ui.loadSettings()")
343347

348+
if this.Settings != nil {
349+
logger.Error("ui.loadSettings() - this.Settings has already been set")
350+
logger.TraceLeave("ui.loadSettings()")
351+
return
352+
}
353+
344354
settingsResponse, err := (&octoprintApis.OctoScreenSettingsRequest{}).Do(this.Client, this.UIState)
345355
if err != nil {
346356
text := err.Error()
@@ -355,19 +365,26 @@ func (this *UI) loadSettings() {
355365
}
356366

357367
this.OctoPrintPluginIsAvailable = false
358-
359-
logger.TraceLeave("ui.loadSettings()")
360-
return
368+
// Use default settings
369+
this.Settings = &dataModels.OctoScreenSettingsResponse {
370+
FilamentInLength: 100,
371+
FilamentOutLength: 100,
372+
ToolChanger: false,
373+
XAxisInverted: false,
374+
YAxisInverted: false,
375+
ZAxisInverted: false,
376+
MenuStructure: nil,
377+
}
361378
} else {
362379
logger.Info("The call to GetSettings succeeded and the OctoPrint plug-in is available")
363380
this.OctoPrintPluginIsAvailable = true
364-
}
365381

366-
if !this.validateMenuItems(settingsResponse.MenuStructure, "", true) {
367-
settingsResponse.MenuStructure = nil
368-
}
382+
if !this.validateMenuItems(settingsResponse.MenuStructure, "", true) {
383+
settingsResponse.MenuStructure = nil
384+
}
369385

370-
this.Settings = settingsResponse
386+
this.Settings = settingsResponse
387+
}
371388

372389
logger.TraceLeave("ui.loadSettings()")
373390
}
@@ -425,7 +442,7 @@ func (this *UI) update() {
425442
logger.TraceEnter("ui.update()")
426443

427444
this.sdNotify(daemon.SdNotifyWatchdog)
428-
445+
429446
if this.connectionAttempts > 8 {
430447
logger.Info("ui.update() - this.connectionAttempts > 8")
431448
this.splashPanel.putOnHold()
@@ -442,28 +459,12 @@ func (this *UI) update() {
442459
this.connectionAttempts = 0
443460
}
444461

445-
if this.Settings == nil {
446-
this.loadSettings()
447-
448-
if this.Settings == nil {
449-
this.Settings = &dataModels.OctoScreenSettingsResponse {
450-
FilamentInLength: 100,
451-
FilamentOutLength: 100,
452-
ToolChanger: false,
453-
XAxisInverted: false,
454-
YAxisInverted: false,
455-
ZAxisInverted: false,
456-
MenuStructure: nil,
457-
}
458-
}
459-
}
462+
this.verifyConnection()
460463

461464
if this.OctoPrintPluginIsAvailable {
462465
this.checkNotification()
463466
}
464467

465-
this.verifyConnection()
466-
467468
logger.TraceLeave("ui.update()")
468469
}
469470

uiWidgets/SystemCommandButton.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func CreateSystemCommandButton(
5151

5252
confirmationMessage := ""
5353
if len(cmd.Confirm) != 0 {
54-
confirmationMessage = cmd.Confirm
54+
confirmationMessage = fmt.Sprintf("%s\n\nDo you wish to proceed?", cmd.Confirm)
5555
} else if len(name) != 0 {
5656
confirmationMessage = fmt.Sprintf("Do you wish to %s?", name)
5757
} else {

utils/filament.go

+41-12
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,36 @@ func Extrude(
3232
return
3333
}
3434

35-
logger.Infof("filament.Extrude() - setting flow rate percentage of %d", flowRatePercentage)
36-
if err := SetFlowRate(client, flowRatePercentage); err != nil {
37-
logger.LogError("filament.Extrude()", "SetFlowRate()", err)
35+
if err := SelectTool(client, extruderId); err != nil {
3836
// TODO: display error?
3937
return
4038
}
4139

42-
cmd := &octoprintApis.ToolExtrudeRequest{}
43-
if isForward {
44-
cmd.Amount = length
45-
} else {
46-
cmd.Amount = -length
40+
if err := SetFlowRate(client, flowRatePercentage); err != nil {
41+
// TODO: display error?
42+
return
4743
}
4844

49-
logger.Infof("filament.Extrude() - sending extrude request with length of: %d", cmd.Amount)
50-
if err := cmd.Do(client); err != nil {
51-
logger.LogError("filament.Extrude()", "Do(ToolExtrudeRequest)", err)
45+
if err := SendExtrudeRrequest(client, isForward, length); err != nil {
5246
// TODO: display error?
53-
return
5447
}
5548
}
5649

50+
func SelectTool(
51+
client *octoprintApis.Client,
52+
extruderId string,
53+
) error {
54+
cmd := &octoprintApis.ToolSelectRequest{}
55+
cmd.Tool = extruderId
56+
57+
logger.Infof("filament.SelectTool() - changing tool to %s", cmd.Tool)
58+
if err := cmd.Do(client); err != nil {
59+
logger.LogError("filament.SelectTool()", "Go(ToolSelectRequest)", err)
60+
return err
61+
}
62+
63+
return nil
64+
}
5765

5866
func SetFlowRate(
5967
client *octoprintApis.Client,
@@ -70,3 +78,24 @@ func SetFlowRate(
7078

7179
return nil
7280
}
81+
82+
func SendExtrudeRrequest(
83+
client *octoprintApis.Client,
84+
isForward bool,
85+
length int,
86+
) error {
87+
cmd := &octoprintApis.ToolExtrudeRequest{}
88+
if isForward {
89+
cmd.Amount = length
90+
} else {
91+
cmd.Amount = -length
92+
}
93+
94+
logger.Infof("filament.SendExtrudeRrequest() - sending extrude request with length of: %d", cmd.Amount)
95+
if err := cmd.Do(client); err != nil {
96+
logger.LogError("filament.Extrude()", "Do(ToolExtrudeRequest)", err)
97+
return err
98+
}
99+
100+
return nil
101+
}

0 commit comments

Comments
 (0)