Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How to detect at runtime what protocols are actually included in the build #1851

Closed
tonhuisman opened this issue Aug 7, 2022 · 7 comments · Fixed by #1853
Closed
Labels

Comments

@tonhuisman
Copy link
Contributor

While working on reducing the memory use and .bin size of ESPEasy, also see issue #1849, we are currently working on a way of excluding unused protocols (and that's already working as intended, but needs some fine-tuning, see letscontrolit/ESPEasy#4181).

In ESPEasy, an end-user can select from a list of protocols for received IR codes (that also can be 'learned' automatically), but that list includes all theoretically available protocols, not the list of actually available protocols in the current build.
I have not found a way (yet) how to determine wether a protocol is available or not, so it can either be not included in the list (while parsing over the list as explained in #1181), or reducing that list to the selected/enabled protocols.

If needed I can start a PR to help solve this, f.e. by adding #if DECODE_<protocol> || SEND_<protocol> (or similar, as that's one way to change this) to the required spots in the code.

Not sure if this would be applicable to other parts of the code too.

@NiKiZe
Copy link
Collaborator

NiKiZe commented Aug 7, 2022

I don't think there is any good way to do this.

Maybe we could have a send to gpio0 that returns failure (on non matched switch)

Another way could be to replace the name strings with nulls instead which could be used to skip them?

@tonhuisman
Copy link
Contributor Author

replace the name strings with nulls instead which could be used to skip them?

Maybe that's the simplest way to solve that, I'm already testing the waters on what I can do about this 😃 but it could coincide with the end-of-strings test 🤔, I'll try.

@tonhuisman
Copy link
Contributor Author

replace the name strings with nulls instead which could be used to skip them?

Empty string won't work, as I expected, but using a question mark does, and then checking for the output length > 1 (shortest name is LG), giving this code for filling the vectors that will eventually populate the combobox:

  int size = static_cast<int>(decode_type_t::kLastDecodeType) + 1;
  //...
  int protocolCount = 0;
  for (int i = 0; i < size; i++) {
    const String protocol = typeToString(static_cast<decode_type_t>(i), false);
    if (protocol.length() > 1) {
      decodeTypeOptions.push_back(i);
      decodeTypes.push_back(protocol);
      protocolCount++;
    }
  }

@crankyoldgit
Copy link
Owner

Currently the ways to detect which protocols are supported at runtime are:
bool IRac::isProtocolSupported(const [decode_type_t] protocol) which should be a static method. Unfortunately, that only works for A/C protocols that have have detailed support.

You could abuse/repurpose the IRsend::send() (there are two, one for uint64_t's and one for *uint8_t's). It/They will return true if it was able to send using it.

Note: Both the above are only valid for sending, not receiving/decoding.

Adding something similar to IRac::isProtocolSupported(protocol) to the IRsend & IRrecv classes is the best/better solution. It shouldn't be much effort.

@jimmys01
Copy link
Contributor

jimmys01 commented Aug 8, 2022

How about this:
from the file P035_data_struct.cpp from the ESPeasy project.

String P035_data_struct::listProtocols() { String temp; for (uint32_t i = 0; i <= kLastDecodeType; i++) { if (IRsend::defaultBits((decode_type_t)i) > 0) { temp += typeToString((decode_type_t)i) + ' '; } } return temp;}

String P035_data_struct::listACProtocols() { String temp; for (uint32_t i = 0; i <= kLastDecodeType; i++) { if (hasACState((decode_type_t)i)) { temp += typeToString((decode_type_t)i) + ' '; } } return temp; }

@tonhuisman
Copy link
Contributor Author

tonhuisman commented Aug 8, 2022

IRsend::defaultBits((decode_type_t)i)

That switch then should have the case lines wrapped with #if SEND_<protocol>/#endif to return 0, and smth. similar for IRrecv.

@crankyoldgit
Copy link
Owner

@jimmys01 That won't work really well either. FUJITSU defaults to 0 bits if/when enabled due to the fact of legacy/no standard bit size.

crankyoldgit pushed a commit that referenced this issue Aug 17, 2022
* Inhibit protocol names for not-included protocols
* Move Protocol string-selection to macro, in new file IRmacros.h
* Regenerate IRtext.h

Resolves #1851
crankyoldgit pushed a commit that referenced this issue Aug 17, 2022
…oteESP8266 (#1857)

Most projects use IRremoteESP8266 by including the IRremoteESP8266.h file.
To avoid unexpectedly impacting these projects it is safer to move the include to only where it is to be used.

Ref #1853
Ref #1851
crankyoldgit added a commit that referenced this issue Sep 15, 2022
_v2.8.3 (20220915)_

**[Bug Fixes]**
- Fix `#if` for DECODE_COOLIX48 (#1796)
- Add missing `prev`s to `decodeToState()` (#1783)

**[Features]**
- Add `pause()` function to ESP32 when receiving. (#1871)
- ARGO: Argo add `sendSensorTemp()` (#1858 #1859)
- HAIER_AC160: Experimental detail support. (#1852 #1804)
- BOSCH144: Add IRac class support (#1841)
- Mitsubishi_AC: update left vane in `IRac` class (#1837)
- Basic support for Daikin 312bit/39byte A/C protocol. (#1836 #1829)
- Experimental basic support for Sanyo AC 152 bit protocol. (#1828 #1826)
- GREE: Add model support for `YX1FSF`/Soleus Air Windown A/C (#1823 #1821)
- Experimental basic support for Bosch 144bit protocol. (#1822 #1787)
- Experimental basic support for TCL AC 96 bit protocol. (#1820 #1810)
- Add basic support for clima-butler (52bit) RCS-SD43UWI (#1815 #1812)
- TOTO: An experimental _(s)wipe_ at support for Toto Toilets. (#1811 #1806)
- CARRIER_AC128: Experimental Basic support for Carrier AC 128bit protocol. (#1798 #1797)
- HAIER_AC160: Add basic support for Haier 160bit protocol. (#1805 #1804)
- DAIKIN: Add basic support for 200-bit Daikin protocol. (#1803 #1802)
- FUJITSU: Improve handling of 10C Heat mode. (#1788 #1780)
- FUJITSU: Improve handling of short (command only) messages. (#1784 #1780)

**[Misc]**
- Improve the `_IRREMOTEESP8266_VERSION_VAL` macro (#1875 #1870)
- SONY: Update supported devices. (#1872)
- SAMSUNG: Update supported devices (#1873)
- NEC: Update supported devices (#1874)
- Give IRmacros.h smaller scope to avoid impacting projects using IRremoteESP8266 (#1857 #1853 #1851)
- Inhibit protocol names for not-included protocols (#1853 #1851)
- Test out codeql static analysis (#1842)
- Remove pylint disable=no-self-use (#1817)
- Fujitsu General: update supported devices (#1813)
- DAIKIN: Update supported devices (#1808 #1807)
- Fujitsu: Update supported remote info. (#1801 #1794)
- DAIKIN128: Update supported devices (#1754)
- Voltas: Add link to manual for 122LZF A/C. (#1800 #1799 #1238)
- Daikin128: Additional unit test. (#1795 #1754)
- MIDEA: Update supported devices (#1791 #1790)
crankyoldgit added a commit that referenced this issue Sep 16, 2022
**_v2.8.3 (20220915)_**

**[Bug Fixes]**
- Fix `#if` for DECODE_COOLIX48 (#1796)
- Add missing `prev`s to `decodeToState()` (#1783)

**[Features]**
- Add `pause()` function to ESP32 when receiving. (#1871)
- ARGO: Argo add `sendSensorTemp()` (#1858 #1859)
- HAIER_AC160: Experimental detail support. (#1852 #1804)
- BOSCH144: Add IRac class support (#1841)
- Mitsubishi_AC: update left vane in `IRac` class (#1837)
- Basic support for Daikin 312bit/39byte A/C protocol. (#1836 #1829)
- Experimental basic support for Sanyo AC 152 bit protocol. (#1828 #1826)
- GREE: Add model support for `YX1FSF`/Soleus Air Windown A/C (#1823 #1821)
- Experimental basic support for Bosch 144bit protocol. (#1822 #1787)
- Experimental basic support for TCL AC 96 bit protocol. (#1820 #1810)
- Add basic support for clima-butler (52bit) RCS-SD43UWI (#1815 #1812)
- TOTO: An experimental _(s)wipe_ at support for Toto Toilets. (#1811 #1806)
- CARRIER_AC128: Experimental Basic support for Carrier AC 128bit protocol. (#1798 #1797)
- HAIER_AC160: Add basic support for Haier 160bit protocol. (#1805 #1804)
- DAIKIN: Add basic support for 200-bit Daikin protocol. (#1803 #1802)
- FUJITSU: Improve handling of 10C Heat mode. (#1788 #1780)
- FUJITSU: Improve handling of short (command only) messages. (#1784 #1780)

**[Misc]**
- Improve the `_IRREMOTEESP8266_VERSION_VAL` macro (#1875 #1870)
- SONY: Update supported devices. (#1872)
- SAMSUNG: Update supported devices (#1873)
- NEC: Update supported devices (#1874)
- Give IRmacros.h smaller scope to avoid impacting projects using IRremoteESP8266 (#1857 #1853 #1851)
- Inhibit protocol names for not-included protocols (#1853 #1851)
- Test out codeql static analysis (#1842)
- Remove pylint disable=no-self-use (#1817)
- Fujitsu General: update supported devices (#1813)
- DAIKIN: Update supported devices (#1808 #1807)
- Fujitsu: Update supported remote info. (#1801 #1794)
- DAIKIN128: Update supported devices (#1754)
- Voltas: Add link to manual for 122LZF A/C. (#1800 #1799 #1238)
- Daikin128: Additional unit test. (#1795 #1754)
- MIDEA: Update supported devices (#1791 #1790)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants