Skip to content

Commit

Permalink
added status screen and menu structure
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkv committed Nov 23, 2019
1 parent 845d348 commit fc33e3a
Show file tree
Hide file tree
Showing 16 changed files with 668 additions and 221 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ build-internal: prepare-internal
cp ../*.deb /build/;

prepare-internal:
dch --create -v $(VERSION)-6 --package $(PACKAGE_NAME) empty; \
dch --create -v $(VERSION)-9 --package $(PACKAGE_NAME) empty; \
cd $(WORKDIR)/..; \
tar -czf octoscreen_$(VERSION).orig.tar.gz --exclude-vcs OctoScreen

Expand Down
51 changes: 51 additions & 0 deletions styles/z-bolt/images/actions.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 11 additions & 24 deletions styles/z-bolt/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ scrollbar slider {
}

progress, trough {
min-height: 40px;
min-height: 20px;
font-size: 50px;
}

Expand All @@ -31,8 +31,12 @@ progress {
}

.printing-progress-bar{
font-size: 70px;
color: #999;
font-size: 60px;
color: #00C9B4;
}

.printing-state {
opacity: 0.5;
}

button {
Expand Down Expand Up @@ -142,25 +146,8 @@ button.keyboard {
}

.printing-status-label {
margin-top: 10px;
/* font-size: 24px; */
}

/* GtkWindow {
background-color: green;
border-width: 3px;
border-color: blue;
} */

/* GtkButton {
background-image: none;
background-color:#1010FF;
margin:2px;
border-radius:0;
} */
padding-top: 5px;
padding-bottom: 3px;

/* button, entry {
color: #ff00ea;
font: 12px "Comic Sans";
background-color: #1010FF;
} */
font-size: 24px;
}
16 changes: 16 additions & 0 deletions ui/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/gotk3/gotk3/glib"
"github.com/gotk3/gotk3/gtk"
"github.com/mcuadros/go-octoprint"
)

// Set at compilation time.
Expand Down Expand Up @@ -89,6 +90,21 @@ func (p *CommonPanel) Scaled(s int) int {
return s * p.UI.scaleFactor
}

func (m *CommonPanel) arrangeButtons(buttons []gtk.IWidget) {

row := 4

for i, k := range buttons {
m.Grid().Attach(k, (i%row)+1, i/row, 1, 1)
}
}

func (m *CommonPanel) command(gcode string) error {
cmd := &octoprint.CommandRequest{}
cmd.Commands = []string{gcode}
return cmd.Do(m.UI.Printer)
}

