Skip to content

Commit

Permalink
Merge pull request #286 from Z-Bolt/2.7.1-dev
Browse files Browse the repository at this point in the history
merge 2.7.1-dev into master
  • Loading branch information
JeffB42 committed Apr 3, 2021
2 parents 1f40974 + 2f67f64 commit 1cf8a70
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 50 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
16 changes: 13 additions & 3 deletions octoprintApis/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()")
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion ui/CommonPanel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ui/HttpRequestTestWindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
55 changes: 28 additions & 27 deletions ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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()")
}
Expand Down Expand Up @@ -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()
Expand All @@ -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()")
}

Expand Down
2 changes: 1 addition & 1 deletion uiWidgets/SystemCommandButton.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
53 changes: 41 additions & 12 deletions utils/filament.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}

0 comments on commit 1cf8a70

Please sign in to comment.