Commit 0333bb2a authored by Jake Read's avatar Jake Read

add link rep. to ui

parent 6addc5e8
......@@ -19,7 +19,9 @@ This project serves the developement environment / api we use to write and repre
- how do users know to hookup, how to hookup ?
- then draw something, and how does UI hook up, and when route changes ?
- change /src to /modules or /units ?
- catch err where can't click-escape from settings ?
-
- walk program units and change
- rename inout to jsunit
......
......@@ -309,6 +309,14 @@ function redrawLinks() {
while (svg.firstChild) {
svg.removeChild(svg.firstChild)
}
// find that link
var lnkPt
var nLnk = 0
for(mdlName in program.modules){
if(program.modules[mdlName].description.isLink){
lnkPt = getLeftWall(program.modules[mdlName].ui.domElem)
}
}
// redraw thru all links, just look at reps
for (mdlName in program.modules) {
var mdlRep = program.modules[mdlName]
......@@ -328,6 +336,12 @@ function redrawLinks() {
}
}
}
if(mdlRep.description.isHardware && !mdlRep.description.isLink){
nLnk ++
var hwPt = getRightWall(mdlRep.ui.domElem)
lnkPt.y += 10 * nLnk
var ln = newLine(hwPt.x, hwPt.y, lnkPt.x, lnkPt.y)
}
}
}
......
......@@ -296,4 +296,46 @@ function getInputArrow(div) {
}
return pos
}
function newLine(x1, y1, x2, y2) {
var ln = {}
ln.elem = document.createElementNS(svgns, 'line')
ln.elem.style.stroke = '#fcd17b'
ln.elem.style.fill = 'none'
ln.elem.style.strokeWidth = '7px'
ln.x1 = x1
ln.y1 = y1
ln.x2 = x2
ln.y2 = y2
redrawLine(ln)
svg.appendChild(ln.elem)
return ln
}
function redrawLine(ln) {
ln.elem.setAttribute('x1', ln.x1)
ln.elem.setAttribute('y1', ln.y1)
ln.elem.setAttribute('x2', ln.x2)
ln.elem.setAttribute('y2', ln.y2)
}
function getLeftWall(div) {
var x = div.offsetLeft + 25
var y = div.offsetTop + 25
var pt = {
x: x,
y: y
}
return pt
}
function getRightWall(div) {
var x = div.offsetLeft + div.clientWidth - 25
var y = div.offsetTop + div.clientHeight - 25
var pt = {
x: x,
y: y
}
return pt
}
\ No newline at end of file
......@@ -29,7 +29,9 @@ const Programs = require('./programs.js')
var program = Programs.new('hw unit test')
var link = Programs.loadModuleFromSource(program, './modules/hardware/atkseriallink.js')
//var link = Programs.loadModuleFromSource(program, './modules/hardware/atkseriallink.js')
var atkbbs = Programs.loadModuleFromSource(program, './modules/hardware/atkbbs.js')
atkbbs.description.position = {
......@@ -37,12 +39,12 @@ atkbbs.description.position = {
top: 200
}
link.description.position = {
left:475,
top: 100
}
// link.description.position = {
// left:475,
// top: 100
// }
link.attach(atkbbs.route)
//link.attach(atkbbs.route)
//program = Programs.open('programs/default.json')
......
......@@ -12,6 +12,7 @@ function ATKSerialLink() {
var atkSerialLink = {
description: {
isHardware: true,
isLink: true,
name: 'Serialport ATK Link',
alt: 'window into hardware world'
},
......@@ -95,7 +96,7 @@ function ATKSerialLink() {
pckt = literalRoute.concat(pckt) // add route
pckt.unshift(pckt.length + 1) // add length byte
if (writeToSerialPort(pckt)) {
console.log('PCKT OOT >>', pckt.toString())
console.log('PCKT OUT >>', pckt.toString(), '---------------')
} else {
// try to open ?
openSerialPort()
......@@ -188,10 +189,8 @@ function ATKSerialLink() {
var match = false
for (key in atkSerialLink.routes) {
if (returnRoute.toString() === atkSerialLink.routes[key].route.toString()) {
console.log('RETURN LINK AT', atkSerialLink.routes[key])
// strip header and return message
var msg = pckt.slice(pckt.indexOf(255) + 1)
console.log("RETURN MSG", msg)
match = true
atkSerialLink.routes[key].onMessage(msg)
}
......
......@@ -5,10 +5,10 @@ const Reps = require('./reps.js')
const JSUnit = require('./lib/jsunit.js')
let isStateKey = JSUnit.isStateKey
function newProgram(name){
function newProgram(name) {
var program = {
description: {
name: name,
name: name,
id: name
},
modules: {}
......@@ -38,6 +38,19 @@ function loadModuleFromSource(program, path, id) {
}
mod.description.path = path
/* ---------------------------------- */
// WARN! Corner Case should Go Away or Improve at next spiral
if(mod.description.isLink){
for (mdlName in program.modules) {
if (program.modules[mdlName].description.isLink) {
console.log("PRGMEM ONLY BIG ENOUGH FOR ONE LINK")
process.exit()
}
}
}
// end corner case code
/* ---------------------------------- */
// add to program object
program.modules[mod.description.id] = mod
......@@ -69,6 +82,32 @@ function loadModuleFromSource(program, path, id) {
}
console.log('ADDING', mod.description.id, 'to', program.description.id)
/* ---------------------------------- */
// WARN! Corner Case should Go Away or Improve at next spiral
// hardware corner case is hardware corner case
// here's what we'll do
// if it's hardware, and we're not loading from some saved program (no id)
//
if (mod.description.isHardware && !mod.description.isLink && id == null) {
// make sure we haven't already done this, thx
var lnk = null
for (mdlName in program.modules) {
if (program.modules[mdlName].description.isLink) {
lnk = mdlName
}
}
if (lnk) {
console.log('CORNER CASE: LOADING HW MODULE, LINKING TO LINK')
program.modules[lnk].attach(mod.route)
} else {
console.log('CORNER CASE: LOADING HW MODULE, ALSO LOADING LINK')
var link = loadModuleFromSource(program, './modules/hardware/atkseriallink.js')
// hook it up auto-like
link.attach(mod.route)
}
}
// also return it so that we can write programs without the UI
return mod
} else {
......
......@@ -2,6 +2,8 @@ const JSUnit = require('./lib/jsunit.js')
let isStateKey = JSUnit.isStateKey
function makeRepFromModule(mdl) {
// rep != mdl
// rep is rep of mdl
var rep = {
description: {
id: mdl.description.id,
......@@ -11,6 +13,15 @@ function makeRepFromModule(mdl) {
}
}
// yikes tho, corner cases should be easier ...
if(mdl.description.isHardware){
rep.description.isHardware = true
}
if(mdl.description.isLink){
rep.description.isLink = true
}
if(mdl.description.position){
rep.description.position = mdl.description.position
}
......
......@@ -224,6 +224,12 @@ function uiRequestNewModule(data) {
Programs.loadModuleFromSource(program, data)
// bit of a mess to pick out the last entered module
var keys = Object.keys(program.modules)
var latest = keys[keys.length - 1]
if(program.modules[latest].description.isLink && data != './modules/hardware/atkseriallink.js'){
// we just added hardware, so added a link, so we've added two
// just burn it down
socketSend('restart', '')
}
socketSend('put module', Reps.makeFromModule(program.modules[keys[keys.length - 1]]))
}
......
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