flash-string-2

bitrex/xod-menu-system/flash-string-2

No description
flash-string-2
@/flash-string-2
flash-string-2
TXT
TXTstring
To use the node in your project you should have the bitrex/xod-menu-system library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

#pragma XOD dirtiness disable

class FlashStringView : public ListView<char> {
 public:
  class Cursor : public detail::Cursor<char> {
   public:
    Cursor(const char PROGMEM* str) : _ptr(str) {}

    bool isValid() const override {
      return static_cast<bool>(static_cast<char>(pgm_read_byte(_ptr)));
    }

    bool value(char* out) const override {
      *out = static_cast<char>(pgm_read_byte(_ptr));
      return static_cast<bool>(*out);
    }

    void next() override { ++_ptr; }

   private:
    const char PROGMEM* _ptr;
  };

 public:
  FlashStringView(const char PROGMEM* str = nullptr) : _str(str) {}
  FlashStringView(const __FlashStringHelper* str)
      : _str(reinterpret_cast<const char PROGMEM*>(str)) {}

  FlashStringView& operator=(const FlashStringView& rhs) {
    _str = rhs._str;
    return *this;
  }

  virtual Iterator<char> iterate() const override {
    return _str ? Iterator<char>(new Cursor(_str)) : Iterator<char>::nil();
  }

 private:
  friend class Cursor;
  const char PROGMEM* _str;
};


class XStringFlashString : public XString {
 public:
  XStringFlashString(const char PROGMEM* str) : XString(&_view), _view(str) {}

  XStringFlashString(const __FlashStringHelper* str)
      : XString(&_view), _view(str) {}

 private:
  FlashStringView _view;
};

struct State {
};

{{ GENERATED_CODE }}

const char text[] PROGMEM = {"Select? (Y/N)"};
static XStringFlashString out_text = XStringFlashString(text);

void evaluate(Context ctx) {
    if (isSettingUp()) {
        emitValue<output_TXT>(ctx, out_text);
    }
}