C++ code: additional changes

pull/1/head
Christian Seiler 4 weeks ago
parent 5e695cf99a
commit 4ec91564b8
  1. 18
      Specification.rst
  2. 8
      cpp/src/monoformat_structured.cpp
  3. 119
      cpp/src/monoformat_structured.hpp

@ -43,7 +43,8 @@ All sections and elements are aligned to 32 bits. In doubt padding bytes with va
Fonts Fonts
----- -----
? All fonts must be in the U8G2 font format that can be parsed by the u8g2-fonts Rust crate, see
<https://github.com/Finomnis/u8g2-fonts/> for details.
File Header File Header
=========== ===========
@ -194,7 +195,14 @@ Custom Font
This section defines a custom font that is to be used within this file. Any custom font used by draw elements MUST occur in the file before the font is used. This section defines a custom font that is to be used within this file. Any custom font used by draw elements MUST occur in the file before the font is used.
font support t.b.d. The section consists of the following type-specific header:
0 1 2 3
+------------------------+------------------------+------------------------+------------------------+
0 | Actual Size of Font (octets) | Reserved |
+------------------------+------------------------+------------------------+------------------------+
This is followed by the font data itself in the format. The actual size indicates how long the font actually is in octets, which may be smaller than the padded length of the section indicates.
Elements Elements
======== ========
@ -371,11 +379,7 @@ Horizontally Scrolling Text
+------------------------+------------------------+------------------------+------------------------+ +------------------------+------------------------+------------------------+------------------------+
8 | Height | Flags | Scroll Speed | 8 | Height | Flags | Scroll Speed |
+------------------------+------------------------+------------------------+------------------------+ +------------------------+------------------------+------------------------+------------------------+
12 | Font Name Size | Text Length | 12 | Font Index | Text ... |
+------------------------+------------------------+------------------------+------------------------+
16 | Font Name ... |
+------------------------+------------------------+------------------------+------------------------+
... | ... Font Name | Text ... |
+------------------------+------------------------+------------------------+------------------------+ +------------------------+------------------------+------------------------+------------------------+
... | ... Text | Padding (if required) | ... | ... Text | Padding (if required) |
+------------------------+------------------------+------------------------+------------------------+ +------------------------+------------------------+------------------------+------------------------+

@ -125,7 +125,7 @@ std::size_t ImageElement::serializeTo(std::span<std::byte> target) const {
// FIXME: serialize // FIXME: serialize
} }
void ImageElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick) { void ImageElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) {
// FIXME: draw // FIXME: draw
} }
@ -133,7 +133,7 @@ std::expected<std::unique_ptr<ImageElement>, ParseError> ImageElement::parse(std
// FIXME: parse // FIXME: parse
} }
AnimationElement::AnimationElement(std::uint16_t x, std::uint16_t y, std::uint16_t width, std::uint16_t height, std::uint16_t numberOfFrames, std::uint8_t updateInterval) AnimationElement::AnimationElement(std::uint16_t x, std::uint16_t y, std::uint16_t width, std::uint16_t height, std::uint16_t numberOfFrames, std::uint16_t updateInterval)
: m_x{x} : m_x{x}
, m_y{y} , m_y{y}
, m_width{width} , m_width{width}
@ -165,7 +165,7 @@ std::uint16_t AnimationElement::numberOfFrames() const noexcept {
return m_numberOfFrames; return m_numberOfFrames;
} }
std::uint8_t AnimationElement::updateInterval() const noexcept { std::uint16_t AnimationElement::updateInterval() const noexcept {
return m_updateInterval; return m_updateInterval;
} }
@ -212,7 +212,7 @@ std::size_t AnimationElement::serializeTo(std::span<std::byte> target) const {
// FIXME: implement this // FIXME: implement this
} }
void AnimationElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick) { void AnimationElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) {
// FIXME: implement this // FIXME: implement this
} }

