mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 15:12:06 +00:00 
			
		
		
		
	Turn off PN532 RF field when not expecting a tag (#1046)
* Turn off PN532 RF field when not expecting a tag Avoids interference with Wifi connectivity of nearby devices. * Rename turn_off_rf_ method * documented off command bytes Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>
This commit is contained in:
		| @@ -86,6 +86,8 @@ void PN532::setup() { | |||||||
|     this->mark_failed(); |     this->mark_failed(); | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   this->turn_off_rf_(); | ||||||
| } | } | ||||||
|  |  | ||||||
| void PN532::update() { | void PN532::update() { | ||||||
| @@ -114,13 +116,16 @@ void PN532::loop() { | |||||||
|  |  | ||||||
|   if (read.size() <= 2 || read[0] != 0x4B) { |   if (read.size() <= 2 || read[0] != 0x4B) { | ||||||
|     // Something failed |     // Something failed | ||||||
|  |     this->turn_off_rf_(); | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   uint8_t num_targets = read[1]; |   uint8_t num_targets = read[1]; | ||||||
|   if (num_targets != 1) |   if (num_targets != 1) { | ||||||
|     // no tags found or too many |     // no tags found or too many | ||||||
|  |     this->turn_off_rf_(); | ||||||
|     return; |     return; | ||||||
|  |   } | ||||||
|  |  | ||||||
|   // const uint8_t target_number = read[2]; |   // const uint8_t target_number = read[2]; | ||||||
|   // const uint16_t sens_res = uint16_t(read[3] << 8) | read[4]; |   // const uint16_t sens_res = uint16_t(read[3] << 8) | read[4]; | ||||||
| @@ -150,6 +155,17 @@ void PN532::loop() { | |||||||
|     format_uid(buf, nfcid, nfcid_length); |     format_uid(buf, nfcid, nfcid_length); | ||||||
|     ESP_LOGD(TAG, "Found new tag '%s'", buf); |     ESP_LOGD(TAG, "Found new tag '%s'", buf); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   this->turn_off_rf_(); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void PN532::turn_off_rf_() { | ||||||
|  |   ESP_LOGVV(TAG, "Turning RF field OFF"); | ||||||
|  |   this->pn532_write_command_check_ack_({ | ||||||
|  |       0x32,  // RFConfiguration | ||||||
|  |       0x1,   // RF Field | ||||||
|  |       0x0    // Off | ||||||
|  |   }); | ||||||
| } | } | ||||||
|  |  | ||||||
| float PN532::get_setup_priority() const { return setup_priority::DATA; } | float PN532::get_setup_priority() const { return setup_priority::DATA; } | ||||||
|   | |||||||
| @@ -55,6 +55,8 @@ class PN532 : public PollingComponent, | |||||||
|  |  | ||||||
|   bool read_ack_(); |   bool read_ack_(); | ||||||
|  |  | ||||||
|  |   void turn_off_rf_(); | ||||||
|  |  | ||||||
|   bool requested_read_{false}; |   bool requested_read_{false}; | ||||||
|   std::vector<PN532BinarySensor *> binary_sensors_; |   std::vector<PN532BinarySensor *> binary_sensors_; | ||||||
|   std::vector<PN532Trigger *> triggers_; |   std::vector<PN532Trigger *> triggers_; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user