mirror of
				https://github.com/Pablo2048/Interval.git
				synced 2025-10-31 00:12:36 +01:00 
			
		
		
		
	Podrobnejsi popis v readme, doplnen reload.
This commit is contained in:
		
							
								
								
									
										2
									
								
								LICENSE
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								LICENSE
									
									
									
									
									
								
							| @@ -1,6 +1,6 @@ | ||||
| MIT License | ||||
|  | ||||
| Copyright (c) 2018  | ||||
| Copyright (c) 2014, 2016, 2018 Pavel Brychta http://www.xpablo.cz | ||||
|  | ||||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
| of this software and associated documentation files (the "Software"), to deal | ||||
|   | ||||
| @@ -1,2 +1,7 @@ | ||||
| # Interval | ||||
| Arduino knihovna pro časování pomocí intervalů | ||||
| Koncepce programové konstrukce aplikace pro Arduino spočívá ve dvou hlavních metodách – **setup()** a **loop()**, ve které program neustále běží. | ||||
| Pro pohodlnější práci s obsluhou periodických procesů jsem napsal jednoduchou knihovnu, která tyto úkoly umožňuje napsat velmi elegantním způsobem. | ||||
| Knihovna **Interval** vytváří časovací objekty a zpřístupňuje dvě metody – metodu **set** a metodu **expired**. | ||||
| Metoda **set** se používá k nastavení timeoutu a definici začátku časování, metoda **expired** pak slouží k ověření, zda nastavený interval již vypršel. | ||||
| Zajímavostí je, že knihovna korektně ošetřuje přetečení vnitřního milisekundového čítače, takže nehrozí nebezpečí špatného časování i při velmi dlouhé době chodu zařízení. | ||||
|   | ||||
| @@ -10,19 +10,19 @@ extern "C" { | ||||
| uint32_t Interval::remains(void) | ||||
| { | ||||
|  | ||||
| 	return timeout - (millis() - timefrom); | ||||
| 	return _timeout - (millis() - _timefrom); | ||||
| } | ||||
|  | ||||
| uint32_t Interval::elapsed(void) | ||||
| { | ||||
|  | ||||
| 	return millis() - timefrom; | ||||
| 	return millis() - _timefrom; | ||||
| } | ||||
|  | ||||
| bool Interval::expired(void) | ||||
| { | ||||
|  | ||||
| 	if ((millis() - timefrom) >= timeout) | ||||
| 	if ((millis() - _timefrom) >= _timeout) | ||||
| 		return true; | ||||
| 	else | ||||
| 		return false; | ||||
| @@ -31,6 +31,14 @@ bool Interval::expired(void) | ||||
| void Interval::set(uint32_t tmout) | ||||
| { | ||||
|  | ||||
| 	timefrom = millis(); | ||||
| 	timeout = tmout; | ||||
|   _reload = tmout; | ||||
| 	_timefrom = millis(); | ||||
| 	_timeout = _reload; | ||||
| } | ||||
|  | ||||
| void Interval::reload(void) | ||||
| { | ||||
|  | ||||
|   _timefrom = millis(); | ||||
|   _timeout = _reload; | ||||
| } | ||||
|   | ||||
| @@ -3,13 +3,9 @@ | ||||
| #define interval_h | ||||
|  | ||||
| /* Interval | ||||
|  * Copyright (C) 2014, 2016  Pavel Brychta http://www.xpablo.cz | ||||
|  * Copyright (C) 2014, 2016, 2018  Pavel Brychta http://www.xpablo.cz | ||||
|  * | ||||
|  * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License | ||||
|  * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. | ||||
|  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||||
|  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details. | ||||
|  * You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses  | ||||
|  * This program is free software: you can redistribute it and/or modify it under the terms of the MIT License | ||||
|  */ | ||||
|  | ||||
| #include <inttypes.h> | ||||
| @@ -17,11 +13,13 @@ | ||||
| class Interval | ||||
| { | ||||
|   protected: | ||||
| 	uint32_t timefrom; | ||||
| 	uint32_t timeout; | ||||
| 	uint32_t _timefrom; | ||||
| 	uint32_t _timeout; | ||||
|   uint32_t _reload; | ||||
|   public: | ||||
| 	bool expired(void); | ||||
| 	void set(uint32_t tmout); | ||||
|   void reload(void); | ||||
| 	uint32_t elapsed(void); | ||||
| 	uint32_t remains(void); | ||||
| }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user