Skip to content

Commit

Permalink
squash, range + 1
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Aug 23, 2023
1 parent 1e89856 commit 5e0c0a1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 30 deletions.
39 changes: 12 additions & 27 deletions Marlin/src/lcd/e3v2/proui/dwinui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,10 @@ void DWINUI::drawFillCircle(uint16_t bcolor, uint16_t x, uint16_t y, uint8_t r)
// color2 : End color
uint16_t DWINUI::ColorInt(int16_t val, int16_t minv, int16_t maxv, uint16_t color1, uint16_t color2) {
uint8_t B, G, R;
const float n = float(val - minv) / (maxv - minv);
R = (1 - n) * GetRColor(color1) + n * GetRColor(color2);
G = (1 - n) * GetGColor(color1) + n * GetGColor(color2);
B = (1 - n) * GetBColor(color1) + n * GetBColor(color2);
const float n = float(val - minv) / (maxv - minv + 1);
R = (1.0f - n) * GetRColor(color1) + n * GetRColor(color2);
G = (1.0f - n) * GetGColor(color1) + n * GetGColor(color2);
B = (1.0f - n) * GetBColor(color1) + n * GetBColor(color2);
return RGB(R, G, B);
}

Expand All @@ -294,31 +294,16 @@ uint16_t DWINUI::ColorInt(int16_t val, int16_t minv, int16_t maxv, uint16_t colo
// minv : Minimum value
// maxv : Maximum value
uint16_t DWINUI::RainbowInt(int16_t val, int16_t minv, int16_t maxv) {
uint8_t B, G, R;
const uint8_t maxB = 28, maxR = 28, maxG = 38;
const int16_t limv = _MAX(abs(minv), abs(maxv));
float n = (minv >= 0) ? (float)(val - minv) / (maxv - minv) : (float)val / limv;
float n = (minv >= 0) ? float(val - minv) / (maxv - minv + 1) : (float)val / limv;
LIMIT(n, -1, 1);
if (n <= -0.5) {
R = 0;
G = maxG * (1 + n);
B = maxB;
}
else if (n <= 0) {
R = 0;
G = maxG;
B = maxB * (-n) * 2;
}
else if (n < 0.5) {
R = maxR * n * 2;
G = maxG;
B = 0;
}
else {
R = maxR;
G = maxG * (1 - n);
B = 0;
}

constexpr uint8_t maxB = 28, maxR = 28, maxG = 38;
uint8_t R, G, B;
if (n <= -0.5f) { R = 0; G = maxG * (1.0f + n); B = maxB; }
else if (n <= 0.0f) { R = 0; G = maxG; B = maxB * (-n) * 2; }
else if (n < 0.5f) { R = maxR * n * 2; G = maxG; B = 0; }
else { R = maxR; G = maxG * (1.0f - n); B = 0; }
return RGB(R, G, B);
}

Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/lcd/e3v2/proui/meshviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void MeshViewer::drawMeshPoint(const uint8_t x, const uint8_t y, const float z)
NOLESS(max, z); NOMORE(min, z);

const uint16_t color = DWINUI::RainbowInt(v, zmin, zmax);
DWINUI::drawFillCircle(color, px(x), py(y), r(_MAX(_MIN(v,zmax),zmin)));
DWINUI::drawFillCircle(color, px(x), py(y), r(_MAX(_MIN(v, zmax), zmin)));
TERN_(TJC_DISPLAY, delay(100));

const uint16_t fy = py(y) - fs;
Expand All @@ -91,8 +91,8 @@ void MeshViewer::drawMeshPoint(const uint8_t x, const uint8_t y, const float z)
switch (v) {
case -999 ... -100:
case 100 ... 999: DWINUI::drawSignedFloat(meshfont, 1, 1, px(x) - 3 * fs, fy, z); break;
case -99 ... -1: sprintf_P(msg, PSTR("-.%02i"), -v); break;
case 1 ... 99: sprintf_P(msg, PSTR( ".%02i"), v); break;
case -99 ... -1: sprintf_P(msg, PSTR("-.%02i"), -v); break;
case 1 ... 99: sprintf_P(msg, PSTR( ".%02i"), v); break;
default:
dwinDrawString(false, meshfont, DWINUI::textColor, DWINUI::backColor, px(x) - 4, fy, "0");
return;
Expand Down

0 comments on commit 5e0c0a1

Please sign in to comment.