Skip to content
Snippets Groups Projects
Commit 28b3843c authored by Jake Read's avatar Jake Read
Browse files

ready refactor again

parent 587752f2
No related branches found
No related tags found
No related merge requests found
...@@ -3,7 +3,14 @@ ...@@ -3,7 +3,14 @@
## what it do ## what it do
... now ... ... 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) - terminal serves terminal input line (client, css)
- input lines comes thru to setter - input lines comes thru to setter
......
...@@ -39,7 +39,7 @@ wss.on('connection', (ws) => { ...@@ -39,7 +39,7 @@ wss.on('connection', (ws) => {
// say hello // say hello
socketSend('console', 'hello client') socketSend('console', 'hello client')
// send current config // send current config
sendModules() sendModules()()
console.log('socket open on 8081') console.log('socket open on 8081')
ws.on('message', (evt) => { ws.on('message', (evt) => {
socketRecv(evt) socketRecv(evt)
...@@ -110,16 +110,14 @@ var modules = new Array() ...@@ -110,16 +110,14 @@ var modules = new Array()
var term = addModule('./src/ui/terminal.js') var term = addModule('./src/ui/terminal.js')
var gcode = addModule('./src/parsing/gcode.js') var gcode = addModule('./src/parsing/gcode.js')
// attaching an output to an input
term.outputs.lineOut.attach(gcode.inputs.lineIn) term.outputs.lineOut.attach(gcode.inputs.lineIn)
console.log('here setting term ui lineIn to new txt') // setting ui elements / state
term.ui.lineIn.set("new txt") term.ui.lineIn.set("G1 F100 X10 Y10")
gcode.ui.G0.set(1255)
gcode.ui.g0speed.set(1255)
// to add UI vars to prgmem / save them
// typically, set in ui, saved in ui
// setting data w/r/t the representations they serve
term.rep = {} term.rep = {}
term.rep.left = 10 term.rep.left = 10
term.rep.top = 10 term.rep.top = 10
......
...@@ -5,20 +5,32 @@ let Output = InOut.Output ...@@ -5,20 +5,32 @@ let Output = InOut.Output
let UIElement = InOut.UIElement let UIElement = InOut.UIElement
function Gcode() { function Gcode() {
this.description = {
var gcode = {
description: {
name: 'Gcode Parser', name: 'Gcode Parser',
alt: 'line of gcode -> planner recognized move' 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 function changeMode() {
this.ui = { console.log('gcode mode changed to', gcode.ui.mode.value)
mode: new UIElement('string', 'G0', null),
g0speed: new UIElement('number', 1200, null),
g1speed: new UIElement('number', 400, null)
} }
// local functions // local functions
var getKeyValues = (str) => { function getKeyValues(str){
var kv = {} var kv = {}
for (var i = 0; i < str.length; i++) { for (var i = 0; i < str.length; i++) {
if (str[i].match('[A-Za-z]')) { // regex to match upper case letters if (str[i].match('[A-Za-z]')) { // regex to match upper case letters
...@@ -33,7 +45,11 @@ function Gcode() { ...@@ -33,7 +45,11 @@ function Gcode() {
return kv 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 = { var instruction = {
position: {}, position: {},
hasMove: false, hasMove: false,
...@@ -43,7 +59,7 @@ function Gcode() { ...@@ -43,7 +59,7 @@ function Gcode() {
kv = getKeyValues(str) kv = getKeyValues(str)
// track modality // track modality
if (kv.G == 0 | kv.G == 1) { 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) { } else if (kv.G != null) {
// no arcs pls // no arcs pls
console.log('unfriendly Gcode mode!', kv) console.log('unfriendly Gcode mode!', kv)
...@@ -54,11 +70,11 @@ function Gcode() { ...@@ -54,11 +70,11 @@ function Gcode() {
instruction.position[key] = kv[key] instruction.position[key] = kv[key]
instruction.hasMove = true instruction.hasMove = true
} else if (key.match('[F]')) { } 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? // and this for help later?
instruction.kv = kv instruction.kv = kv
...@@ -69,21 +85,16 @@ function Gcode() { ...@@ -69,21 +85,16 @@ function Gcode() {
var lineIn = (str) => { var lineIn = (str) => {
var instruction = parseGcode(str) var instruction = parseGcode(str)
if (instruction.hasMove) { if (instruction.hasMove) {
this.outputs.instructionOut.emit(instruction) console.log('gcode emit', instruction)
gcode.outputs.instructionOut.emit(instruction)
} else { } 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 = { return gcode
instructionOut: new Output('move instruction', 'object'),
modeChange: new Output('mode change', 'string')
}
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment