muwerk mupplet Display Library
muwerk applets; mupplets: functional units that support specific hardware or reusable applications
Loading...
Searching...
No Matches
st7735_matrix.h
1// st7735_matrix.h - ST7735B and ST7735R TFT module driver
2
3#pragma once
4
5#include "Adafruit_ST7735.h"
6
7namespace ustd {
8
20class St7735Matrix : public Adafruit_ST7735 {
21 protected:
22 uint8_t hardware;
23 uint8_t rotation;
24
25 public:
36 St7735Matrix(uint8_t csPin, uint8_t dcPin, uint8_t rsPin, uint8_t hardware, uint8_t rotation)
37 : Adafruit_ST7735(csPin, dcPin, rsPin), hardware(hardware), rotation(rotation) {
38 textbgcolor = ST77XX_BLACK;
39 textcolor = ST77XX_WHITE;
40 }
41
44 void begin() {
45 initR(hardware);
46 fillScreen(textbgcolor);
47 setRotation(rotation);
48 }
49
53 inline bool getTextWrap() const {
54 return wrap;
55 }
56
60 inline int16_t getCursorX() const {
61 return cursor_x;
62 }
63
67 inline int16_t getCursorY() const {
68 return cursor_y;
69 };
70
74 inline uint16_t getTextColor() const {
75 return textcolor;
76 }
77
81 inline uint16_t getTextBackground() const {
82 return textbgcolor;
83 }
84
99 void getCharBounds(unsigned char c, int16_t *x, int16_t *y, int16_t *minx, int16_t *miny,
100 int16_t *maxx, int16_t *maxy) {
101 charBounds(c, x, y, minx, miny, maxx, maxy);
102 }
103
120 bool printFormatted(int16_t x, int16_t y, int16_t w, int16_t align, String content,
121 uint8_t baseLine, uint8_t yAdvance = 0) {
122 int16_t xx = 0, yy = 0;
123 uint16_t ww = 0, hh = 0;
124 bool old_wrap = wrap;
125 wrap = false;
126 getTextBounds(content, 0, 0, &xx, &yy, &ww, &hh);
127 wrap = old_wrap;
128
129 switch (align) {
130 default:
131 case 0:
132 // left
133 xx = 0;
134 break;
135 case 1:
136 // center
137 xx = (w - ww) / 2;
138 break;
139 case 2:
140 // right
141 xx = w - ww;
142 break;
143 }
144 if (yAdvance && (hh % yAdvance)) {
145 hh = ((hh / yAdvance) + 1) * yAdvance;
146 }
147 GFXcanvas16 tmp(w, hh);
148 if (gfxFont) {
149 tmp.setFont(gfxFont);
150 }
151 tmp.fillScreen(textbgcolor);
152 tmp.setTextWrap(false);
153 tmp.setCursor(xx, baseLine ? baseLine : -1 * yy);
154 tmp.setTextColor(textcolor, textbgcolor);
155 tmp.print(content);
156 drawRGBBitmap(x, y, tmp.getBuffer(), w, hh);
157 // set cursor after last printed character
158 setCursor(x + tmp.getCursorX(), y + (baseLine ? baseLine : -1 * yy));
159 return w >= (int16_t)ww;
160 }
161};
162
163} // namespace ustd
The ST7735 Matrix Display Class.
Definition: st7735_matrix.h:20
int16_t getCursorX() const
Definition: st7735_matrix.h:60
uint16_t getTextBackground() const
Definition: st7735_matrix.h:81
St7735Matrix(uint8_t csPin, uint8_t dcPin, uint8_t rsPin, uint8_t hardware, uint8_t rotation)
Definition: st7735_matrix.h:36
int16_t getCursorY() const
Definition: st7735_matrix.h:67
void begin()
Definition: st7735_matrix.h:44
void getCharBounds(unsigned char c, int16_t *x, int16_t *y, int16_t *minx, int16_t *miny, int16_t *maxx, int16_t *maxy)
Definition: st7735_matrix.h:99
bool getTextWrap() const
Definition: st7735_matrix.h:53
uint16_t getTextColor() const
Definition: st7735_matrix.h:74
bool printFormatted(int16_t x, int16_t y, int16_t w, int16_t align, String content, uint8_t baseLine, uint8_t yAdvance=0)
Definition: st7735_matrix.h:120
The muwerk namespace.
Definition: display_digits_max72xx.h:10