Skip to content
Snippets Groups Projects
Select Git revision
  • at_palomagr
  • master default protected
2 results

atkunit.js

Blame
  • Jake's avatar
    Jake Read authored
    6addc5e8
    History
    atkunit.js 1.04 KiB
    // software object for reciprocal hardware object 
    
    // boilerplate atkapi header
    const InOut = require('./jsunit.js')
    let Input = InOut.Input
    let Output = InOut.Output
    let State = InOut.State
    let Button = InOut.Button
    
    const ATKRoute = require('./atkroute.js')
    
    function Hardware(){
    	var hardware = {
    		description:{
    			name: 'hardwareUnit',
    			alt: 'software representation of networked hardware object',
    			isHardware: true 
    		},
    		route: ATKRoute('0,0')
    	}
    
    	hardware.state = State()
    	var state = hardware.state 
    
    	state.test = Button('test network', onNetworkTest)
    	state.message = 'click above to test network'
    	state.route = '0,0' // default  
    
    	state.onChange('route', function(){
    		hardware.route.route = state.route 
    	})
    
    	function onNetworkTest(){
    		var tstpck = new Array()
    		tstpck.push(127)
    		state.message = 'test packet out'
    		hardware.route.send(tstpck)
    	}
    
    	hardware.route.subscribe(127, testReturn)
    
    	function testReturn(msg){
    		state.message = 'test OK'
    		console.log('test returns with msg', msg)
    	}
    
    	return hardware
    }
    
    module.exports = Hardware