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

ready refactor again

parent 587752f2
Branches
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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
......
......@@ -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
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment