npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

plc-ton

v0.1.0

Published

plc based ton timer

Downloads

3

Readme

ton

A TON plc based timer for javascript.

The TON (On-Delay Timer) type of timer is used to control on-delay actions. When the Timer start, it wait a preset period of time to turn on is output.

Installation

$ npm install plc-ton --save

Basic Usage

const Ton = require('plc-ton');
const Wiring = require('wiring.io');

var myTimer = new Ton(1000, function(){
		console.log('1s');
	})

myTimer.Start();

TON constructor([preset [, retentive [, callback [, ...args]]]])

  • preset {number | string}
  • retentive {boolean}
  • callback {function}
  • args

preset Defines the preset value for the timer in ms. Default is 1000 (1s).

retentive Set true or false the retentive behavior. When the retentive is false (default), the property Ton.V is reset when Ton.Stop is called. Counting restarts from 0. When the retentive is true, the timer retains its value when Ton.Stop is called before the Preset value is reached. Counting restarts from this value.

callback Function to call when the preset value is reached.

args arguments to pass to a callback function.

let timer1 = new Ton();
//timer whit preset value of 1,5s and retentive behavior
let timer2 = new Ton(1500, true);
//timer whit preset value of 500ms and a callback functions whit argument
let timer3 = new Ton('500', Foo, 'running');

Timer Atributes

isRetentive

Type: {boolean}

Indicate the retentive behavior of the timer. See retentive description on constructor secction.

isRunning

Type: {boolean}

Indicate the running status of the timer.

P

Type: {number}

Indicate the preset value of the timer.

Q

Type: {boolean}

Timer output. Indicate the preset value was reached.

tick

Type: {Wiring.Signal}

A signal that is emited by timer when the preset value was reached. See wiring.io for mor details about signal and slots.

V

Type: {number}

Value that increments from 0 to the preset value timer.P when the timer is running. The value can be read and tested, but not written to

Timer Methods

Start()

Start the timer. Similar to put in true the in input of a plc's ton timer. Returns a Boolean indicating whether or not the timer was started.

let timer1 = new Ton(2000)
timer1.Start() //  true - the timer started

setTimeout(function(){
		timer1.start() //  false - the timer is already started
	}, 1000);

Stop()

Stop or pause (depents of retentive behavior) a timer. Similar to the start() method, Stop() returns a Boolean indicating whether or not the timer was stopped.

let timer1 = new Ton(2000)
timer1.Stop() // false - the timer is already stopped
timer1.Start() //  true - the timer started
timer1.Stop() // true - the timer stopped

SetAction(callback [, ...args])

Set a callback function to call when the preset value is reached. The callback function will be called whit the aruments passed to SetAcction.

function Report(action, date1){
	console.log(action + ': ' + (Date.now() - date1));
}
let timer1 = new Ton(2000)
timer1.SetAction(Report, 'Total Time', Date.now());
timer1.Start()
//Total Time: 2000

Development

Pull requests are welcome.

Get the code

$ git clone https://github.com/hsocarras/ton.git

Install the dependencies

$ npm install

Run the tests

$ npm test

Contributing

If you have a suggestion or found a issue, let us known and create an issue

License

This project is licensed under the MIT License - see the LICENSE.md file for details