worked on SPI, fixed some bugs

adjusted LCD code
added code for INA3221
worked on UI
This commit is contained in:
2020-06-24 21:28:44 +02:00
parent 6dfce7803a
commit ccd7f119d3
11 changed files with 258 additions and 88 deletions

View File

@@ -44,15 +44,16 @@ class UI {
UIPainter p;
UIElement root;
UIElement* eFocused = nullptr;
int focusIdx = 0;
//UIElement* eFocused = nullptr;
UIElement* eDown = nullptr;
Color cBackground = Color::fromRGB(180,240,180);
public:
UI() {
root.setRect(0,0,240,320);
UI(int w, int h) {
root.setRect(0,0,w,h);
root.setVisible(true);
p.setFG(cBackground);
p.fillRect(root.getRect());
@@ -77,7 +78,6 @@ public:
}
}
void onTouchDone() {
@@ -87,13 +87,28 @@ public:
}
}
void focusNext() {
root.children[focusIdx]->setFocus(false);
focusIdx = (focusIdx + 1) % root.children.size();
root.children[focusIdx]->setFocus(true);
}
void focusPrev() {
root.children[focusIdx]->setFocus(false);
focusIdx = ((focusIdx - 1) + root.children.size()) % root.children.size();
root.children[focusIdx]->setFocus(true);
}
void draw() {
//debugMod1("UI", "draw %zu elements", elements.size());
// for (UIElement* e : elements) {
// e->_draw(p);
// }
//p.setFG(cBackground);
//p.fillRect(root.getRect());
root._draw(p);
}
};

View File

@@ -23,6 +23,9 @@ private:
const Color fillNormal = Color::fromRGB(180,180,180);
const Color fillDown = Color::fromRGB(120,120,120);
const Color fillFocus = Color::fromRGB(120,120,140);
const Color frameBright = Color::fromRGB(230,230,230);
const Color frameDark = Color::fromRGB(50,50,50);
@@ -58,7 +61,11 @@ public:
void draw(UIPainter& p) override {
p.setFG( down ? fillDown : fillNormal );
if (focus) {
p.setFG( fillFocus );
} else {
p.setFG( down ? fillDown : fillNormal );
}
p.fillRect(rect);
p.setFG( down ? frameDark : frameBright );

View File

@@ -15,13 +15,20 @@ protected:
UIRect rect;
bool _visible = true;
bool _needsRedraw = true;
bool opaque = true;
bool focus = false;
std::vector<UIElement*> children;
static constexpr const char* TAG = "UIElement";
public:
void setOpaque(bool opaque) {
this->opaque = opaque;
}
void setRect(const UIRect r) {
this->rect = r;
setNeedsRedraw();
@@ -44,6 +51,11 @@ public:
return this->_visible;
}
void setFocus(bool focus) {
this->focus = focus;
setNeedsRedraw();
}
void setNeedsRedraw() {
this->_needsRedraw = true;
}
@@ -99,7 +111,7 @@ protected:
void _draw(UIPainter& p) {
// if hidde, ignore for me and children
// if hiden, ignore for me and children
if (!_visible) {return;}
// draw myself (if needed)

View File

@@ -11,7 +11,7 @@
class UILabel : public UIElement {
std::string txt;
Color cBackground = Color::fromRGB(255,255,255);
Color cText = Color::fromRGB(0,0,0);
@@ -21,18 +21,21 @@ public:
;
}
/** set the text to draw */
void setText(const std::string& txt) {
this->txt = txt;
setNeedsRedraw();
}
void draw(UIPainter& p) {
/** draw the label */
void draw(UIPainter& p) override {
p.setFG(cBackground);
p.fillRect(rect);
//const uint16_t txtW = fnt_f1.getWidth(txt);
//const uint16_t txtH = fnt_f1.getHeight();
if (opaque) {
p.setFG(cBackground);
p.fillRect(rect);
}
p.setFG(cText);
p.drawText(rect.x, rect.y, txt.c_str());