Skip to content

Commit

Permalink
singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Dec 19, 2023
1 parent e60d308 commit c513396
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
50 changes: 26 additions & 24 deletions Marlin/src/lcd/e3v2/proui/plot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,42 +39,44 @@
#include "../../marlinui.h"
#include "plot.h"

#define Plot_Bg_Color RGB(1, 12, 8)
#define plotBgColor RGB(1, 12, 8)

Plot plot;

uint16_t Plot::graphpoints, Plot::r, Plot::x2, Plot::y2, Plot::yP; // = 0
frame_rect_t Plot::graphframe; // = { 0 }
float Plot::scale; // = 0

void Plot::draw(const frame_rect_t &frame, const_celsius_float_t max, const_celsius_float_t ref/*=0*/) {
plot.graphframe = frame;
plot.graphpoints = 0;
plot.scale = frame.h / max;
plot.x2 = frame.x + frame.w - 1;
plot.y2 = frame.y + frame.h - 1;
plot.r = LROUND((plot.y2) - ref * plot.scale);
DWINUI::drawBox(1, Plot_Bg_Color, frame);
graphframe = frame;
graphpoints = 0;
scale = frame.h / max;
x2 = frame.x + frame.w - 1;
y2 = frame.y + frame.h - 1;
r = LROUND((y2) - ref * scale);
DWINUI::drawBox(1, plotBgColor, frame);
for (uint8_t i = 1; i < 4; i++) if (i * 60 < frame.w) dwinDrawVLine(COLOR_LINE, i * 60 + frame.x, frame.y, frame.h);
DWINUI::drawBox(0, COLOR_WHITE, DWINUI::extendFrame(frame, 1));
dwinDrawHLine(COLOR_RED, frame.x, plot.r, frame.w);
dwinDrawHLine(COLOR_RED, frame.x, r, frame.w);
}

void Plot::update(const_celsius_float_t value) {
if (!plot.scale) return;
const uint16_t y = LROUND((plot.y2) - value * plot.scale);
if (plot.graphpoints < plot.graphframe.w) {
if (plot.graphpoints < 1) {
dwinDrawPoint(COLOR_YELLOW, 1, 1, plot.graphframe.x, y);
}
else {
dwinDrawLine(COLOR_YELLOW, plot.graphpoints + plot.graphframe.x - 1, plot.yP, plot.graphpoints + plot.graphframe.x, y);
}
if (!scale) return;
const uint16_t y = LROUND((y2) - value * scale);
if (graphpoints < graphframe.w) {
if (graphpoints < 1)
dwinDrawPoint(COLOR_YELLOW, 1, 1, graphframe.x, y);
else
dwinDrawLine(COLOR_YELLOW, graphpoints + graphframe.x - 1, yP, graphpoints + graphframe.x, y);
}
else {
dwinFrameAreaMove(1, 0, 1, Plot_Bg_Color, plot.graphframe.x, plot.graphframe.y, plot.x2, plot.y2);
if ((plot.graphpoints % 60) == 0) dwinDrawVLine(COLOR_LINE, plot.x2 - 1, plot.graphframe.y + 1, plot.graphframe.h - 2);
dwinDrawPoint(COLOR_RED, 1, 1, plot.x2 - 1, plot.r);
dwinDrawLine(COLOR_YELLOW, plot.x2 - 2, plot.yP, plot.x2 - 1, y);
dwinFrameAreaMove(1, 0, 1, plotBgColor, graphframe.x, graphframe.y, x2, y2);
if ((graphpoints % 60) == 0) dwinDrawVLine(COLOR_LINE, x2 - 1, graphframe.y + 1, graphframe.h - 2);
dwinDrawPoint(COLOR_RED, 1, 1, x2 - 1, r);
dwinDrawLine(COLOR_YELLOW, x2 - 2, yP, x2 - 1, y);
}
plot.yP = y;
plot.graphpoints++;
yP = y;
graphpoints++;
TERN_(HAS_BACKLIGHT_TIMEOUT, ui.refresh_backlight_timeout());
}

Expand Down
7 changes: 4 additions & 3 deletions Marlin/src/lcd/e3v2/proui/plot.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ class Plot {
static void update(const_celsius_float_t value);

private:
uint16_t graphpoints, r, x2, y2, yP = 0;
frame_rect_t graphframe = {0};
float scale = 0;
static uint16_t graphpoints, r, x2, y2, yP;
static frame_rect_t graphframe;
static float scale;
};

extern Plot plot;

0 comments on commit c513396

Please sign in to comment.