@ -50,7 +50,7 @@ struct Element {
virtual ~Element() = default; virtual ~Element() = default;
virtual ElementType elementType() const = 0; virtual ElementType elementType() const = 0;
virtual std::size_t serializeTo(std::span<std::byte> target) const = 0; virtual std::size_t serializeTo(std::span<std::byte> target) const = 0;
virtual void drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick) = 0; virtual void drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) = 0;
protected: protected:
Element() = default; Element() = default;
@ -93,7 +93,7 @@ struct ImageElement : public Element {
virtual ~ImageElement() override; virtual ~ImageElement() override;
virtual ElementType elementType() const override; virtual ElementType elementType() const override;
virtual std::size_t serializeTo(std::span<std::byte> target) const override; virtual std::size_t serializeTo(std::span<std::byte> target) const override;
virtual void drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick) override; virtual void drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) override;
static std::expected<std::unique_ptr<ImageElement>, ParseError> parse(std::span<std::byte const>& buffer); static std::expected<std::unique_ptr<ImageElement>, ParseError> parse(std::span<std::byte const>& buffer);
@ -106,14 +106,14 @@ private:
}; };
struct AnimationElement : public Element { struct AnimationElement : public Element {
AnimationElement(std::uint16_t x, std::uint16_t y, std::uint16_t width, std::uint16_t height, std::uint16_t numberOfFrames, std::uint8_t updateInterval); AnimationElement(std::uint16_t x, std::uint16_t y, std::uint16_t width, std::uint16_t height, std::uint16_t numberOfFrames, std::uint16_t updateInterval);
std::uint16_t x() const noexcept; std::uint16_t x() const noexcept;
std::uint16_t y() const noexcept; std::uint16_t y() const noexcept;
std::uint16_t width() const noexcept; std::uint16_t width() const noexcept;
std::uint16_t height() const noexcept; std::uint16_t height() const noexcept;
std::uint16_t numberOfFrames() const noexcept; std::uint16_t numberOfFrames() const noexcept;
std::uint8_t updateInterval() const noexcept; std::uint16_t updateInterval() const noexcept;
std::span<std::byte> buffers() noexcept; std::span<std::byte> buffers() noexcept;
std::span<std::byte const> buffers() const noexcept; std::span<std::byte const> buffers() const noexcept;
std::span<std::byte> buffer(std::uint16_t frameIndex) noexcept; std::span<std::byte> buffer(std::uint16_t frameIndex) noexcept;
@ -124,7 +124,7 @@ struct AnimationElement : public Element {
virtual ~AnimationElement() override; virtual ~AnimationElement() override;
virtual ElementType elementType() const override; virtual ElementType elementType() const override;
virtual std::size_t serializeTo(std::span<std::byte> target) const override; virtual std::size_t serializeTo(std::span<std::byte> target) const override;
virtual void drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick) override; virtual void drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) override;
static std::expected<std::unique_ptr<AnimationElement>, ParseError> parse(std::span<std::byte const>& buffer); static std::expected<std::unique_ptr<AnimationElement>, ParseError> parse(std::span<std::byte const>& buffer);
@ -134,7 +134,7 @@ private:
std::uint16_t m_width{}; std::uint16_t m_width{};
std::uint16_t m_height{}; std::uint16_t m_height{};
std::uint16_t m_numberOfFrames{}; std::uint16_t m_numberOfFrames{};
std::uint8_t m_updateInterval{}; std::uint16_t m_updateInterval{};
std::vector<std::byte> m_buffer; std::vector<std::byte> m_buffer;
}; };
@ -156,7 +156,7 @@ struct HScrollImageElement : public Element {
virtual ~HScrollImageElement() override; virtual ~HScrollImageElement() override;
virtual ElementType elementType() const override; virtual ElementType elementType() const override;
virtual std::size_t serializeTo(std::span<std::byte> target) const override; virtual std::size_t serializeTo(std::span<std::byte> target) const override;
virtual void drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick) override; virtual void drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) override;
static std::expected<std::unique_ptr<HScrollImageElement>, ParseError> parse(std::span<std::byte const>& buffer); static std::expected<std::unique_ptr<HScrollImageElement>, ParseError> parse(std::span<std::byte const>& buffer);
@ -189,7 +189,7 @@ struct VScrollImageElement : public Element {
virtual ~VScrollImageElement() override; virtual ~VScrollImageElement() override;
virtual ElementType elementType() const override; virtual ElementType elementType() const override;
virtual std::size_t serializeTo(std::span<std::byte> target) const override; virtual std::size_t serializeTo(std::span<std::byte> target) const override;
virtual void drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick) override; virtual void drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) override;
static std::expected<std::unique_ptr<VScrollImageElement>, ParseError> parse(std::span<std::byte const>& buffer); static std::expected<std::unique_ptr<VScrollImageElement>, ParseError> parse(std::span<std::byte const>& buffer);
@ -221,7 +221,7 @@ struct LineElement : public Element {
virtual ~LineElement() override; virtual ~LineElement() override;
virtual ElementType elementType() const override; virtual ElementType elementType() const override;
virtual std::size_t serializeTo(std::span<std::byte> target) const override; virtual std::size_t serializeTo(std::span<std::byte> target) const override;
virtual void drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick) override; virtual void drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) override;
static std::expected<std::unique_ptr<LineElement>, ParseError> parse(std::span<std::byte const>& buffer); static std::expected<std::unique_ptr<LineElement>, ParseError> parse(std::span<std::byte const>& buffer);
@ -234,7 +234,89 @@ private:
std::uint8_t m_flags{}; std::uint8_t m_flags{};
}; };
// FIXME: text elements struct ClippedTextElement : public Element {
ClippedTextElement(std::uint16_t x, std::uint16_t y, std::uint16_t width, std::uint16_t height, std::uint16_t fontIndex, std::string text);
std::uint16_t x() const noexcept;
std::uint16_t y() const noexcept;
std::uint16_t width() const noexcept;
std::uint16_t height() const noexcept;
std::uint16_t fontIndex() const noexcept;
std::string text() const;
virtual ~ClippedTextElement() override;
virtual ElementType elementType() const override;
virtual std::size_t serializeTo(std::span<std::byte> target) const override;
virtual void drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) override;
static std::expected<std::unique_ptr<ClippedTextElement>, ParseError> parse(std::span<std::byte const>& buffer);
private:
std::uint16_t m_x{};
std::uint16_t m_y{};
std::uint16_t m_width{};
std::uint16_t m_height{};
std::uint16_t m_fontIndex{};
std::string m_text;
};
struct HScrollTextElement : public Element {
HScrollTextElement(std::uint16_t x, std::uint16_t y, std::uint16_t width, std::uint16_t height, std::uint8_t flags, std::uint8_t scrollSpeed, std::uint16_t fontIndex, std::string text);
std::uint16_t x() const noexcept;
std::uint16_t y() const noexcept;
std::uint16_t width() const noexcept;
std::uint16_t height() const noexcept;
std::uint8_t flags() const noexcept;
std::uint8_t scrollSpeed() const noexcept;
std::uint16_t fontIndex() const noexcept;
std::string text() const;
virtual ~HScrollTextElement() override;
virtual ElementType elementType() const override;
virtual std::size_t serializeTo(std::span<std::byte> target) const override;
virtual void drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) override;
static std::expected<std::unique_ptr<HScrollTextElement>, ParseError> parse(std::span<std::byte const>& buffer);
private:
std::uint16_t m_x{};
std::uint16_t m_y{};
std::uint16_t m_width{};
std::uint16_t m_height{};
std::uint8_t m_flags{};
std::uint8_t m_scrollSpeed{};
std::uint16_t m_fontIndex{};
std::string m_text;
};
struct CurrentTimeElement : public Element {
CurrentTimeElement(std::uint16_t x, std::uint16_t y, std::uint16_t width, std::uint16_t height, std::uint16_t fontIndex, std::uint16_t utcOffset, std::uint16_t flags);
std::uint16_t x() const noexcept;
std::uint16_t y() const noexcept;
std::uint16_t width() const noexcept;
std::uint16_t height() const noexcept;
std::uint16_t fontIndex() const noexcept;
std::uint16_t utcOffset() const noexcept;
std::uint16_t flags() const noexcept;
virtual ~CurrentTimeElement() override;
virtual ElementType elementType() const override;
virtual std::size_t serializeTo(std::span<std::byte> target) const override;
virtual void drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) override;
static std::expected<std::unique_ptr<CurrentTimeElement>, ParseError> parse(std::span<std::byte const>& buffer);
private:
std::uint16_t m_x{};
std::uint16_t m_y{};
std::uint16_t m_width{};
std::uint16_t m_height{};
std::uint16_t m_fontIndex{};
std::uint16_t m_utcOffset{};
std::uint16_t m_flags{};
};
struct AlwaysDrawnSection : public Section { struct AlwaysDrawnSection : public Section {
AlwaysDrawnSection() = default; AlwaysDrawnSection() = default;
@ -259,6 +341,8 @@ struct AlwaysDrawnSection : public Section {
virtual SectionType sectionType() const override; virtual SectionType sectionType() const override;
virtual std::size_t serializeTo(std::span<std::byte> target) const override; virtual std::size_t serializeTo(std::span<std::byte> target) const override;
static std::expected<std::unique_ptr<AlwaysDrawnSection>, ParseError> parse(std::span<std::byte const>& buffer);
private: private:
std::vector<std::unique_ptr<Element>> m_elements; std::vector<std::unique_ptr<Element>> m_elements;
bool m_drawOnFront{true}; bool m_drawOnFront{true};
@ -294,6 +378,8 @@ struct TimeBasedDrawnSection : public Section {
virtual SectionType sectionType() const override; virtual SectionType sectionType() const override;
virtual std::size_t serializeTo(std::span<std::byte> target) const override; virtual std::size_t serializeTo(std::span<std::byte> target) const override;
static std::expected<std::unique_ptr<TimeBasedDrawnSection>, ParseError> parse(std::span<std::byte const>& buffer);
private: private:
std::vector<std::unique_ptr<Element>> m_elements; std::vector<std::unique_ptr<Element>> m_elements;
std::uint64_t m_startTimestamp{}; std::uint64_t m_startTimestamp{};
@ -303,7 +389,18 @@ private:
bool m_clearBeforeDrawing{true}; bool m_clearBeforeDrawing{true};
}; };
// FIXME: custom font sections struct CustomFontSection : public Section {
CustomFontSection() = default;
virtual ~CustomFontSection() override;
virtual SectionType sectionType() const override;
virtual std::size_t serializeTo(std::span<std::byte> target) const override;
static std::expected<std::unique_ptr<CustomFontSection>, ParseError> parse(std::span<std::byte const>& buffer);
private:
std::vector<std::byte> m_fontData;
};
struct File { struct File {
std::vector<std::unique_ptr<Section>> sections; std::vector<std::unique_ptr<Section>> sections;

Loading…
Cancel
Save