type BackgroundTask struct {
close chan bool

Expand Down
196 changes: 196 additions & 0 deletions ui/extrude.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
package ui

import (
"fmt"
"strings"
"time"

"github.com/gotk3/gotk3/gtk"
"github.com/mcuadros/go-octoprint"
)

var extrudePanelInstance *extrudePanel

type extrudePanel struct {
CommonPanel

amount *StepButton
tool *StepButton

box *gtk.Box
labels map[string]*LabelWithImage
previous *octoprint.TemperatureState
}

func ExtrudePanel(ui *UI, parent Panel) Panel {
if extrudePanelInstance == nil {
m := &extrudePanel{CommonPanel: NewCommonPanel(ui, parent),
labels: map[string]*LabelWithImage{},
}
m.panelH = 2
m.b = NewBackgroundTask(time.Second*5, m.updateTemperatures)
m.initialize()
extrudePanelInstance = m
}

return extrudePanelInstance
}

func (m *extrudePanel) initialize() {
defer m.Initialize()

m.Grid().Attach(m.createExtrudeButton("Extrude", "extrude.svg", 1), 1, 0, 1, 1)
m.Grid().Attach(m.createExtrudeButton("Retract", "retract.svg", -1), 4, 0, 1, 1)

m.box = MustBox(gtk.ORIENTATION_VERTICAL, 5)
m.box.SetVAlign(gtk.ALIGN_CENTER)
m.box.SetHAlign(gtk.ALIGN_CENTER)
m.Grid().Attach(m.box, 2, 0, 2, 1)

m.amount = MustStepButton("move-step.svg", Step{"1mm", 1}, Step{"5mm", 5}, Step{"10mm", 10})
m.Grid().Attach(m.amount, 2, 1, 1, 1)

m.Grid().Attach(m.createToolButton(), 1, 1, 1, 1)
m.Grid().Attach(m.createFlowrateButton(), 3, 1, 1, 1)
}

func (m *extrudePanel) updateTemperatures() {
s, err := (&octoprint.ToolStateRequest{
History: true,
Limit: 1,
}).Do(m.UI.Printer)

if err != nil {
Logger.Error(err)
return
}

m.loadTemperatureState(s)
}

func (m *extrudePanel) loadTemperatureState(s *octoprint.TemperatureState) {
for tool, current := range s.Current {
if _, ok := m.labels[tool]; !ok {
m.addNewTool(tool)
}

m.loadTemperatureData(tool, &current)
}

m.previous = s
}

func (m *extrudePanel) addNewTool(tool string) {
m.labels[tool] = MustLabelWithImage("extruder.svg", "")
m.box.Add(m.labels[tool])
m.tool.AddStep(Step{strings.Title(tool), tool})

Logger.Infof("New tool detected %s", tool)
}

func (m *extrudePanel) loadTemperatureData(tool string, d *octoprint.TemperatureData) {
text := fmt.Sprintf("%s: %.1f°C / %.1f°C", strings.Title(tool), d.Actual, d.Target)

if m.previous != nil && d.Target > 0 {
if p, ok := m.previous.Current[tool]; ok {
text = fmt.Sprintf("%s (%.1f°C)", text, d.Actual-p.Actual)
}
}

m.labels[tool].Label.SetText(text)
m.labels[tool].ShowAll()
}

func (m *extrudePanel) createToolButton() *StepButton {
m.tool = MustStepButton("extruder.svg")
m.tool.Callback = func() {
cmd := &octoprint.ToolSelectRequest{}
cmd.Tool = m.tool.Value().(string)

Logger.Infof("Changing tool to %s", cmd.Tool)
if err := cmd.Do(m.UI.Printer); err != nil {
Logger.Error(err)
return
}
}

return m.tool
}

func (m *extrudePanel) createFlowrateButton() *StepButton {
b := MustStepButton("speed-step.svg", Step{"Slow", 75}, Step{"Normal", 100}, Step{"High", 125})
b.Callback = func() {
cmd := &octoprint.ToolFlowrateRequest{}
cmd.Factor = b.Value().(int)

Logger.Infof("Changing flowrate to %d%%", cmd.Factor)
if err := cmd.Do(m.UI.Printer); err != nil {
Logger.Error(err)
return
}
}

return b
}

func (m *extrudePanel) createLoadButton() gtk.IWidget {
length := 750.0

if m.UI.Settings != nil {
length = m.UI.Settings.FilamentInLength
}

return MustButtonImage("Load", "extrude.svg", func() {
cmd := &octoprint.CommandRequest{}
cmd.Commands = []string{
"G91",
fmt.Sprintf("G0 E%.1f F5000", length*0.80),
fmt.Sprintf("G0 E%.1f F500", length*0.20),
"G90",
}

Logger.Info("Sending filament load request")
if err := cmd.Do(m.UI.Printer); err != nil {
Logger.Error(err)
return
}
})
}

func (m *extrudePanel) createUnloadButton() gtk.IWidget {

length := 800.0

if m.UI.Settings != nil {
length = m.UI.Settings.FilamentOutLength
}

return MustButtonImage("Unload", "retract.svg", func() {
cmd := &octoprint.CommandRequest{}
cmd.Commands = []string{
"G91",
fmt.Sprintf("G0 E-%.1f F5000", length),
"G90",
}

Logger.Info("Sending filament unload request")
if err := cmd.Do(m.UI.Printer); err != nil {
Logger.Error(err)
return
}
})
}

func (m *extrudePanel) createExtrudeButton(label, image string, dir int) gtk.IWidget {

return MustPressedButton(label, image, func() {
cmd := &octoprint.ToolExtrudeRequest{}
cmd.Amount = m.amount.Value().(int) * dir

Logger.Infof("Sending extrude request, with amount %d", cmd.Amount)
if err := cmd.Do(m.UI.Printer); err != nil {
Logger.Error(err)
return
}
}, 200)
}
Loading

0 comments on commit fc33e3a

Please sign in to comment.