Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
Printrun
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
machinery
Printrun
Commits
e73a8a94
Commit
e73a8a94
authored
Jan 12, 2013
by
kliment
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #313 from colah/temp-prompt
Temp prompt
parents
80403aa7
a377b85c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
11 deletions
+71
-11
pronsole.py
pronsole.py
+71
-11
No files found.
pronsole.py
View file @
e73a8a94
...
...
@@ -183,15 +183,46 @@ class Settings:
def
_all_settings
(
self
):
return
dict
([(
k
,
getattr
(
self
,
k
))
for
k
in
self
.
__dict__
.
keys
()
if
not
k
.
startswith
(
"_"
)])
class
Status
:
def
__init__
(
self
):
self
.
extruder_temp
=
0
self
.
extruder_temp_target
=
0
self
.
bed_temp
=
0
self
.
bed_temp_target
=
0
self
.
print_job
=
None
self
.
print_job_progress
=
1.0
def
update_tempreading
(
self
,
tempstr
):
r
=
tempstr
.
split
()
# eg. r = ["ok", "T:20.5", "/0.0", "B:0.0", "/0.0", "@:0"]
if
len
(
r
)
==
6
:
self
.
extruder_temp
=
float
(
r
[
1
][
2
:])
self
.
extruder_temp_target
=
float
(
r
[
2
][
1
:])
self
.
bed_temp
=
float
(
r
[
3
][
2
:])
self
.
bed_temp_target
=
float
(
r
[
4
][
1
:])
@
property
def
bed_enabled
(
self
):
return
self
.
bed_temp
!=
0
@
property
def
extruder_enabled
(
self
):
return
self
.
extruder_temp
!=
0
class
pronsole
(
cmd
.
Cmd
):
def
__init__
(
self
):
cmd
.
Cmd
.
__init__
(
self
)
if
not
READLINE
:
self
.
completekey
=
None
self
.
status
=
Status
()
self
.
dynamic_temp
=
False
self
.
p
=
printcore
.
printcore
()
self
.
p
.
recvcb
=
self
.
recvcb
self
.
recvlisteners
=
[]
self
.
prompt
=
"PC>"
self
.
in_macro
=
False
self
.
p
.
onlinecb
=
self
.
online
self
.
f
=
None
self
.
listing
=
0
...
...
@@ -231,6 +262,30 @@ class pronsole(cmd.Cmd):
self
.
web_config
=
None
self
.
web_auth_config
=
None
def
promptf
(
self
):
"""A function to generate prompts so that we can do dynamic prompts. """
if
self
.
in_macro
:
return
"..>"
elif
not
self
.
p
.
online
:
return
"uninitialized>"
elif
self
.
status
.
extruder_enabled
and
self
.
dynamic_temp
:
if
self
.
status
.
extruder_temp_target
==
0
:
return
"T:
%
s>"
%
self
.
status
.
extruder_temp
else
:
return
"T:
%
s/
%
s>"
%
(
self
.
status
.
extruder_temp
,
self
.
status
.
extruder_temp_target
)
else
:
return
"printer>"
def
postcmd
(
self
,
stop
,
line
):
""" A hook we override to generate prompts after
each command is executed, for the next prompt.
We also use it to send M105 commands so that
temp info gets updated for the prompt."""
if
self
.
p
.
online
and
self
.
dynamic_temp
:
self
.
p
.
send_now
(
"M105"
)
self
.
prompt
=
self
.
promptf
()
return
stop
def
set_temp_preset
(
self
,
key
,
value
):
if
not
key
.
startswith
(
"bed"
):
self
.
temps
[
"pla"
]
=
str
(
self
.
settings
.
temperature_pla
)
...
...
@@ -258,7 +313,7 @@ class pronsole(cmd.Cmd):
def
online
(
self
):
print
"Printer is now online"
sys
.
stdout
.
write
(
self
.
prompt
)
sys
.
stdout
.
write
(
self
.
prompt
f
()
)
sys
.
stdout
.
flush
()
def
help_help
(
self
,
l
):
...
...
@@ -290,7 +345,8 @@ class pronsole(cmd.Cmd):
def
end_macro
(
self
):
if
self
.
__dict__
.
has_key
(
"onecmd"
):
del
self
.
onecmd
# remove override
self
.
prompt
=
"PC>"
self
.
in_macro
=
False
self
.
prompt
=
self
.
promptf
()
if
self
.
cur_macro_def
!=
""
:
self
.
macros
[
self
.
cur_macro_name
]
=
self
.
cur_macro_def
macro
=
self
.
compile_macro
(
self
.
cur_macro_name
,
self
.
cur_macro_def
)
...
...
@@ -342,7 +398,8 @@ class pronsole(cmd.Cmd):
self
.
cur_macro_name
=
macro_name
self
.
cur_macro_def
=
""
self
.
onecmd
=
self
.
hook_macro
# override onecmd temporarily
self
.
prompt
=
"..>"
self
.
in_macro
=
False
self
.
prompt
=
self
.
promptf
()
def
delete_macro
(
self
,
macro_name
):
if
macro_name
in
self
.
macros
.
keys
():
...
...
@@ -520,6 +577,7 @@ class pronsole(cmd.Cmd):
def
preloop
(
self
):
print
"Welcome to the printer console! Type
\"
help
\"
for a list of available commands."
self
.
prompt
=
self
.
promptf
()
cmd
.
Cmd
.
preloop
(
self
)
def
do_connect
(
self
,
l
):
...
...
@@ -813,10 +871,11 @@ class pronsole(cmd.Cmd):
def
recvcb
(
self
,
l
):
if
"T:"
in
l
:
self
.
tempreadings
=
l
self
.
status
.
update_tempreading
(
l
)
tstring
=
l
.
rstrip
()
if
(
tstring
!=
"ok"
and
not
tstring
.
startswith
(
"ok T"
)
and
not
tstring
.
startswith
(
"T:"
)
and
not
self
.
listing
and
not
self
.
monitoring
):
print
tstring
sys
.
stdout
.
write
(
self
.
prompt
)
sys
.
stdout
.
write
(
self
.
prompt
f
()
)
sys
.
stdout
.
flush
()
for
i
in
self
.
recvlisteners
:
i
(
l
)
...
...
@@ -848,16 +907,17 @@ class pronsole(cmd.Cmd):
def
help_help
(
self
):
self
.
do_help
(
""
)
def
tempcb
(
self
,
l
):
if
"T:"
in
l
:
print
l
.
replace
(
"
\r
"
,
""
)
.
replace
(
"T"
,
"Hotend"
)
.
replace
(
"B"
,
"Bed"
)
.
replace
(
"
\n
"
,
""
)
.
replace
(
"ok "
,
""
)
def
do_gettemp
(
self
,
l
):
if
"dynamic"
in
l
:
self
.
dynamic_temp
=
True
if
self
.
p
.
online
:
self
.
recvlisteners
+=
[
self
.
tempcb
]
self
.
p
.
send_now
(
"M105"
)
time
.
sleep
(
0.75
)
self
.
recvlisteners
.
remove
(
self
.
tempcb
)
if
not
self
.
status
.
bed_enabled
:
print
"Hotend:
%
s/
%
s"
%
(
self
.
status
.
extruder_temp
,
self
.
status
.
extruder_temp_target
)
else
:
print
"Hotend:
%
s/
%
s"
%
(
self
.
status
.
extruder_temp
,
self
.
status
.
extruder_temp_target
)
print
"Bed:
%
s/
%
s"
%
(
self
.
status
.
bed_temp
,
self
.
status
.
bed_temp_target
)
def
help_gettemp
(
self
):
print
"Read the extruder and bed temperature."
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment