Commit 55f838b3 authored by Nicolas Biri's avatar Nicolas Biri

Upgrade references

parent 40f3346f
......@@ -8,7 +8,7 @@ let Class, Model, Enum
Model = JSMF.Model
Class = JSMF.Class
Enum = JSMF.Enum
}).call();
}).call()
const Signal = new Enum('Signal', ['LOW', 'HIGH'])
......
......@@ -25,8 +25,8 @@ on.transition = tOn
const aOff = AML.Action.newInstance({value: AML.Signal.LOW, actuator: led})
const tOff = AML.Transition.newInstance({value: AML.Signal.HIGH, sensor: button})
const off = AML.State.newInstance({name: 'off'})
on.action = aOff
on.transition = tOff
off.action = aOff
off.transition = tOff
/*
......@@ -41,15 +41,15 @@ tOff.next = on
*/
const switchApp = AML.App.newInstance({
name: 'Switch!',
bricks: [button, led],
states: [on, off],
initial: off
name: 'Switch!',
bricks: [button, led],
states: [on, off],
initial: off
})
const Switch = new Model('Switch', AML.ArduinoML, switchApp, true)
module.exports = {
Switch: Switch,
switchApp: switchApp
Switch: Switch,
switchApp: switchApp
}
{
"name": "foo",
"version": "0.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "BSD-2-Clause"
}
'use strict'
const JSMF = require('../../src/index')
let Class, Model, Enum
(function() {
Model = JSMF.Model
Class = JSMF.Class
}).call()
const Member = new Class('Member', [], {firstName : String})
const Family = new Class('Family', [], {lastName : String},
{ father: { type: Member
, cardinality: JSMF.Cardinality.one
, opposite: 'familyFather'
, oppositeCardinality: JSMF.Cardinality.optional
}
, mother: { type: Member
, cardinality: JSMF.Cardinality.one
, opposite: 'familyMother'
, oppositeCardinality: JSMF.Cardinality.optional
}
, sons: { type: Member
, cardinality: JSMF.Cardinality.any
, opposite: 'familySon'
, oppositeCardinality: JSMF.Cardinality.optional
}
, daughters: { type: Member
, cardinality: JSMF.Cardinality.any
, opposite: 'familyDaughter'
, oppositeCardinality: JSMF.Cardinality.optional
}
})
const Families = new Model('Families', undefined, [Family, Member])
module.exports = {Families}
'use strict'
const JSMF = require('../../src/index')
let Class, Model, Enum
(function() {
Model = JSMF.Model
Class = JSMF.Class
}).call()
const Person = new Class('Person', [], {fullName: String})
const Male = new Class('Male', Person)
const Female = new Class('Male', Person)
const Persons = new Model('Persons', undefined, [Person, Male, Female])
module.exports = {Persons}
'use strict';
var AML = require('./MMArduinoML.js')
var Model;
(function() {
var JSMF = require('../../src/index');
Model = JSMF.Model;
}).call();
var switchExample = new Model('Switch!');
switchExample.setReferenceModel(AML.ArduinoML);
var button = AML.Sensor.newInstance({name: 'button', pin: 9});
switchExample.add(button);
var led = AML.Actuator.newInstance({name: 'led', pin: 12});
switchExample.add(led);
/*
* on state
*/
var aOn = AML.Action.newInstance({value: AML.Signal.HIGH, actuator: led});
switchExample.add(aOn);
var tOn = AML.Transition.newInstance({value: AML.Signal.HIGH, sensor: button});
switchExample.add(tOn);
var on = AML.State.newInstance({name: 'on', action: aOn, transition: tOn})
switchExample.add(on);
/*
* off state
*/
var aOff = AML.Action.newInstance({value: AML.Signal.LOW, actuator: led});
switchExample.add(aOff);
var tOff = AML.Transition.newInstance({value: AML.Signal.HIGH, sensor: button});
switchExample.add(tOff);
var off = AML.State.newInstance({name: 'off', action: aOff, transition: tOff})
switchExample.add(off);
/*
* set transitions
*/
tOn.setNext(off);
tOff.setNext(on);
/*
* define app
*/
var switchApp = AML.App.newInstance({
name: 'Switch!',
bricks: [button, led],
states: [on, off],
initial: off
});
switchExample.add(switchApp);
module.exports = {
switchExample: switchExample,
switchApp: switchApp
}
'use strict';
var Class;
var Model;
var Enum;
(function() {var JSMF = require('../../src/index');
Model = JSMF.Model;
Class = JSMF.Class;
Enum = JSMF.Enum;
}).call();
var ArduinoML = new Model('ArduinoML');
var Signal = new Enum('Signal', {LOW: 0, HIGH: 1});
var NamedElement = Class.newInstance('NamedElement', [], {name: String});
var App = Class.newInstance('App', NamedElement);
var State = Class.newInstance('State', NamedElement);
App.setReference('states', State, -1);
App.setReference('initial', State, 1);
var Brick = Class.newInstance('Brick', NamedElement, {pin: Number});
var Action = Class.newInstance('Action', [], {value: Number});
State.setReference('action', Action, -1);
var Transition = Class.newInstance('Transition', [], {value: Number});
Transition.setReference('next', State, 1);
State.setReference('transition', Transition, 1);
var Sensor = Class.newInstance('Sensor', Brick);
Transition.setReference('sensor', Sensor, 1);
var Actuator = Class.newInstance('Actuator', Brick);
Action.setReference('actuator', Actuator, 1);
App.setReference('bricks', Brick, -1);
ArduinoML.setModellingElements([Signal, NamedElement, App, State, Brick, Action, Transition, Sensor, Actuator]);
module.exports = {
ArduinoML: ArduinoML,
Signal: Signal,
NamedElement: NamedElement,
App: App,
State: State,
Brick: Brick,
Action: Action,
Transition: Transition,
Sensor: Sensor,
Actuator: Actuator
}
# The ArduinoML Example
This directory contains 2 javascript file:
- `MMArduinoMl.js`, which implements the (ArduinoML model)[https://github.com/mosser/ArduinoML-kernel/tree/master/docs];
- `MArduinoML`, which implement the simple "switch" arduino app, described on the same document.
{
"name": "foo",
"version": "0.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "BSD-2-Clause"
}
......@@ -25,12 +25,12 @@
"author": "Jean-Sebastien Sottet <jean-sebastien.sottet@list.lu> (http://www.list.lu/)",
"license": "MIT",
"dependencies": {
"lodash": "^4.1.0",
"uuid": "^2.0.1"
"lodash": "^4.15.0",
"uuid": "^2.0.3"
},
"devDependencies": {
"should": "^7.1.1",
"mocha": "^2.4.5",
"should": "^11.1.0",
"mocha": "^3.0.2",
"assert": "^1.3.0"
}
}
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