Add cursor to custom curves - Closes #6399 (#7707)

Add cursor to custom curves
Refactor functions declaration
Cosmetics
This commit is contained in:
DanielGeA
2020-09-22 17:49:15 +02:00
committed by GitHub
parent b4d8504577
commit 869f8127ec
20 changed files with 137 additions and 981 deletions
+49 -3
View File
@@ -61,6 +61,7 @@ void menuModelCurvesAll(event_t event)
case EVT_KEY_FIRST(KEY_ENTER):
if (CURVE_SELECTED() && !READ_ONLY()) {
s_currIdxSubMenu = sub;
s_currSrcRaw = MIXSRC_NONE;
pushMenu(menuModelCurveOne);
}
break;
@@ -140,9 +141,9 @@ void editCurveRef(coord_t x, coord_t y, CurveRef & curve, event_t event, LcdFlag
break;
case CURVE_REF_CUSTOM:
drawCurveName(x, y, curve.value, flags);
if (active && menuHorizontalPosition==1) {
if (event==EVT_KEY_LONG(KEY_ENTER) && curve.value!=0) {
s_currIdxSubMenu = (curve.value<0 ? -curve.value-1 : curve.value-1);
if (active && menuHorizontalPosition == 1) {
if (event == EVT_KEY_LONG(KEY_ENTER) && curve.value != 0) {
s_currIdxSubMenu = abs(curve.value) - 1;
pushMenu(menuModelCurveOne);
}
else {
@@ -152,3 +153,48 @@ void editCurveRef(coord_t x, coord_t y, CurveRef & curve, event_t event, LcdFlag
break;
}
}
void drawFunction(FnFuncP fn, uint8_t offset)
{
lcdDrawVerticalLine(CURVE_CENTER_X - offset, CURVE_CENTER_Y-CURVE_SIDE_WIDTH, CURVE_SIDE_WIDTH * 2, 0xee);
lcdDrawHorizontalLine(CURVE_CENTER_X - CURVE_SIDE_WIDTH - offset, CURVE_CENTER_Y, CURVE_SIDE_WIDTH * 2, 0xee);
coord_t prev_yv = (coord_t) - 1;
for (int xv = -CURVE_SIDE_WIDTH; xv <= CURVE_SIDE_WIDTH; xv++) {
coord_t yv = (LCD_H - 1) - (((uint16_t)RESX + fn(xv * (RESX/CURVE_SIDE_WIDTH))) / 2 * (LCD_H - 1) / RESX);
if (prev_yv != (coord_t) - 1) {
if (abs((int8_t)yv-prev_yv) <= 1) {
lcdDrawPoint(CURVE_CENTER_X + xv - offset - 1, prev_yv, FORCE);
}
else {
uint8_t tmp = (prev_yv < yv ? 0 : 1);
lcdDrawSolidVerticalLine(CURVE_CENTER_X + xv - offset - 1, yv + tmp, prev_yv - yv);
}
}
prev_yv = yv;
}
}
void drawCursor(FnFuncP fn, uint8_t offset)
{
int x512 = getValue(s_currSrcRaw);
if (s_currSrcRaw >= MIXSRC_FIRST_TELEM) {
if (s_currScale > 0)
x512 = (x512 * 1024) / convertTelemValue(s_currSrcRaw - MIXSRC_FIRST_TELEM + 1, s_currScale);
drawSensorCustomValue(LCD_W - FW - offset, 6 * FH, (s_currSrcRaw - MIXSRC_FIRST_TELEM) / 3, x512, 0);
}
else {
lcdDrawNumber(LCD_W - FW - offset, 6*FH, calcRESXto1000(x512), RIGHT | PREC1);
}
x512 = limit(-1024, x512, 1024);
int y512 = fn(x512);
y512 = limit(-1024, y512, 1024);
lcdDrawNumber(CURVE_CENTER_X - FWNUM - offset, 1*FH, calcRESXto1000(y512), RIGHT | PREC1);
x512 = CURVE_CENTER_X + x512/(RESX / CURVE_SIDE_WIDTH);
y512 = (LCD_H - 1) - ((y512 + RESX) / 2) * (LCD_H - 1) / RESX;
lcdDrawSolidVerticalLine(x512 - offset, y512-3, 3 * 2 + 1);
lcdDrawSolidHorizontalLine(x512 - 3 - offset, y512, 3 * 2 + 1);
}