Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ZOffsetRequest.go « octoprintApis - github.com/Z-Bolt/OctoScreen.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 972ee1ccbd0423bf639874565994710c66434a10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package octoprintApis

import (
	"bytes"
	"encoding/json"
	// "fmt"

	"github.com/Z-Bolt/OctoScreen/logger"
	"github.com/Z-Bolt/OctoScreen/octoprintApis/dataModels"
)


type ZOffsetRequest struct {
	Command string `json:"command"`
	Tool    int    `json:"tool"`
}

func (this *ZOffsetRequest) Do(client *Client) (*dataModels.ZOffsetResponse, error) {
	this.Command = "get_z_offset"

	params := bytes.NewBuffer(nil)
	if err := json.NewEncoder(params).Encode(this); err != nil {
		logger.LogError("ZOffsetRequest.Do()", "json.NewEncoder(params).Encode(this)", err)
		return nil, err
	}

	// bytes, err := client.doJsonRequest("POST", UriZBoltRequest, params, ConnectionErrors)
	bytes, err := client.doJsonRequest("GET", PluginZBoltApiUri, params, ConnectionErrors, true)
	if err != nil {
		logger.LogError("ZOffsetRequest.Do()", "client.doJsonRequest()", err)
		return nil, err
	}

	response := &dataModels.ZOffsetResponse{}
	if err := json.Unmarshal(bytes, response); err != nil {
		logger.LogError("ZOffsetRequest.Do()", "json.Unmarshal()", err)
		return nil, err
	}

	return response, err
}




// SetZOffsetRequest - retrieves the current configuration of OctoPrint.
type SetZOffsetRequest struct {
	Command string  `json:"command"`
	Tool    int     `json:"tool"`
	Value   float64 `json:"value"`
}

func (this *SetZOffsetRequest) Do(client *Client) error {
	this.Command = "set_z_offset"

	buffer := bytes.NewBuffer(nil)
	if err := json.NewEncoder(buffer).Encode(this); err != nil {
		logger.LogError("SetZOffsetRequest.Do()", "json.NewEncoder(params).Encode(this)", err)
		return err
	}

	_, err := client.doJsonRequest("POST", PluginZBoltApiUri, buffer, ConnectionErrors, true)
	return err
}