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

some more usage and writing notes

parent 1b99397e
Branches
No related tags found
No related merge requests found
...@@ -127,17 +127,95 @@ To disconnect, click the output to disconnect, and then the input to disconnect ...@@ -127,17 +127,95 @@ To disconnect, click the output to disconnect, and then the input to disconnect
# RuNDMC Architecture # RuNDMC Architecture
![arch](doc/images/rndmc-architecture.png)
Above is a somewhat-complete representation of what-all is going on in software.
Essentially, we load tiny programs (```modules/sub/modulename.js```) using node.js's *require* function. These programs each have inputs and outputs, and some state. Each also has a description (an example of a complete module is below).
The UI serves a representation of this through a websocket.
Pardon my at-the-moment brief explanation.
# Writing New Modules # Writing New Modules
- whenever a menu is requested, the system searches ```modules/ * ``` for *anything*. include your .js of a new module there Whenever a menu is requested, the system searches ```modules/ * ``` for *anything*. include your .js of a new module there.
- anything goes: you can run whatever code will run in node.js ... just follow these simple rules
- TODO: put example here, with comments These modules are written with objects inherited from ```lib/jsunit.js```
Here's an example. This is modules/ui/number.js.
Besides Inputs, Outputs, a Description and State object, anything else goes. I.E. local functions, other Node.JS packages, etc.
```JavaScript
// boilerplate rndmc header
const InOut = require('../../lib/jsunit.js')
let Input = InOut.Input
let Output = InOut.Output
let State = InOut.State
let Button = InOut.Button
// a constructor, a fn, a javascript mess
function uiNum() {
// this is the tiny program-as-and-object that we'll load into rundmc
// description / name is required to load successfully
var uinum = {
description: {
name: 'number-output',
alt: 'for clicking'
}
}
// the State() object is what the system scrapes for ui variables / updates from the UI
// this includes things like Button('title', callback), which are unique state variables
// they can also be found in jsunit.js
uinum.state = State()
// alias !
var state = uinum.state
state.number = 10
state.onChange('number', onNumberDesire)
state.button = Button('WHAM', onNumberDesire)
// inputs are required, and must be Input('type', callback)
uinum.inputs = {
thru: Input('any', onThruInput), // makes anything into num event
evt: Input('any', onNumberDesire)
}
// outputs: Output('type')
uinum.outputs = {
out: Output('number')
}
// here's our input callback, specified in the input constructor
function onThruInput(input){
if(typeof input == 'number'){
state.number = input
} else {
state.number = parseFloat(input)
}
onNumberDesire()
}
function onNumberDesire(){
// here's how we fire an output.
uinum.outputs.out.emit(state.number)
}
// gotta give the program this thing we made
return uinum
}
// this for node.js's require() function
module.exports = uiNum
```
# Writing Hardware Modules # Writing Hardware Modules
- TODO: same, also including links / explanation to atk Hardware Modules are identical to other modules, but they inherit a class that can be found and examined at ```lib/atkunit.js``` which subsequently calls hardware-interfacing classes from ```lib/atkroute.js``` and often use tools from ```lib/packets.js``` (packets.js is mostly about packing 64-bit information into byte-size units).
# Development Notes # Development Notes
......
doc/images/rndmc-architecture.png

62.1 KiB

// boilerplate atkapi header // boilerplate rndmc header
const InOut = require('../../lib/jsunit.js') const InOut = require('../../lib/jsunit.js')
let Input = InOut.Input let Input = InOut.Input
let Output = InOut.Output let Output = InOut.Output
...@@ -8,14 +8,18 @@ let Button = InOut.Button ...@@ -8,14 +8,18 @@ let Button = InOut.Button
// a constructor, a fn, a javascript mess // a constructor, a fn, a javascript mess
function uiNum() { function uiNum() {
// this is the tiny program-as-and-object that we'll load into rundmc
// description / name is required to load successfully
var uinum = { var uinum = {
// descriptions are used in UI
description: { description: {
name: 'number output', name: 'number-output',
alt: 'for clicking' alt: 'for clicking'
} }
} }
// the State() object is what the system scrapes for ui variables / updates from the UI
// this includes things like Button('title', callback), which are unique state variables
// they can also be found in jsunit.js
uinum.state = State() uinum.state = State()
// alias ! // alias !
var state = uinum.state var state = uinum.state
...@@ -25,15 +29,18 @@ function uiNum() { ...@@ -25,15 +29,18 @@ function uiNum() {
state.button = Button('WHAM', onNumberDesire) state.button = Button('WHAM', onNumberDesire)
// inputs are required, and must be Input('type', callback)
uinum.inputs = { uinum.inputs = {
thru: Input('any', onThruInput), // makes anything into num event thru: Input('any', onThruInput), // makes anything into num event
evt: Input('any', onNumberDesire) evt: Input('any', onNumberDesire)
} }
// outputs: Output('type')
uinum.outputs = { uinum.outputs = {
out: Output('number') out: Output('number')
} }
// here's our input callback, specified in the input constructor
function onThruInput(input){ function onThruInput(input){
if(typeof input == 'number'){ if(typeof input == 'number'){
state.number = input state.number = input
...@@ -44,11 +51,13 @@ function uiNum() { ...@@ -44,11 +51,13 @@ function uiNum() {
} }
function onNumberDesire(){ function onNumberDesire(){
// here's how we fire an output.
uinum.outputs.out.emit(state.number) uinum.outputs.out.emit(state.number)
} }
// gotta give the program this thing we made
return uinum return uinum
} }
// exports // this for node.js's require() function
module.exports = uiNum module.exports = uiNum
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment