Oscillator
Description
This object is being used to create a 'Oscillator' in an app. The object counts to a certain value and stops for a define interval before triggering again.
The objects will now stop running once input parameters are changed.
App Builder Object
Source Code
function start(counter) {
context.counter = counter;
if (context.counter < context.countMax && !context.reset) {
sleep(context.interval, true);
}
}
function onWakeup() {
if (context.counter < context.countMax && !context.reset) {
context.counter += 1;
sleep(context.interval, true);
return [new Date()];
}
return [];
}
function execute() {
// Defaults
if (!context.interval) {
context.interval = parseInt(inPorts[2].value, 10) || 1000;
}
if (!context.countMax) {
context.countMax = parseInt(inPorts[1].value, 10) || 10;
}
if (!context.reset) {
context.reset = false;
}
// Logic
switch (trigger) {
case TRIGGERS.SYSTEM_ASYNC:
return onWakeup();
case 0:
context.reset = false;
start(0);
break;
case 1:
context.countMax = inPorts[1].value;
break;
case 2:
context.interval = inPorts[2].value;
break;
case 3:
context.reset = true;
break;
default: break;
}
return [];
}
In Ports
Position | Name | Message Type | Description |
---|---|---|---|
1 | Start | Trigger | This port is being used to start the 'Oscillator' object. |
2 | Count | Number | This port is being used to define the end count of the 'Oscillator' object. |
3 | Interval | Number | This port is being used to define the sleep interval in milliseconds of the 'Oscillator' object. |
4 | Reset | Trigger | This port is being used to reset the 'Oscillator' object and start from the beginning. |
Out Ports
Position | Name | Message Type | Description |
---|---|---|---|
1 | Trigger | Trigger | This port is being used to send out the message containing the trigger. |
Properties
Name | Description |
---|---|
Object Name | The name of the object on the canvas. |
Show Code View | The switch to turn on code view for the Code Object. |
Duplicate code into custom Code Object |