4000n
May 21, 2023, 12:11pm
1
Hi,
I store the html ui with progmem.
const char htmlUX[] PROGMEM = R"UX0129(
<!DOCTYPE HTML><html>
my html code here
</body>
</html>
)UX0129";
However according to the hardware board and number of sensors, I need 2 interfaces with are very similiar.
So far I use this pragma compiler solution can be
#if myboard == 1
const char htmlUXforBoard1[] PROGMEM = R"UXbord1(
my code for board1
)UXbord1;
#else
const char htmlUXforBoard2[] PROGMEM = R"UXbord2(
board2 code
)UXbord2;
#endif
Because, most of the code are the same, I wish to have pragma if when code actually differs, something like
const char htmlUX[] PROGMEM = R"UX(
shared html code
#if myboard == 1
board1 code
#else
board2 code
#endif
next part of shared html code
#if myboard == 1
board1 code specific
#else
board2 code specific
#endif
)UX;
Thanks
4000n
May 21, 2023, 9:43pm
3
Won't work as in code their are double and single quotes into the PROGMEM(that's the very beauty of it, you can assign an entire html web page code with css and js), for instance:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
you can't write, something as such as the #if #else are part of the string, so an end quote is not treated as end, progmem as a start and end tag scheme:
To illustrate, the following is just a string as is:
const char htmlUX[] PROGMEM = R"UX(
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
#if myboard == 1
<script>
document.getElementById("HWL").innerText = "this is board 1 app";
</script>
"
#else
"board2 code"
#endif
)UX;
Does that work with Raw String Literals as well as normal string literals? Can you actually mix them? Interesting, if so.
4000n
May 25, 2023, 9:04pm
7
Please, try this:
#include <Arduino.h>
#define TOSTR_(...) #__VA_ARGS__
#define STRINGIFY(...) TOSTR_(__VA_ARGS__)
const char htmlUX[] PROGMEM = "is this a compiler"
#ifdef MYBOARD
"bug"
#else
"with or without the degree char in the following"
#endif
STRINGIFY(
<input name="txtGt" type="number" value="39.5" max="42" step="0.5" style="width:160px;">°C<br>
)
;