Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rndmc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jake Read
rndmc
Commits
28b3843c
Commit
28b3843c
authored
6 years ago
by
Jake Read
Browse files
Options
Downloads
Patches
Plain Diff
ready refactor again
parent
587752f2
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+8
-1
8 additions, 1 deletion
README.md
server.js
+6
-8
6 additions, 8 deletions
server.js
src/parsing/gcode.js
+61
-50
61 additions, 50 deletions
src/parsing/gcode.js
with
75 additions
and
59 deletions
README.md
+
8
−
1
View file @
28b3843c
...
...
@@ -3,7 +3,14 @@
## what it do
... now ...
-
refactor ui with setter
-
happy with module writing?
-
with setting?
-
state variables look like variables in module writing
-
system wraps in setters / getters
-
system has this.state.onChange('varname', function(){ fn code })
-
refactor ui with new everything
-
terminal serves terminal input line (client, css)
-
input lines comes thru to setter
...
...
This diff is collapsed.
Click to expand it.
server.js
+
6
−
8
View file @
28b3843c
...
...
@@ -39,7 +39,7 @@ wss.on('connection', (ws) => {
// say hello
socketSend
(
'
console
'
,
'
hello client
'
)
// send current config
sendModules
()
sendModules
()
()
console
.
log
(
'
socket open on 8081
'
)
ws
.
on
(
'
message
'
,
(
evt
)
=>
{
socketRecv
(
evt
)
...
...
@@ -110,16 +110,14 @@ var modules = new Array()
var
term
=
addModule
(
'
./src/ui/terminal.js
'
)
var
gcode
=
addModule
(
'
./src/parsing/gcode.js
'
)
// attaching an output to an input
term
.
outputs
.
lineOut
.
attach
(
gcode
.
inputs
.
lineIn
)
console
.
log
(
'
here setting term ui lineIn to new txt
'
)
term
.
ui
.
lineIn
.
set
(
"
new txt
"
)
gcode
.
ui
.
g0speed
.
set
(
1255
)
// to add UI vars to prgmem / save them
// typically, set in ui, saved in ui
// setting ui elements / state
term
.
ui
.
lineIn
.
set
(
"
G1 F100 X10 Y10
"
)
gcode
.
ui
.
G0
.
set
(
1255
)
// setting data w/r/t the representations they serve
term
.
rep
=
{}
term
.
rep
.
left
=
10
term
.
rep
.
top
=
10
...
...
This diff is collapsed.
Click to expand it.
src/parsing/gcode.js
+
61
−
50
View file @
28b3843c
...
...
@@ -5,20 +5,32 @@ let Output = InOut.Output
let
UIElement
=
InOut
.
UIElement
function
Gcode
()
{
this
.
description
=
{
var
gcode
=
{
description
:
{
name
:
'
Gcode Parser
'
,
alt
:
'
line of gcode -> planner recognized move
'
},
ui
:
{
mode
:
UIElement
(
'
string
'
,
'
G0
'
,
changeMode
),
G0
:
UIElement
(
'
number
'
,
1200
,
null
),
G1
:
UIElement
(
'
number
'
,
400
,
null
)
},
inputs
:
{
lineIn
:
Input
(
'
string
'
,
parseGcode
)
},
outputs
:
{
instructionOut
:
Output
(
'
move instruction
'
),
modeChange
:
Output
(
'
string
'
)
}
}
// state
this
.
ui
=
{
mode
:
new
UIElement
(
'
string
'
,
'
G0
'
,
null
),
g0speed
:
new
UIElement
(
'
number
'
,
1200
,
null
),
g1speed
:
new
UIElement
(
'
number
'
,
400
,
null
)
function
changeMode
()
{
console
.
log
(
'
gcode mode changed to
'
,
gcode
.
ui
.
mode
.
value
)
}
// local functions
var
getKeyValues
=
(
str
)
=>
{
function
getKeyValues
(
str
){
var
kv
=
{}
for
(
var
i
=
0
;
i
<
str
.
length
;
i
++
)
{
if
(
str
[
i
].
match
(
'
[A-Za-z]
'
))
{
// regex to match upper case letters
...
...
@@ -33,7 +45,11 @@ function Gcode() {
return
kv
}
var
parseGcode
=
(
str
)
=>
{
// TODO: test, can we link global vars to ui objects ...
// gcode.ui.mode.value = var ? no bc set / get etc
// more like var = gcode.ui.mode.value ? is this referential?
function
parseGcode
(
str
){
var
instruction
=
{
position
:
{},
hasMove
:
false
,
...
...
@@ -43,7 +59,7 @@ function Gcode() {
kv
=
getKeyValues
(
str
)
// track modality
if
(
kv
.
G
==
0
|
kv
.
G
==
1
)
{
this
.
state
.
mode
=
'
G
'
+
kv
.
G
.
toString
()
gcode
.
ui
.
mode
.
set
(
'
G
'
+
kv
.
G
.
toString
()
)
}
else
if
(
kv
.
G
!=
null
)
{
// no arcs pls
console
.
log
(
'
unfriendly Gcode mode!
'
,
kv
)
...
...
@@ -54,11 +70,11 @@ function Gcode() {
instruction
.
position
[
key
]
=
kv
[
key
]
instruction
.
hasMove
=
true
}
else
if
(
key
.
match
(
'
[F]
'
))
{
this
.
state
.
speeds
[
this
.
state
.
mode
]
=
kv
.
F
gcode
.
ui
[
gcode
.
ui
.
mode
.
value
].
set
(
kv
.
F
)
}
}
instruction
.
speed
=
this
.
state
.
speeds
[
this
.
state
.
mode
]
instruction
.
speed
=
gcode
.
ui
[
gcode
.
ui
.
mode
.
value
].
get
()
// and this for help later?
instruction
.
kv
=
kv
...
...
@@ -69,21 +85,16 @@ function Gcode() {
var
lineIn
=
(
str
)
=>
{
var
instruction
=
parseGcode
(
str
)
if
(
instruction
.
hasMove
)
{
this
.
outputs
.
instructionOut
.
emit
(
instruction
)
console
.
log
(
'
gcode emit
'
,
instruction
)
gcode
.
outputs
.
instructionOut
.
emit
(
instruction
)
}
else
{
this
.
outputs
.
modeChange
.
emit
(
this
.
state
.
mode
)
outputs
.
modeChange
.
emit
(
gcode
.
ui
.
mode
.
get
()
)
}
}
// ins and outs
this
.
inputs
=
{
lineIn
:
new
Input
(
'
string
'
,
lineIn
)
}
this
.
outputs
=
{
instructionOut
:
new
Output
(
'
move instruction
'
,
'
object
'
),
modeChange
:
new
Output
(
'
mode change
'
,
'
string
'
)
}
return
gcode
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment