Commit 15571dff authored by Jake Read's avatar Jake Read

ongoing

parent d9325673
......@@ -25,6 +25,7 @@ function ATKRoute(route, calls) {
atkroute.onMessage = function(msg){
// one key at a time, for now
var key = msg[0].toString()
// *could* slice the key out at this point, but nah
if(this.calls[key] != null){
this.calls[key](msg)
}
......
......@@ -22,6 +22,8 @@ function Hardware(){
hardware.state = State()
var state = hardware.state
state.reset = Button('reset hardware', onReset)
state.test = Button('test network', onNetworkTest)
state.message = 'click above to test network'
state.route = '0,0' // default
......@@ -30,6 +32,13 @@ function Hardware(){
hardware.route.route = state.route
})
function onReset(){
var rstpck = new Array()
rstpck.push(128)
state.message = 'reset command issued'
hardware.route.send(rstpck)
}
function onNetworkTest(){
var tstpck = new Array()
tstpck.push(127)
......
......@@ -13,7 +13,7 @@ function unPack32(arr){
var unPacked = arr[0] << 24 | arr[1] << 16 | arr[2] << 8 | arr[3]
return unPacked
} else {
console.log("ERR: arr > 4 at unPack32")
console.log("ERR: arr > 4 at unPack32", arr)
}
}
......
......@@ -29,11 +29,12 @@ const Programs = require('./programs.js')
var program = Programs.new('new program')
var step = Programs.loadModuleFromSource(program, './modules/hardware/atkstepper.js')
// UI
const View = require('./views.js')
View.startHttp()
View.startWs()
Programs.assignSocket(View.uiSocket)
View.assignProgram(program)
View.assignProgram(program)
\ No newline at end of file
......@@ -191,6 +191,7 @@ function ATKSerialLink() {
if (returnRoute.toString() === atkSerialLink.routes[key].route.toString()) {
// strip header and return message
var msg = pckt.slice(pckt.indexOf(255) + 1)
// this slices down to the keys ... doesn't take the keys away
match = true
atkSerialLink.routes[key].onMessage(msg)
}
......
......@@ -20,17 +20,30 @@ function Stepper() {
stepper.description.alt = 'software representation of stepper motor'
stepper.inputs = {
move: Input('move instruction', onNewInstruction),
trapezoid: Input('move instruction', onNewInstruction),
accel: Input('number', onAccelCommand),
rmtrig: Input('event', onRawMove)
}
stepper.outputs = {
ack: Output('move acknowledgement'),
position: Output('number')
}
// alias to state (from Hardware() beginnings)
// ptr to state (from Hardware() beginnings)
var state = stepper.state
// for acceleration moves, in steps/s/s
state.rate = 2000
state.onChange('rate', () => {
if(state.rate > 2000){
state.rate = 2000
} else if (state.rate < 100){
state.rate = 100
}
})
state.axis = 'X'
state.spu = 200 // steps per unit
state.rawMove = -10
......@@ -55,6 +68,10 @@ function Stepper() {
sendToHardware(testMove)
}
function onAccelCommand(num){
// 1 or 0 for start or stop accelerating
}
function onNewInstruction(move) {
// console.log('move to stepper', stepper.state.axis, move)
// pick out axis (check if it's a wait move)
......@@ -200,15 +217,16 @@ function Stepper() {
stepper.route.subscribe(131, onHardwareStepsComplete)
function onHardwareStepsComplete(pckt) {
var stepsMade = PCKT.unPack32(pckt)
var stepsMade = PCKT.unPack32(pckt.slice(1))
state.position += stepsMade
var unitsMade = stepsMade / state.spu
var ack = {
axis: state.axis,
increment: unitsMade
}
console.log("STEPPER ACK MOVE", state.axis)
console.log("STEPPER ACK MOVE", state.axis, stepsMade)
stepper.outputs.ack.emit(ack)
stepper.outputs.position.emit(state.position)
}
stepper.route.subscribe(132, onHardwareWaitComplete)
......
......@@ -34,7 +34,7 @@ function startHttp() {
// through this window
http.listen(8080, () => {
console.log('listening on 8080 for static files')
console.log('RNDMC is listening on localhost:8080')
})
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment