An accurate timer for ZeppOS.
中文文档 »
Download
·
Report Bug
·
Request Feature
Table of Contents
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.
The content here will help you get familiar with the program quickly.
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
.
-
To use this library, you need to create a ZeppOS applet project first.refer to the ZeppOS quick start.
-
Please download the latest
zeppos_timer.js
file in the Releases, and placezeppos_timer.js
in thelibs/
directory of the root of the applet -
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
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();
- Multi-language Support for README
- English
- 中文
See the open issues for a full list of proposed features (and known issues).
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!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
XiaomaiTX - [email protected]
Project Link: https://github.com/XiaomaiTX/zeppos-timer