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

Extensions for the Arduino #3

Open
fletchjp opened this issue Jan 4, 2023 · 9 comments
Open

Extensions for the Arduino #3

fletchjp opened this issue Jan 4, 2023 · 9 comments

Comments

@fletchjp
Copy link

fletchjp commented Jan 4, 2023

Hi. Thank you for micro-moustache. I am attaching a file with a modified version for your information.

  1. I have added a library.properties file for use by the Arduino IDE.
  2. I have changed the include directory to src.
  3. There is an extra header file called moustach_code.h which adds new capabilities.

I can also send you some examples using the extensions if you wish.

I am running code on an Arduino UNO.

Happy New Year

John Fletcher
micro-moustache.zip

@rzeldent
Copy link
Owner

rzeldent commented Jan 5, 2023 via email

@fletchjp
Copy link
Author

fletchjp commented Jan 5, 2023

Rene

Thank you, I will do that. It will take a few days as I have a talk to give on Sunday. I will make some examples. I suggest I bump the version number. Shall I make it 1.1.0 as I have not changed your interface?

@rzeldent
Copy link
Owner

rzeldent commented Jan 6, 2023 via email

@fletchjp
Copy link
Author

Rene

I have now made an example for my extra functions which are in a separate header file. I have changed the version number to 1.1.0 as the interface is not changed. I have added new material to the README file to describe how to use the new functions.

I do need to change the name of the folder holding the headers from 'include' to 'src' and I don't know whether that will break use on other hardware than a UNO.

I can make this into a pull request although I am not sure how best to do this.

In the meantime I am attaching a ZIP file with a copy of the library as I now have it configured. Please let me know whether this makes sense to you.

Best wishes

John
micro-moustache.zip

@rzeldent
Copy link
Owner

rzeldent commented Jan 14, 2023 via email

@fletchjp
Copy link
Author

fletchjp commented Jan 14, 2023

Rene

The difference is that I am running on an Arduino UNO where the messages are regarded as warnings because of the use of -fpermissive in the Arduino IDE setup. This applies on both the Arduino IDE 1.8.19 and 2.0.3 which use the same configuration file, for example

C:\Users\john\Documents\Arduino\examples\moustache_values\moustache_values.ino:49:40: warning: passing 'const String' as 'this' argument discards qualifiers [-fpermissive]
number_value[0].value = String(number);

I think you are working on a different system which provides different settings.

I have tried compiling the example for an Arduino DUE and that fails. The message is the same except that it is an error.

The reason it fails for the DUE is that -fpermissive is not defined. When I add it to the line compiler.cpp.flags in platform.txt then the errors become warnings and it compiles.

platform.txt is hidden away in the user's AppData\Local\Arduino15\packages on a Windows computer

I have tried in the past to find out just what -fpermissive does allow on different systems without success,

It may be that you can change the settings on your system, or just label my work for Arduino UNOs etc. I can now use a DUE as a test system to see if I can get around this.

I have taken the other approach and looked for a work around for the error and not found one (yet).

What do you think?

John

@fletchjp
Copy link
Author

I have had a look at ways to work around this problem without using -fpermissive. I have not found a solution.

I don't know what you think. Perhaps I should abandon this idea, except for the example for error messages.

John

@rzeldent
Copy link
Owner

rzeldent commented Jan 23, 2023 via email

@rzeldent
Copy link
Owner

rzeldent commented Jan 28, 2023

Hi John,

I looked again at you extensions and basically what you want to do is not recreate the array but be able to update a particular value. This makes a lot of sense if you have a single/global instance.
So, maybe the const is too strict when using the moustache values. To overcome this I made the moustache_variable_t's value parameter not const, so it is posible to change it. I think this will make it easier to work with this library.

When using this version, the array is no longer allowed to be const. So below an example how to use it.
You can use your templates to change the values and then just call render.

Please give it a go and let me know what you think about this change see branch: feature/no_const.

Kind regards,

Rene

void setup()
{
    const char *taxes =
        "Hello {{name}}\n"
        "You have just won {{value}} dollars!\n"
        "{{#in_ca}}"
        "Well, {{taxed_value}} dollars, after taxes.\n"
        "{{/in_ca}}"
        "{{^in_ca}}"
        "And no taxes paid!\n"
        "{{/in_ca}}";

    moustache_variable_t substitutions[] = {
        {"name", "Chris"},
        {"value", String(10000)},
        {"taxed_value", String(10000 - (10000 * 0.4))},
        {"in_ca", String(true)}};

    auto result = moustache_render(taxes, substitutions);
    Serial.println(result);

    substitutions[3].value = String(false);
    result = moustache_render(taxes, substitutions);
    Serial.println(result);
}

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