mirror of
				https://github.com/esp8266/Arduino.git
				synced 2025-10-30 04:26:50 +03:00 
			
		
		
		
	* polledTimeout: add option to use CPU count instead of millis() * use more "using" alias * more c++/clear code, using typename (thanks @devyte) * rename class name to include unit, introduce timeMax() and check it with assert() * remove useless defines * improve api readability, add micro-second unit * update example * mock: emulate getCycleCount, add/fix polledTimeout CI test * + nano-seconds, assert -> message, comments, host test * allow 0 for timeout (enables immediate timeout, fix division by 0) * typo, set member instead of local variable * unify error message * slight change on checkExpired() allows "never expired" also removed printed message, add YieldAndDelay, simplify calculations * remove traces of debug.h/cpp in this PR * include missing <limits> header * back to original expired test, introduce boolean _neverExpires, fix reset(), getTimeout() is invalid * fix expiredOneShot with _timeout==0 check * reenable getTimeout() * expose checkExpired with unit conversion * fix timing comments, move critical code to iram * add member ::neverExpires and use it where relevant * improve clarity * remove exposed checkExpired(), adapt LEAmDNS with equivalent * add API ::resetToNeverExpires(), use it in LEAmDNS * remove offending constness from ::flagged() LEAmDNS (due do API fix in PolledTimeout) * simplify "Fast" base classes * minor variable rename * Fix examples * compliance with good c++ manners * minor changes for consistency * add missing const * expired() and bool() moved to iram * constexpr compensation computing * add/update comments * move neverExpires and alwaysExpired
		
			
				
	
	
		
			38 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			38 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| // Wire Master Reader
 | |
| // by devyte
 | |
| // based on the example of the same name by Nicholas Zambetti <http://www.zambetti.com>
 | |
| 
 | |
| // Demonstrates use of the Wire library
 | |
| // Reads data from an I2C/TWI slave device
 | |
| // Refer to the "Wire Slave Sender" example for use with this
 | |
| 
 | |
| // This example code is in the public domain.
 | |
| 
 | |
| 
 | |
| #include <Wire.h>
 | |
| #include <PolledTimeout.h>
 | |
| 
 | |
| #define SDA_PIN 4
 | |
| #define SCL_PIN 5
 | |
| const int16_t I2C_MASTER = 0x42;
 | |
| const int16_t I2C_SLAVE = 0x08;
 | |
| 
 | |
| void setup() {
 | |
|   Serial.begin(115200);  // start serial for output
 | |
|   Wire.begin(SDA_PIN, SCL_PIN, I2C_MASTER);        // join i2c bus (address optional for master)
 | |
| }
 | |
| 
 | |
| void loop() {
 | |
|   using periodic = esp8266::polledTimeout::periodicMs;
 | |
|   static periodic nextPing(1000);
 | |
| 
 | |
|   if (nextPing) {
 | |
|     Wire.requestFrom(I2C_SLAVE, 6);    // request 6 bytes from slave device #8
 | |
| 
 | |
|     while (Wire.available()) { // slave may send less than requested
 | |
|       char c = Wire.read(); // receive a byte as character
 | |
|       Serial.print(c);         // print the character
 | |
|     }
 | |
|   }
 | |
| }
 |