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

IR lib FlashString handling #2502

Closed
kmihaylov opened this issue Apr 18, 2022 · 5 comments
Closed

IR lib FlashString handling #2502

kmihaylov opened this issue Apr 18, 2022 · 5 comments

Comments

@kmihaylov
Copy link
Contributor

kmihaylov commented Apr 18, 2022

This is not Sming issue, but something that I can't figure out. I'm trying to port the latest IR lib to Sming and I stuck with IR's FlashStrings not built with Sming.

First let me show the compiler error:

Building /home/opt/Sming/Sming/out/Esp8266/debug/lib/clib-IR.a
C+ /home/opt/Sming/Sming/Libraries/IR/src/ir_Carrier.cpp
/home/opt/Sming/Sming/Libraries/IR/src/ir_Carrier.cpp: In member function 'String IRCarrierAc64::toString() const':
/home/opt/Sming/Sming/Libraries/IR/src/ir_Carrier.cpp:493:38: error: could not convert 'kPowerStr' from 'const __FlashStringHelper* const' to 'String'
  493 |   result += addBoolToString(_.Power, kPowerStr, false);
      |                                      ^~~~~~~~~
      |                                      |
      |                                      const __FlashStringHelper* const

The variable kPowerStr is defined in IRtext.cpp. I'm posting the macros:

#define IRTEXT_CONST_BLOB_NAME(NAME)\
    NAME ## Blob

#define IRTEXT_CONST_BLOB_DECL(NAME)\
    const char IRTEXT_CONST_BLOB_NAME(NAME) [] PROGMEM

#define IRTEXT_CONST_BLOB_PTR(NAME)\
    IRTEXT_CONST_PTR(NAME) {\
        IRTEXT_CONST_PTR_CAST(IRTEXT_CONST_BLOB_NAME(NAME)) }

#define IRTEXT_CONST_STRING(NAME, VALUE)\
    static IRTEXT_CONST_BLOB_DECL(NAME) { VALUE };\
    IRTEXT_CONST_PTR(NAME) PROGMEM {\
        IRTEXT_CONST_PTR_CAST(&(IRTEXT_CONST_BLOB_NAME(NAME))[0]) }

and

IRTEXT_CONST_STRING(kPowerStr, D_STR_POWER);  ///< "Power"

Then Eclipse evaluated the macro to:

static const char kPowerStrBlob [] __attribute__((aligned(4))) { "Power" };
const char* const kPowerStr __attribute__((aligned(4))) {&(kPowerStrBlob)[0] }

where PROGMEM is(?) __attribute__((aligned(4))) (Looking in the header files I thing it should be something longer...?

I don't know how const char* const went to const __FlashStringHelper* const. I'm reading https://sming.readthedocs.io/en/latest/framework/core/pgmspace.html w/o luck.

@mikee47
Copy link
Contributor

mikee47 commented Apr 18, 2022

The constructor is delcared explicit String(flash_string_t pstr) so you'll need to modify code like this:

result += addBoolToString(_.Power, String(kPowerStr), false);

@mikee47
Copy link
Contributor

mikee47 commented Apr 19, 2022

On further inspection, the FlashString library can handle all this more easily. See https://github.com/mikee47/IRremoteESP8266/tree/sming. Builds but not tested.

@kmihaylov
Copy link
Contributor Author

kmihaylov commented Apr 19, 2022

@mikee47 thanks.

Do I understand properly that String(kPowerStr) will copy the flash string to RAM?

The library heavily uses *Str like the above mentioned kPowerStr. I have no problem to modify all the files to String(...), but is this the best way? Is this some Arduino thing that the flash strings can be directly used?


Just saw your commit. I'll test in the afternoon.

@kmihaylov
Copy link
Contributor Author

IR receive works just fine. I can solder second board to check IR send.

@mikee47
Copy link
Contributor

mikee47 commented Apr 12, 2024

Assuming resolved

@mikee47 mikee47 closed this as completed Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants