diff --git a/CHANGELOG.md b/CHANGELOG.md index b5a3ca3c2..8762f4b97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file. ### Added - Allow MCP230xx pinmode from output to input (#11104) - SML VBUS support (#11125) +- Command ``Sensor80 1 <0..7>`` to control MFRC522 RFID antenna gain from 18dB (0) to 48dB (7) (#11073) ### Changed - TuyaMcu dimmer timeout (#11121) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 2ae0f984a..aebea7960 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -82,6 +82,7 @@ The attached binaries can also be downloaded from http://ota.tasmota.com/tasmota ### Added - Allow MCP230xx pinmode from output to input [#11104](https://github.com/arendst/Tasmota/issues/11104) - SML VBUS support [#11125](https://github.com/arendst/Tasmota/issues/11125) +- Command ``Sensor80 1 <0..7>`` to control MFRC522 RFID antenna gain from 18dB (0) to 48dB (7) [#11073](https://github.com/arendst/Tasmota/issues/11073) ### Changed - TuyaMcu dimmer timeout [#11121](https://github.com/arendst/Tasmota/issues/11121) diff --git a/tasmota/xsns_80_mfrc522.ino b/tasmota/xsns_80_mfrc522.ino index 29207819c..3ad92f4d9 100644 --- a/tasmota/xsns_80_mfrc522.ino +++ b/tasmota/xsns_80_mfrc522.ino @@ -126,6 +126,36 @@ void RC522Show(void) { } #endif // USE_WEBSERVER +/*********************************************************************************************\ + * Supported commands for Sensor80: + * + * Sensor80 1 - Show antenna gain + * Sensor80 1 - Set antenna gain 0..7 (default 4) +\*********************************************************************************************/ + +bool RC522Command(void) { + bool serviced = true; + char argument[XdrvMailbox.data_len]; + + for (uint32_t ca = 0; ca < XdrvMailbox.data_len; ca++) { + if ((' ' == XdrvMailbox.data[ca]) || ('=' == XdrvMailbox.data[ca])) { XdrvMailbox.data[ca] = ','; } + } + + switch (XdrvMailbox.payload) { + case 1: // Antenna gain + uint8_t gain; + if (strchr(XdrvMailbox.data, ',') != nullptr) { + gain = strtol(ArgV(argument, 2), nullptr, 10) & 0x7; + Mfrc522->PCD_SetAntennaGain(gain << 4); + } + gain = Mfrc522->PCD_GetAntennaGain() >> 4; // 0..7 + Response_P(PSTR("{\"Sensor80\":{\"Gain\":%d}}"), gain); + break; + } + + return serviced; +} + /*********************************************************************************************\ * Interface \*********************************************************************************************/ @@ -145,6 +175,11 @@ bool Xsns80(uint8_t function) { RC522ScanForTag(); } break; + case FUNC_COMMAND_SENSOR: + if (XSNS_80 == XdrvMailbox.index) { + result = RC522Command(); + } + break; #ifdef USE_WEBSERVER case FUNC_WEB_SENSOR: RC522Show();