/zeppos-timer

An accurate timer for ZeppOS. 一个适用于ZeppOS的准确的计时器

Primary LanguageJavaScriptMIT LicenseMIT

Contributors Forks Stargazers Issues MIT License


zeppos_timer.js

An accurate timer for ZeppOS.
中文文档 »

Download · Report Bug · Request Feature

Table of Contents
  1. About The zeppos_timer.js
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact

About The zeppos_timer.js

An accurate timer for ZeppOS. ZeppTimer is a small and refined JavaScript class that provides an accurate timer for the ZeppOS system.

Here's why:

  • In all versions of ZeppOS, there is a significant time discrepancy between the system's timer and the actual time due to underlying issues with the system. To achieve more accurate timing, I implemented a simple but effective approach to reduce timing errors and packaged it into ZeppTimer.

  • Furthermore, in ZeppOS 2.x, the official approach to timer components was replaced with setTimeOut and cleanTimeOut, requiring logic adjustments when migrating ZeppOS 1.0 applications that use timers to ZeppOS 2.x and above. Using the ZeppTimer library can save developers the cost of migration.

Use the Usage to easily get started.

(back to top)

Getting Started

The content here will help you get familiar with the program quickly.

Prerequisites

Before using this library, please make sure you already have an understanding of ZeppOS applet development, you can refer to the ZeppOS official documentation. Also, you need a code editor(Like Microsoft VSCode) and knowledge of JavaScript.

Installation

  1. To use this library, you need to create a ZeppOS applet project first.refer to the ZeppOS quick start.

  2. Please download the latest zeppos_timer.js file in the Releases, and place zeppos_timer.js in the libs/ directory of the root of the applet

  3. Add a reference to zeppos_timer.js in the project

import { ZeppTimer } from "../libs/zeppos_timer"; // Replace with the path to your zeppos_timer.js

At this point, you're ready to use the zeppos_timer.js library

(back to top)

Usage

Then create a new instance of the class:

const timer = new ZeppTimer(() => {
  console.log("Tick!");
}, 1000);

The first argument to the ZeppTimer constructor is a callback function that will be called on each tick of the timer. The second argument is the time interval between ticks, in milliseconds.

To start the timer, call the start method:

timer.start();

To stop the timer, call the stop method:

timer.stop();

(back to top)

Roadmap

  • Multi-language Support for README
    • English
    • 中文

See the open issues for a full list of proposed features (and known issues).

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE for more information.

(back to top)

Contact

XiaomaiTX - i@lenrome.cn

Project Link: https://github.com/XiaomaiTX/zeppos-timer

(back to top)