diff --git a/src/graphdisplay.h b/src/graphdisplay.h index c5c5301..75cc3b3 100644 --- a/src/graphdisplay.h +++ b/src/graphdisplay.h @@ -67,7 +67,7 @@ void GraphDisplay::initScreen(TftInterface &tft) { Base::initScreen(tft); - m_graph.start(static_cast &>(*this).getBuffers()); + m_graph.start(tft, static_cast &>(*this).getBuffers()); } template @@ -75,7 +75,7 @@ void GraphDisplay::redraw(TftInterface &tft) { Base::redraw(tft); - m_graph.redraw(static_cast &>(*this).getBuffers()); + m_graph.redraw(tft, static_cast &>(*this).getBuffers()); } template diff --git a/src/splitgraphdisplay.h b/src/splitgraphdisplay.h index ca3c734..57a2632 100644 --- a/src/splitgraphdisplay.h +++ b/src/splitgraphdisplay.h @@ -75,22 +75,20 @@ void SplitGraphDisplay::initScreen(TftInterface &tft) { Base::initScreen(tft); - m_titleLabel.start(); + m_titleLabel.start(tft); tft.fillRect(0, 34, tft.width(), 3, TFT_WHITE); - m_graph0.start(static_cast&>(*this).getTopBuffers()); - m_graph1.start(static_cast&>(*this).getBottomBuffers()); + m_graph0.start(tft, static_cast&>(*this).getTopBuffers()); + m_graph1.start(tft, static_cast&>(*this).getBottomBuffers()); } template void SplitGraphDisplay::redraw(TftInterface &tft) { - tft.setTextFont(4); - tft.setTextColor(TFT_YELLOW, TFT_BLACK); - m_titleLabel.redraw(text()); + m_titleLabel.redraw(tft, text(), TFT_YELLOW, TFT_BLACK, 4); - m_graph0.redraw(static_cast&>(*this).getTopBuffers()); - m_graph1.redraw(static_cast&>(*this).getBottomBuffers()); + m_graph0.redraw(tft, static_cast&>(*this).getTopBuffers()); + m_graph1.redraw(tft, static_cast&>(*this).getBottomBuffers()); } template diff --git a/src/tftespiimpl.h b/src/tftespiimpl.h index 931a7b8..f22f505 100644 --- a/src/tftespiimpl.h +++ b/src/tftespiimpl.h @@ -73,6 +73,19 @@ public: void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint16_t *data) { m_tft.pushImage(x, y, w, h, data); } void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint16_t *data, uint16_t transparent) { m_tft.pushImage(x, y, w, h, data, transparent); } + uint16_t decodeUTF8(const uint8_t *buf, uint16_t *index, uint16_t remaining) override { return m_tft.decodeUTF8(buf, index, remaining); } + uint16_t decodeUTF8(uint8_t c) override { return m_tft.decodeUTF8(c); } + + void setSwapBytes(bool swap) override { m_tft.setSwapBytes(swap); } + bool getSwapBytes(void) const override { return m_tft.getSwapBytes(); } + + void startWrite(void) override { m_tft.startWrite(); } + void writeColor(uint16_t color, uint32_t len) override { m_tft.writeColor(color, len); } + void endWrite(void) override { m_tft.endWrite(); } + + void pushColor(uint16_t color, uint32_t len) override { m_tft.pushColor(color, len); } + + void setAddrWindow(int32_t xs, int32_t ys, int32_t w, int32_t h) override { m_tft.setAddrWindow(xs, ys, w, h); } private: TFT_eSPI m_tft; }; diff --git a/src/tftinterface.h b/src/tftinterface.h index a629d4e..2a1d756 100644 --- a/src/tftinterface.h +++ b/src/tftinterface.h @@ -84,6 +84,25 @@ public: // These are used to render images or sprites stored in RAM arrays (used by Sprite class for 16bpp Sprites) virtual void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint16_t *data) = 0; virtual void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint16_t *data, uint16_t transparent) = 0; + + // Used by library and Smooth font class to extract Unicode point codes from a UTF8 encoded string + virtual uint16_t decodeUTF8(const uint8_t *buf, uint16_t *index, uint16_t remaining) = 0; + virtual uint16_t decodeUTF8(uint8_t c) = 0; + + // Swap the byte order for pushImage() and pushPixels() - corrects endianness + virtual void setSwapBytes(bool swap) = 0; + virtual bool getSwapBytes(void) const = 0; + + // Bare metal functions + virtual void startWrite(void) = 0; + virtual void writeColor(uint16_t color, uint32_t len) = 0; + virtual void endWrite(void) = 0; + + // Push (aka write pixel) colours to the set window + virtual void pushColor(uint16_t color, uint32_t len) = 0; + + // The TFT_eSprite class inherits the following functions (not all are useful to Sprite class + virtual void setAddrWindow(int32_t xs, int32_t ys, int32_t w, int32_t h) = 0; }; inline bool isLandscape(const TftInterface &tft) diff --git a/src/widgets/graph.h b/src/widgets/graph.h index 6432445..356793e 100644 --- a/src/widgets/graph.h +++ b/src/widgets/graph.h @@ -26,11 +26,11 @@ public: Graph(int x, int y, int height); - void start(const Container &buffers); - void redraw(const Container &buffers); + void start(TftInterface &tft, const Container &buffers); + void redraw(TftInterface &tft, const Container &buffers); private: - void render(const Container &buffers, bool delta); + void render(TftInterface &tft, const Container &buffers, bool delta); const int m_x, m_y, m_height; @@ -56,7 +56,7 @@ Graph::Graph(int x, int y, int height) : } template -void Graph::start(const Container &buffers) +void Graph::start(TftInterface &tft, const Container &buffers) { m_min = 0.f; m_max = 10.f; @@ -66,20 +66,20 @@ void Graph::start(const Container &buffers) for (auto iter = std::begin(m_labels); iter != std::end(m_labels); iter++) { tft.drawFastHLine(m_x+leftMargin-5, float(m_y)+(float(m_height)/(m_labels.size()-1)*std::distance(std::begin(m_labels), iter)), 4, TFT_WHITE); - iter->start(); + iter->start(tft); } - render(buffers, false); + render(tft, buffers, false); } template -void Graph::redraw(const Container &buffers) +void Graph::redraw(TftInterface &tft, const Container &buffers) { - render(buffers, true); + render(tft, buffers, true); } template -void Graph::render(const Container &buffers, bool delta) +void Graph::render(TftInterface &tft, const Container &buffers, bool delta) { float min{std::numeric_limits::quiet_NaN()}, max{std::numeric_limits::quiet_NaN()}; bool first{true}; @@ -115,10 +115,8 @@ void Graph::render(const Container &buffers, bool delta) if (m_min < 0 && m_max < 0) m_max = 0; - tft.setTextFont(2); - tft.setTextColor(TFT_WHITE, TFT_BLACK); for (auto iter = std::begin(m_labels); iter != std::end(m_labels); iter++) - iter->redraw(std::to_string(int(m_max+((m_min-m_max)/(m_labels.size()-1)*std::distance(std::begin(m_labels), iter))))); + iter->redraw(tft, std::to_string(int(m_max+((m_min-m_max)/(m_labels.size()-1)*std::distance(std::begin(m_labels), iter)))), TFT_WHITE, TFT_BLACK, 2); int x{leftMargin}; for (auto pixelsIter = std::begin(m_lastPixels); pixelsIter!=std::end(m_lastPixels); pixelsIter++)