Giter Site home page Giter Site logo

Comments (3)

phillipjohnston avatar phillipjohnston commented on May 31, 2024

The way I think we handle this is by providing an F() macro in the base logger, which is defined if there isn't one defined in the logging strategy. This would ensure that logger code doesn't have to change.

We would need a derived strategy which handles F() appropriately, needs to read the string from flash. We can't put this in the base necessarily because we might want to use the logger with unit tests that don't include Arduino.h/WString.h. We should allow swapping to a strategy which just passes these strings through if there's no overriding implementation.

One implication, however, is that the F() macro must be included/defined by the Arduino headers before including the base logger header.

from arduino-logger.

phillipjohnston avatar phillipjohnston commented on May 31, 2024

https://www.arduino.cc/reference/en/language/variables/utilities/progmem/
https://www.nongnu.org/avr-libc/user-manual/pgmspace.html

from arduino-logger.

phillipjohnston avatar phillipjohnston commented on May 31, 2024
size_t Print::print(const __FlashStringHelper *ifsh) {

    PGM_P p = reinterpret_cast<PGM_P>(ifsh);




    char buff[128] __attribute__ ((aligned(4)));

    auto len = strlen_P(p);

    size_t n = 0;

    while (n < len) {

        int to_write = std::min(sizeof(buff), len - n);

        memcpy_P(buff, p, to_write);

        auto written = write(buff, to_write);

        n += written;

        p += written;

        if (!written) {

            // Some error, write() should write at least 1 byte before returning

            break;

        }

    }

    return n;

}

from arduino-logger.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.