Skip to content

Commit

Permalink
Merge pull request #290 from Z-Bolt/2.7.2-dev
Browse files Browse the repository at this point in the history
2.7.2-dev into master
  • Loading branch information
JeffB42 authored Apr 10, 2021
2 parents 1cf8a70 + ecfc324 commit 5c7cb4f
Show file tree
Hide file tree
Showing 49 changed files with 203 additions and 117 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.1
VERSION := 2.7.2
BUILD_DATE ?= $(shell date --utc +%Y%m%d-%H:%M:%S)
#BRANCH = $(shell git rev-parse --abbrev-ref HEAD)

Expand Down
9 changes: 5 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/v2.7.1/octoscreen_2.7.1_armhf.deb
sudo dpkg -i octoscreen_2.7.1_armhf.deb
wget https://github.com/Z-Bolt/OctoScreen/releases/download/v2.7.2/octoscreen_2.7.2_armhf.deb
sudo dpkg -i octoscreen_2.7.2_armhf.deb
```

Or to update an existing version of OctoScreen:
```sh
wget https://github.com/Z-Bolt/OctoScreen/releases/download/v2.7.1/octoscreen_2.7.1_armhf.deb
wget https://github.com/Z-Bolt/OctoScreen/releases/download/v2.7.2/octoscreen_2.7.2_armhf.deb
sudo dpkg -r octoscreen
sudo dpkg -i octoscreen_2.7.1_armhf.deb
sudo dpkg -i octoscreen_2.7.2_armhf.deb
sudo reboot now
```

Expand Down Expand Up @@ -153,6 +153,7 @@ The basic configuration is handled via environment variables, if you are using t

- `OCTOSCREEN_RESOLUTION` - Resolution of the application, and should be configured to the resolution of your screen. Optimal resolution for OctoScreen is no less than 800x480, so if the physical resolution of your screen is 480x320, it's recommended to set the software resolution 800x533. If you are using Raspbian you can do it by changing [`hdmi_cvt`](https://www.raspberrypi.org/documentation/configuration/config-txt/video.md) param in `/boot/config.txt` file. Please see [Setting Up OctoScreen and Your Display](https://github.com/Z-Bolt/OctoScreen/wiki/Setting-Up-OctoScreen-and-Your-Display) and [Installing OctoScreen with a 3.5" 480x320 TFT screen](https://github.com/Z-Bolt/OctoScreen/wiki/Installing-OctoScreen-with-a-3.5%22-480x320-TFT-screen) for more information.

- `DISPLAY_CURSOR` - To display the cursor, add `DISPLAY_CURSOR=true` to your config file. In order to display the cursor, you will also need to edit `/lib/systemd/system/octoscreen.service` and remove `-nocursor`



Expand Down
5 changes: 5 additions & 0 deletions debian/local/octoscreen/config
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,8 @@ OCTOSCREEN_LOG_LEVEL=Error
OCTOSCREEN_RESOLUTION=800x480
# OCTOSCREEN_RESOLUTION is optional and defaults to 800x480 if missing
# (defined in globalVars.go)


# To display the cursor, uncomment the following line and set to true.
#DISPLAY_CURSOR=true
# You will also need to edit /lib/systemd/system/octoscreen.service and remove "-nocursor"
2 changes: 1 addition & 1 deletion debian/octoscreen.service
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ExecStart=/usr/bin/xinit /usr/bin/OctoScreen -- :0 -nolisten tcp -nocursor
ExecStartPost=/bin/bash /etc/octoscreen/disablescreenblank.sh 0
StandardOutput=journal
Restart=always
WatchdogSec=20s
WatchdogSec=40s

[Install]
WantedBy=graphical.target
Expand Down
51 changes: 51 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strconv"
"strings"

"github.com/gotk3/gotk3/gdk"
"github.com/gotk3/gotk3/gtk"
"github.com/sirupsen/logrus"

Expand Down Expand Up @@ -123,6 +124,8 @@ func main() {

utils.DumpEnvironmentVariables()

setCursor()

if initSucceeded != true {
// readConfig() logs any errors it encounters. Don't display
// the error here, because the error could be long, and we don't
Expand Down Expand Up @@ -368,3 +371,51 @@ func getSize() (width int, height int, err error) {
logger.TraceLeave("main.getSize()")
return
}

func setCursor() {
// For reference, see "How to turn on a pointer"
// https://github.com/Z-Bolt/OctoScreen/issues/285
// and "No mouse pointer when running xinit"
// https://www.raspberrypi.org/forums/viewtopic.php?t=139546

displayCursor := strings.ToLower(os.Getenv("DISPLAY_CURSOR"))
if displayCursor != "true" {
return
}

window, err := getRootWindow()
if err != nil {
return
}

cursor, err := getDefaultCursor()
if err != nil {
return
}

window.SetCursor(cursor)
}

func getRootWindow() (*gdk.Window, error) {
screen, err := gdk.ScreenGetDefault()
if err != nil {
return nil, err
}

window, err := screen.GetRootWindow()

return window, err
}

func getDefaultCursor() (*gdk.Cursor, error) {
display, err := gdk.DisplayGetDefault()
if err != nil {
return nil, err
}

// Examples of the different cursors can be found at
// https://developer.gnome.org/gdk3/stable/gdk3-Cursors.html#gdk-cursor-new-from-name
cursor, err := gdk.CursorNewFromName(display, "default")

return cursor, err
}
6 changes: 3 additions & 3 deletions octoprintApis/BedOffsetRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ type BedOffsetRequest struct {

// Do sends an API request and returns an error if any.
func (cmd *BedOffsetRequest) Do(c *Client) error {
b := bytes.NewBuffer(nil)
if err := cmd.encode(b); err != nil {
buffer := bytes.NewBuffer(nil)
if err := cmd.encode(buffer); err != nil {
return err
}

_, err := c.doJsonRequest("POST", PrinterToolApiUri, b, PrintToolErrors)
_, err := c.doJsonRequest("POST", PrinterToolApiUri, buffer, PrintToolErrors, true)
return err
}

Expand Down
8 changes: 4 additions & 4 deletions octoprintApis/BedStateRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ type BedStateRequest struct {
// Do sends an API request and returns the API response.
func (cmd *BedStateRequest) Do(c *Client) (*dataModels.TemperatureStateResponse, error) {
uri := fmt.Sprintf("%s?history=%t&limit=%d", PrinterBedApiUri, cmd.IncludeHistory, cmd.Limit)
b, err := c.doJsonRequest("GET", uri, nil, PrintBedErrors)
bytes, err := c.doJsonRequest("GET", uri, nil, PrintBedErrors, true)
if err != nil {
return nil, err
}

r := &dataModels.TemperatureStateResponse{}
if err := json.Unmarshal(b, &r); err != nil {
response := &dataModels.TemperatureStateResponse{}
if err := json.Unmarshal(bytes, &response); err != nil {
return nil, err
}

return r, err
return response, err
}
6 changes: 3 additions & 3 deletions octoprintApis/BedTargetRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ type BedTargetRequest struct {

// Do sends an API request and returns an error if any.
func (cmd *BedTargetRequest) Do(c *Client) error {
b := bytes.NewBuffer(nil)
if err := cmd.encode(b); err != nil {
buffer := bytes.NewBuffer(nil)
if err := cmd.encode(buffer); err != nil {
return err
}

_, err := c.doJsonRequest("POST", PrinterBedApiUri, b, PrintBedErrors)
_, err := c.doJsonRequest("POST", PrinterBedApiUri, buffer, PrintBedErrors, true)
return err
}

Expand Down
2 changes: 1 addition & 1 deletion octoprintApis/CancelRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ func (cmd *CancelRequest) Do(c *Client) error {
return err
}

_, err := c.doJsonRequest("POST", JobApiUri, buffer, JobToolErrors)
_, err := c.doJsonRequest("POST", JobApiUri, buffer, JobToolErrors, true)
return err
}
6 changes: 3 additions & 3 deletions octoprintApis/CommandRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ type CommandRequest struct {

// Do sends an API request and returns an error if any.
func (cmd *CommandRequest) Do(c *Client) error {
b := bytes.NewBuffer(nil)
if err := json.NewEncoder(b).Encode(cmd); err != nil {
buffer := bytes.NewBuffer(nil)
if err := json.NewEncoder(buffer).Encode(cmd); err != nil {
return err
}

_, err := c.doJsonRequest("POST", PrinterCommandApiUri, b, nil)
_, err := c.doJsonRequest("POST", PrinterCommandApiUri, buffer, nil, true)
return err
}
6 changes: 3 additions & 3 deletions octoprintApis/ConnectRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ type ConnectRequest struct {
func (cmd *ConnectRequest) Do(client *Client) error {
logger.TraceEnter("ConnectRequest.Do()")

bytes := bytes.NewBuffer(nil)
if err := cmd.encode(bytes); err != nil {
buffer := bytes.NewBuffer(nil)
if err := cmd.encode(buffer); err != nil {
logger.LogError("ConnectRequest.Do()", "cmd.encode()", err)
logger.TraceLeave("ConnectRequest.Do()")
return err
}

_, err := client.doJsonRequest("POST", ConnectionApiUri, bytes, ConnectionErrors)
_, err := client.doJsonRequest("POST", ConnectionApiUri, buffer, ConnectionErrors, true)
if err != nil {
logger.LogError("ConnectRequest.go()", "client.doJsonRequest(POST)", err)
}
Expand Down
2 changes: 1 addition & 1 deletion octoprintApis/ConnectionRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type ConnectionRequest struct{}
func (cmd *ConnectionRequest) Do(client *Client) (*dataModels.ConnectionResponse, error) {
logger.TraceEnter("ConnectionRequest.Do()")

bytes, err := client.doJsonRequest("GET", ConnectionApiUri, nil, nil)
bytes, err := client.doJsonRequest("GET", ConnectionApiUri, nil, nil, true)
if err != nil {
logger.LogError("ConnectionRequest.Do()", "client.doJsonRequest(GET)", err)
logger.TraceLeave("ConnectionRequest.Do()")
Expand Down
8 changes: 4 additions & 4 deletions octoprintApis/CustomCommandsRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ type CustomCommandsRequest struct{}

// Do sends an API request and returns the API response.
func (cmd *CustomCommandsRequest) Do(c *Client) (*dataModels.CustomCommandsResponse, error) {
b, err := c.doJsonRequest("GET", PrinterCommandCustomApiUri, nil, nil)
bytes, err := c.doJsonRequest("GET", PrinterCommandCustomApiUri, nil, nil, true)
if err != nil {
return nil, err
}

r := &dataModels.CustomCommandsResponse{}
if err := json.Unmarshal(b, r); err != nil {
response := &dataModels.CustomCommandsResponse{}
if err := json.Unmarshal(bytes, response); err != nil {
return nil, err
}

return r, err
return response, err
}
2 changes: 1 addition & 1 deletion octoprintApis/DeleteFileRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type DeleteFileRequest struct {
// Do sends an API request and returns error if any.
func (req *DeleteFileRequest) Do(c *Client) error {
uri := fmt.Sprintf("%s/%s/%s", FilesApiUri, req.Location, req.Path)
if _, err := c.doJsonRequest("DELETE", uri, nil, FilesLocationDeleteErrors); err != nil {
if _, err := c.doJsonRequest("DELETE", uri, nil, FilesLocationDeleteErrors, true); err != nil {
return err
}

Expand Down
6 changes: 3 additions & 3 deletions octoprintApis/DisconnectRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ type DisconnectRequest struct{}
func (this *DisconnectRequest) Do(client *Client) error {
logger.TraceEnter("DisconnectRequest.Do()")

bytes := bytes.NewBuffer(nil)
if err := this.encode(bytes); err != nil {
buffer := bytes.NewBuffer(nil)
if err := this.encode(buffer); err != nil {
logger.LogError("DisconnectRequest.Do()", "this.encode(bytes)", err)
logger.TraceLeave("DisconnectRequest.Do()")
return err
}

_, err := client.doJsonRequest("POST", ConnectionApiUri, bytes, ConnectionErrors)
_, err := client.doJsonRequest("POST", ConnectionApiUri, buffer, ConnectionErrors, true)
if err != nil {
logger.LogError("DisconnectRequest.Do()", "client.doJsonRequest(POST)", err)
}
Expand Down
6 changes: 3 additions & 3 deletions octoprintApis/FakesAckRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ type FakesAckRequest struct{}
func (this *FakesAckRequest) Do(client *Client) error {
logger.TraceEnter("FakesAckRequest.Do()")

bytes := bytes.NewBuffer(nil)
if err := this.encode(bytes); err != nil {
buffer := bytes.NewBuffer(nil)
if err := this.encode(buffer); err != nil {
logger.LogError("FakesAckRequest.Do()", "this.encode(bytes)", err)
logger.TraceLeave("FakesAckRequest.Do()")
return err
}

_, err := client.doJsonRequest("POST", ConnectionApiUri, bytes, ConnectionErrors)
_, err := client.doJsonRequest("POST", ConnectionApiUri, buffer, ConnectionErrors, true)
if err != nil {
logger.LogError("FakesAckRequest.Do()", "client.doJsonRequest(POST)", err)
logger.LogError("main.findConfigFile()", "Current()", err)
Expand Down
2 changes: 1 addition & 1 deletion octoprintApis/FileRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (request *FileRequest) Do(c *Client) (*dataModels.FileResponse, error) {
request.Recursive,
)

bytes, err := c.doJsonRequest("GET", uri, nil, FilesLocationGETErrors)
bytes, err := c.doJsonRequest("GET", uri, nil, FilesLocationGETErrors, true)
if err != nil {
return nil, err
}
Expand Down
12 changes: 6 additions & 6 deletions octoprintApis/FilesRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ func (cmd *FilesRequest) Do(c *Client) (*dataModels.FilesResponse, error) {
uri = fmt.Sprintf("%s/%s?recursive=%t", FilesApiUri, cmd.Location, cmd.Recursive)
}

b, err := c.doJsonRequest("GET", uri, nil, FilesLocationGETErrors)
bytes, err := c.doJsonRequest("GET", uri, nil, FilesLocationGETErrors, true)
if err != nil {
return nil, err
}

r := &dataModels.FilesResponse{}
if err := json.Unmarshal(b, r); err != nil {
response := &dataModels.FilesResponse{}
if err := json.Unmarshal(bytes, response); err != nil {
return nil, err
}

if len(r.Children) > 0 {
r.Files = r.Children
if len(response.Children) > 0 {
response.Files = response.Children
}

return r, err
return response, err
}
2 changes: 1 addition & 1 deletion octoprintApis/FullStateRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (cmd *FullStateRequest) Do(c *Client) (*dataModels.FullStateResponse, error
*/


bytes, err := c.doJsonRequest("GET", uri, nil, PrintErrors)
bytes, err := c.doJsonRequest("GET", uri, nil, PrintErrors, true)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion octoprintApis/JobRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type JobRequest struct{}

// Do sends an API request and returns the API response.
func (cmd *JobRequest) Do(client *Client) (*dataModels.JobResponse, error) {
bytes, err := client.doJsonRequest("GET", JobApiUri, nil, nil)
bytes, err := client.doJsonRequest("GET", JobApiUri, nil, nil, true)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion octoprintApis/NotificationRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (this *NotificationRequest) Do(client *Client, uiState string) (*dataModels
}

target := fmt.Sprintf("%s?command=get_notification", PluginZBoltOctoScreenApiUri)
bytes, err := client.doJsonRequest("GET", target, nil, ConnectionErrors)
bytes, err := client.doJsonRequest("GET", target, nil, ConnectionErrors, true)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion octoprintApis/OctoScreenSettingsRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type OctoScreenSettingsRequest struct {

func (this *OctoScreenSettingsRequest) Do(client *Client, uiState string) (*dataModels.OctoScreenSettingsResponse, error) {
target := fmt.Sprintf("%s?command=get_settings", PluginZBoltOctoScreenApiUri)
bytes, err := client.doJsonRequest("GET", target, nil, ConnectionErrors)
bytes, err := client.doJsonRequest("GET", target, nil, ConnectionErrors, false)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion octoprintApis/PauseRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (cmd *PauseRequest) Do(c *Client) error {
return err
}

_, err := c.doJsonRequest("POST", JobApiUri, buffer, JobToolErrors)
_, err := c.doJsonRequest("POST", JobApiUri, buffer, JobToolErrors, true)
return err
}

Expand Down
2 changes: 1 addition & 1 deletion octoprintApis/PluginManagerInfoRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (this *PluginManagerInfoRequest) Do(client *Client, uiState string) (*dataM
return nil, err
}

bytes, err := client.doJsonRequest("GET", pluginManagerRequestURI, params, ConnectionErrors)
bytes, err := client.doJsonRequest("GET", pluginManagerRequestURI, params, ConnectionErrors, true)
if err != nil {
logger.LogError("PluginManagerInfoRequest.Do()", "client.doJsonRequest()", err)
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions octoprintApis/PrintHeadHomeRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ type PrintHeadHomeRequest struct {

// Do sends an API request and returns an error if any.
func (cmd *PrintHeadHomeRequest) Do(c *Client) error {
b := bytes.NewBuffer(nil)
if err := cmd.encode(b); err != nil {
buffer := bytes.NewBuffer(nil)
if err := cmd.encode(buffer); err != nil {
return err
}

_, err := c.doJsonRequest("POST", PrinterPrintHeadApiUri, b, PrintHeadJobErrors)
_, err := c.doJsonRequest("POST", PrinterPrintHeadApiUri, buffer, PrintHeadJobErrors, true)
return err
}

Expand Down
Loading

0 comments on commit 5c7cb4f

Please sign in to comment.