diff --git a/Makefile b/Makefile index 40509c73..8b525719 100755 --- a/Makefile +++ b/Makefile @@ -32,7 +32,7 @@ JESSIE_GO_TAGS := gtk_3_14 # Build information #GIT_COMMIT = $(shell git rev-parse HEAD | cut -c1-7) -VERSION := 2.7.0 +VERSION := 2.7.1 BUILD_DATE ?= $(shell date --utc +%Y%m%d-%H:%M:%S) #BRANCH = $(shell git rev-parse --abbrev-ref HEAD) diff --git a/README.md b/README.md index 3b0c3bab..a42476d1 100755 --- a/README.md +++ b/README.md @@ -83,15 +83,15 @@ There are two ways to install OctoScreen: the recommended and supported way is t For example, to install on a new RaspberryPi with OctoPi: ```sh -wget https://github.com/Z-Bolt/OctoScreen/releases/download/2.6.1/octoscreen_2.6.1_armhf.deb -sudo dpkg -i octoscreen_2.6.1_armhf.deb +wget https://github.com/Z-Bolt/OctoScreen/releases/download/v2.7.1/octoscreen_2.7.1_armhf.deb +sudo dpkg -i octoscreen_2.7.1_armhf.deb ``` Or to update an existing version of OctoScreen: ```sh -wget https://github.com/Z-Bolt/OctoScreen/releases/download/2.6.1/octoscreen_2.6.1_armhf.deb +wget https://github.com/Z-Bolt/OctoScreen/releases/download/v2.7.1/octoscreen_2.7.1_armhf.deb sudo dpkg -r octoscreen -sudo dpkg -i octoscreen_2.6.1_armhf.deb +sudo dpkg -i octoscreen_2.7.1_armhf.deb sudo reboot now ``` diff --git a/octoprintApis/client.go b/octoprintApis/client.go index 9fed9455..9e29ef64 100755 --- a/octoprintApis/client.go +++ b/octoprintApis/client.go @@ -81,10 +81,13 @@ func (this *Client) doRequest( ) ([]byte, error) { logger.TraceEnter("Client.doRequest()") logger.Debugf("method: %s", method) - logger.Debugf("target: %s",target) + logger.Debugf("target: %s", target) + logger.Debugf("contentType: %s", contentType) + url := joinUrl(this.Endpoint, target) + logger.Debugf("url: %s", url) - req, err := http.NewRequest(method, joinUrl(this.Endpoint, target), body) + req, err := http.NewRequest(method, url, body) if err != nil { logger.LogError("Client.doRequest()", "http.NewRequest()", err) logger.TraceLeave("Client.doRequest()") @@ -93,12 +96,19 @@ func (this *Client) doRequest( req.Header.Add("Host", "localhost:5000") req.Header.Add("Accept", "*/*") - req.Header.Add("User-Agent", fmt.Sprintf("go-octoprint/%s", Version)) + + userAgent := fmt.Sprintf("go-octoprint/%s", Version) + logger.Debugf("userAgent: %s", userAgent) + req.Header.Add("User-Agent", userAgent) + if contentType != "" { req.Header.Add("Content-Type", contentType) } + // Don't log APIKey due to privacy & security. + // logger.Debugf("API key: %s", this.APIKey) req.Header.Add("X-Api-Key", this.APIKey) + resp, err := this.httpClient.Do(req) if err != nil { logger.LogError("Client.doRequest()", "this.httpClient.Do()", err) diff --git a/ui/CommonPanel.go b/ui/CommonPanel.go index 0dd2a122..95815c0e 100755 --- a/ui/CommonPanel.go +++ b/ui/CommonPanel.go @@ -16,7 +16,7 @@ import ( ) // OctoScreenVersion - set at compilation time. -var OctoScreenVersion = "2.7.0" +var OctoScreenVersion = "2.7.1" type CommonPanel struct { UI *UI diff --git a/ui/HttpRequestTestWindow.go b/ui/HttpRequestTestWindow.go index e4bc00ba..2fb30845 100755 --- a/ui/HttpRequestTestWindow.go +++ b/ui/HttpRequestTestWindow.go @@ -135,7 +135,7 @@ func (this *HttpRequestTestWindow) sdNotify(state string) { _, err := daemon.SdNotify(false, state) if err != nil { - logger.Errorf("sdNotify()", "SdNotify()", err) + logger.LogError("sdNotify()", "daemon.SdNotify()", err) logger.TraceLeave("sdNotify()") return } diff --git a/ui/ui.go b/ui/ui.go index 0276fc6f..a60be6ee 100755 --- a/ui/ui.go +++ b/ui/ui.go @@ -164,13 +164,17 @@ func (this *UI) verifyConnection() { logger.Debug("ui.verifyConnection() - ConnectionRequest.Do() succeeded") jsonResponse, err := utils.StructToJson(connectionResponse) if err != nil { - logger.Debug("ui.verifyConnection() - utils.StructToJson() failed") + logger.LogError("ui.verifyConnection()", "utils.StructToJson()", err) } else { logger.Debugf("ui.verifyConnection() - connectionResponse is: %s", jsonResponse) } this.ConnectionState = connectionResponse.Current.State newUIState, splashMessage = this.getUiStateAndMessageFromConnectionResponse(connectionResponse, newUIState, splashMessage) + + if this.Settings == nil { + this.loadSettings() + } } else { logger.LogError("ui.verifyConnection()", "Broke into the else condition because Do(ConnectionRequest) returned an error", err) newUIState, splashMessage = this.getUiStateAndMessageFromError(err, newUIState, splashMessage) @@ -341,6 +345,12 @@ func (this *UI) checkNotification() { func (this *UI) loadSettings() { logger.TraceEnter("ui.loadSettings()") + if this.Settings != nil { + logger.Error("ui.loadSettings() - this.Settings has already been set") + logger.TraceLeave("ui.loadSettings()") + return + } + settingsResponse, err := (&octoprintApis.OctoScreenSettingsRequest{}).Do(this.Client, this.UIState) if err != nil { text := err.Error() @@ -355,19 +365,26 @@ func (this *UI) loadSettings() { } this.OctoPrintPluginIsAvailable = false - - logger.TraceLeave("ui.loadSettings()") - return + // Use default settings + this.Settings = &dataModels.OctoScreenSettingsResponse { + FilamentInLength: 100, + FilamentOutLength: 100, + ToolChanger: false, + XAxisInverted: false, + YAxisInverted: false, + ZAxisInverted: false, + MenuStructure: nil, + } } else { logger.Info("The call to GetSettings succeeded and the OctoPrint plug-in is available") this.OctoPrintPluginIsAvailable = true - } - if !this.validateMenuItems(settingsResponse.MenuStructure, "", true) { - settingsResponse.MenuStructure = nil - } + if !this.validateMenuItems(settingsResponse.MenuStructure, "", true) { + settingsResponse.MenuStructure = nil + } - this.Settings = settingsResponse + this.Settings = settingsResponse + } logger.TraceLeave("ui.loadSettings()") } @@ -425,7 +442,7 @@ func (this *UI) update() { logger.TraceEnter("ui.update()") this.sdNotify(daemon.SdNotifyWatchdog) - + if this.connectionAttempts > 8 { logger.Info("ui.update() - this.connectionAttempts > 8") this.splashPanel.putOnHold() @@ -442,28 +459,12 @@ func (this *UI) update() { this.connectionAttempts = 0 } - if this.Settings == nil { - this.loadSettings() - - if this.Settings == nil { - this.Settings = &dataModels.OctoScreenSettingsResponse { - FilamentInLength: 100, - FilamentOutLength: 100, - ToolChanger: false, - XAxisInverted: false, - YAxisInverted: false, - ZAxisInverted: false, - MenuStructure: nil, - } - } - } + this.verifyConnection() if this.OctoPrintPluginIsAvailable { this.checkNotification() } - this.verifyConnection() - logger.TraceLeave("ui.update()") } diff --git a/uiWidgets/SystemCommandButton.go b/uiWidgets/SystemCommandButton.go index 134a5d37..a1865a2c 100755 --- a/uiWidgets/SystemCommandButton.go +++ b/uiWidgets/SystemCommandButton.go @@ -51,7 +51,7 @@ func CreateSystemCommandButton( confirmationMessage := "" if len(cmd.Confirm) != 0 { - confirmationMessage = cmd.Confirm + confirmationMessage = fmt.Sprintf("%s\n\nDo you wish to proceed?", cmd.Confirm) } else if len(name) != 0 { confirmationMessage = fmt.Sprintf("Do you wish to %s?", name) } else { diff --git a/utils/filament.go b/utils/filament.go index a2145fc4..397dc329 100755 --- a/utils/filament.go +++ b/utils/filament.go @@ -32,28 +32,36 @@ func Extrude( return } - logger.Infof("filament.Extrude() - setting flow rate percentage of %d", flowRatePercentage) - if err := SetFlowRate(client, flowRatePercentage); err != nil { - logger.LogError("filament.Extrude()", "SetFlowRate()", err) + if err := SelectTool(client, extruderId); err != nil { // TODO: display error? return } - cmd := &octoprintApis.ToolExtrudeRequest{} - if isForward { - cmd.Amount = length - } else { - cmd.Amount = -length + if err := SetFlowRate(client, flowRatePercentage); err != nil { + // TODO: display error? + return } - logger.Infof("filament.Extrude() - sending extrude request with length of: %d", cmd.Amount) - if err := cmd.Do(client); err != nil { - logger.LogError("filament.Extrude()", "Do(ToolExtrudeRequest)", err) + if err := SendExtrudeRrequest(client, isForward, length); err != nil { // TODO: display error? - return } } +func SelectTool( + client *octoprintApis.Client, + extruderId string, +) error { + cmd := &octoprintApis.ToolSelectRequest{} + cmd.Tool = extruderId + + logger.Infof("filament.SelectTool() - changing tool to %s", cmd.Tool) + if err := cmd.Do(client); err != nil { + logger.LogError("filament.SelectTool()", "Go(ToolSelectRequest)", err) + return err + } + + return nil +} func SetFlowRate( client *octoprintApis.Client, @@ -70,3 +78,24 @@ func SetFlowRate( return nil } + +func SendExtrudeRrequest( + client *octoprintApis.Client, + isForward bool, + length int, +) error { + cmd := &octoprintApis.ToolExtrudeRequest{} + if isForward { + cmd.Amount = length + } else { + cmd.Amount = -length + } + + logger.Infof("filament.SendExtrudeRrequest() - sending extrude request with length of: %d", cmd.Amount) + if err := cmd.Do(client); err != nil { + logger.LogError("filament.Extrude()", "Do(ToolExtrudeRequest)", err) + return err + } + + return nil +}