From 22a6669b1e075499fdddcd709dcefdcd89e53c3f Mon Sep 17 00:00:00 2001 From: "bsongis@gmail.com" Date: Tue, 23 Apr 2013 17:06:55 +0000 Subject: [PATCH] [all] Work on curves --- src/menu_model.cpp | 184 ++++++++++++++++++++++++++++----------------- 1 file changed, 117 insertions(+), 67 deletions(-) diff --git a/src/menu_model.cpp b/src/menu_model.cpp index 4a0c9e226..53968a5be 100644 --- a/src/menu_model.cpp +++ b/src/menu_model.cpp @@ -2015,34 +2015,66 @@ int16_t expoFn(int16_t x) return anas[ed->chn]; } -#if defined(CURVES) -static uint8_t s_curveChan; -int16_t curveFn(int16_t x) -{ - return intpol(x, s_curveChan); -} -#endif - -void DrawCurve(FnFuncP fn, uint8_t offset=0) +void DrawFunction(FnFuncP fn, uint8_t offset=0) { lcd_vlineStip(X0-offset, 0, LCD_H, 0xee); lcd_hlineStip(X0-WCHART-offset, Y0, WCHART*2, 0xee); uint8_t prev_yv = 255; - for (int8_t xv=-WCHART+1; xv<=WCHART; xv++) { - uint16_t yv = (RESX + fn(xv * (RESX/WCHART))) / 2; - yv = (LCD_H-1) - yv * (LCD_H-1) / RESX; + for (int8_t xv=-WCHART; xv<=WCHART; xv++) { + uint8_t yv = (LCD_H-1) - (((int16_t)RESX + fn(xv * (RESX/WCHART))) / 2 * (LCD_H-1) / RESX); if (prev_yv != 255) { - if (abs((int8_t)yv-prev_yv) <= 1) - lcd_plot(X0+xv-offset, prev_yv, FORCE); - else - lcd_vline(X0+xv-offset, prev_yv < yv ? yv : yv+1, prev_yv-yv); + if (abs((int8_t)yv-prev_yv) <= 1) { + lcd_plot(X0+xv-offset-1, prev_yv, FORCE); + } + else { + uint8_t tmp = (prev_yv < yv ? 0 : 1); + lcd_vline(X0+xv-offset-1, yv+tmp, prev_yv-yv); + } } prev_yv = yv; } } +#if defined(CURVES) +static uint8_t s_curveChan; +int16_t curveFn(int16_t x) +{ + return intpol(x, s_curveChan); +} + +struct point_t { + uint8_t x; + uint8_t y; +}; + +point_t getPoint(uint8_t i) +{ + point_t result = {0, 0}; + CurveInfo crv = curveinfo(s_curveChan); + if (i < crv.points) { + result.x = X0-1-WCHART+i*WCHART/(crv.points/2); + result.y = (LCD_H-1) - (100 + crv.crv[i]) * (LCD_H-1) / 200; + if (crv.custom && i>0 && i 4) - presetIdx = -4; - for (uint8_t i=0; i0 && i=s_pgOfs && i 0) { if (event==EVT_KEY_BREAK(KEY_ENTER)) { if (s_editMode == EDIT_MODIFY_FIELD) - s_editMode = crv.custom ? 2 : 3; + s_editMode = (crv.custom && i>0 && i0 && i0) { + uint8_t i = m_posHorz; + point_t point = getPoint(i); - lcd_filled_rect(xx, yy-1, 3, 3, SOLID, FORCE); // do markup square - - if (s_editMode>0 && m_posHorz==i) { - if (s_editMode==1 || !BLINK_ON_PHASE) { - // do selection square - lcd_filled_rect(xx-1, yy-2, 5, 5, SOLID, FORCE); - lcd_filled_rect(xx, yy-1, 3, 3, SOLID); - } - - int8_t x = -100 + 200*i/(crv.points-1); - if (crv.custom && i>0 && i