-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
141 lines (112 loc) · 3.08 KB
/
config.go
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package main
import (
"encoding/json"
"io/ioutil"
"os"
)
// Root Dir
var Root string
// configFile to save MainConfig to
var configFile = "config.json"
// MainConfig holds all basic configuration
var MainConfig struct {
NametagFile string `json:"Nametag File"` // File to store nametags
PrinterFile string `json:"Printer File"` // File to store printers
ImagesDir string `json:"Images Directory"` // Directory to store generated images
OpenScadScript string `json:"OpenSCAD Script"` // Openscad script location
StlDir string `json:"Stl Direcotory"` // Directory to store generated stl files
GcodeDir string `json:"Gcode Directory"` // Directory to store generated gcode files
SlicerConfigDir string `json:"Slicer Config Directory"` // Directory to store slicer config files
OpenScadPath string `json:"OpenSCAD Path"` // Path to use to run OpenSCAD
SlicerPath string `json:"Slic3r Path"` // path to use to run Slic3r
}
func initMainDefaults() {
MainConfig.NametagFile = "config/nametags.json"
MainConfig.PrinterFile = "config/printers.json"
MainConfig.ImagesDir = "assets/images/nametags/"
MainConfig.OpenScadScript = "openscad/"
MainConfig.StlDir = "stl/"
MainConfig.GcodeDir = "gcode/"
MainConfig.SlicerConfigDir = "config/"
MainConfig.OpenScadPath = "openscad"
MainConfig.SlicerPath = "slic3r"
}
func loadMain() {
confPath := Root + configFile
if _, err := os.Stat(confPath); os.IsNotExist(err) {
initMainDefaults()
saveMain()
} else {
in, err := ioutil.ReadFile(Root + configFile)
if err != nil {
panic(err)
}
json.Unmarshal(in, &MainConfig)
}
}
func saveMain() {
out, jerr := json.MarshalIndent(MainConfig, "", " ")
if jerr != nil {
Error.Println(jerr)
}
Main.Println(out)
err := ioutil.WriteFile(Root+configFile, out, 0644)
if err != nil {
panic(err)
}
}
func loadNametags() {
in, err := ioutil.ReadFile(Root + MainConfig.NametagFile)
if err != nil {
panic(err)
}
nametagsMux.Lock()
json.Unmarshal(in, &nametags)
maxID := 0
for i := range nametags {
if nametags[i].ID > maxID {
maxID = nametags[i].ID
}
nametags[i].Status = NIdle
//nametags[i].Processing = false
nametags[i].PrinterID = 0
}
nametagsMux.Unlock()
CurrentID = maxID
//Main.Println(nametags)
}
func saveNametags() {
nametagsMux.Lock()
out, jerr := json.MarshalIndent(nametags, "", " ")
nametagsMux.Unlock()
if jerr != nil {
Error.Println(jerr)
}
err := ioutil.WriteFile(Root+MainConfig.NametagFile, out, 0644)
if err != nil {
panic(err)
}
}
func loadPrinters() {
in, err := ioutil.ReadFile(Root + MainConfig.PrinterFile)
if err != nil {
panic(err)
}
json.Unmarshal(in, &printers)
for i := range printers {
printers[i].Status = PIdle
//printers[i].Available = true
printers[i].NametagID = 0
}
//Main.Println(printers)
}
func savePrinters() {
out, jerr := json.MarshalIndent(printers, "", " ")
if jerr != nil {
Error.Println(jerr)
}
err := ioutil.WriteFile(Root+MainConfig.PrinterFile, out, 0644)
if err != nil {
panic(err)
}
}