5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
23 void displayPresetChoice(event_t event
)
25 runPopupWarning(event
);
26 lcdDrawNumber(WARNING_LINE_X
+FW
*7, WARNING_LINE_Y
, 45*warningInputValue
/4, LEFT
|INVERS
);
27 lcdDrawChar(lcdLastRightPos
, WARNING_LINE_Y
, '@', INVERS
);
31 CurveInfo
& crv
= g_model
.curves
[s_curveChan
];
32 int8_t * points
= curveAddress(s_curveChan
);
33 int k
= 25 * warningInputValue
;
34 int dx
= 2000 / (5+crv
.points
-1);
35 for (uint8_t i
=0; i
<5+crv
.points
; i
++) {
36 int x
= -1000 + i
* dx
;
37 points
[i
] = div_and_round(div_and_round(k
* x
, 100), 10);
39 if (crv
.type
== CURVE_TYPE_CUSTOM
) {
40 resetCustomCurveX(points
, 5+crv
.points
);
45 void onCurveOneMenu(const char * result
)
47 if (result
== STR_CURVE_PRESET
) {
48 POPUP_INPUT(STR_PRESET
, displayPresetChoice
, 0, -4, 4);
50 else if (result
== STR_MIRROR
) {
51 CurveInfo
& crv
= g_model
.curves
[s_curveChan
];
52 int8_t * points
= curveAddress(s_curveChan
);
53 for (int i
=0; i
<5+crv
.points
; i
++)
54 points
[i
] = -points
[i
];
56 else if (result
== STR_CLEAR
) {
57 CurveInfo
& crv
= g_model
.curves
[s_curveChan
];
58 int8_t * points
= curveAddress(s_curveChan
);
59 for (int i
=0; i
<5+crv
.points
; i
++)
61 if (crv
.type
== CURVE_TYPE_CUSTOM
) {
62 resetCustomCurveX(points
, 5+crv
.points
);
67 void menuModelCurveOne(event_t event
)
69 static uint8_t pointsOfs
= 0;
70 CurveData
& crv
= g_model
.curves
[s_curveChan
];
71 int8_t * points
= curveAddress(s_curveChan
);
73 drawStringWithIndex(PSIZE(TR_MENUCURVES
)*FW
+FW
, 0, "CV", s_curveChan
+1);
75 lcdDrawText(11*FW
+FW
/2, 0, TR_PT
"\002X\006Y");
76 lcdDrawFilledRect(0, 0, LCD_W
, FH
, SOLID
, FILL_WHITE
|GREY_DEFAULT
);
78 SIMPLE_SUBMENU(STR_MENUCURVES
, 4 + 5+crv
.points
+ (crv
.type
==CURVE_TYPE_CUSTOM
? 5+crv
.points
-2 : 0));
81 lcdDrawTextAlignedLeft(FH
+ 1, STR_NAME
);
82 editName(INDENT_WIDTH
, 2 * FH
+ 1, crv
.name
, sizeof(crv
.name
), event
, menuVerticalPosition
== 0);
85 lcdDrawTextAlignedLeft(3 * FH
+ 1, NO_INDENT(STR_TYPE
));
86 LcdFlags attr
= (menuVerticalPosition
== 1 ? (s_editMode
> 0 ? INVERS
| BLINK
: INVERS
) : 0);
87 lcdDrawTextAtIndex(INDENT_WIDTH
, 4 * FH
+ 1, STR_CURVE_TYPES
, crv
.type
, attr
);
89 uint8_t newType
= checkIncDecModelZero(event
, crv
.type
, CURVE_TYPE_LAST
);
90 if (newType
!= crv
.type
) {
91 for (int i
= 1; i
< 4 + crv
.points
; i
++) {
92 points
[i
] = calcRESXto100(applyCustomCurve(calc100toRESX(getCurveX(5 + crv
.points
, i
)), s_curveChan
));
94 if (moveCurve(s_curveChan
, checkIncDec_Ret
> 0 ? 3 + crv
.points
: -3 - crv
.points
)) {
95 if (newType
== CURVE_TYPE_CUSTOM
) {
96 resetCustomCurveX(points
, 5 + crv
.points
);
104 attr
= (menuVerticalPosition
==2 ? (s_editMode
>0 ? INVERS
|BLINK
: INVERS
) : 0);
105 lcdDrawTextAlignedLeft(5*FH
+1, STR_COUNT
);
106 lcdDrawNumber(INDENT_WIDTH
, 6*FH
+1, 5+crv
.points
, LEFT
|attr
);
107 lcdDrawText(lcdLastRightPos
, 6*FH
+1, STR_PTS
, attr
);
109 int8_t count
= checkIncDecModel(event
, crv
.points
, -3, 12); // 2pts - 17pts
110 if (checkIncDec_Ret
) {
111 int8_t newPoints
[MAX_POINTS_PER_CURVE
];
112 newPoints
[0] = points
[0];
113 newPoints
[4 + count
] = points
[4 + crv
.points
];
114 for (int i
= 1; i
< 4 + count
; i
++)
115 newPoints
[i
] = calcRESXto100(applyCustomCurve(calc100toRESX(getCurveX(5 + count
, i
)), s_curveChan
));
116 if (moveCurve(s_curveChan
, checkIncDec_Ret
* (crv
.type
== CURVE_TYPE_CUSTOM
? 2 : 1))) {
117 for (int i
= 0; i
< 5 + count
; i
++) {
118 points
[i
] = newPoints
[i
];
119 if (crv
.type
== CURVE_TYPE_CUSTOM
&& i
!= 0 && i
!= 4 + count
)
120 points
[5 + count
+ i
- 1] = getCurveX(5 + count
, i
);
128 lcdDrawTextAlignedLeft(7*FH
+1, STR_SMOOTH
);
129 drawCheckBox(7 * FW
, 7 * FH
+ 1, crv
.smooth
, menuVerticalPosition
== 3 ? INVERS
: 0);
130 if (menuVerticalPosition
==3) crv
.smooth
= checkIncDecModel(event
, crv
.smooth
, 0, 1);
138 case EVT_KEY_LONG(KEY_ENTER
):
139 if (menuVerticalPosition
> 1) {
141 POPUP_MENU_ADD_ITEM(STR_CURVE_PRESET
);
142 POPUP_MENU_ADD_ITEM(STR_MIRROR
);
143 POPUP_MENU_ADD_ITEM(STR_CLEAR
);
144 POPUP_MENU_START(onCurveOneMenu
);
148 case EVT_KEY_LONG(KEY_MENU
):
149 pushMenu(menuChannelsView
);
157 attr
= (s_editMode
> 0 ? INVERS
|BLINK
: INVERS
);
158 for (uint8_t i
=0; i
<5+crv
.points
; i
++) {
159 point_t point
= getPoint(i
);
160 uint8_t selectionMode
= 0;
161 if (crv
.type
==CURVE_TYPE_CUSTOM
) {
162 if (menuVerticalPosition
==4+2*i
|| (i
==5+crv
.points
-1 && menuVerticalPosition
==4+5+crv
.points
+5+crv
.points
-2-1))
164 else if (i
>0 && menuVerticalPosition
==3+2*i
)
167 else if (menuVerticalPosition
== 4+i
) {
171 if (i
>=pointsOfs
&& i
<pointsOfs
+7) {
172 int8_t x
= getCurveX(5+crv
.points
, i
);
173 if (crv
.type
==CURVE_TYPE_CUSTOM
&& i
>0 && i
<5+crv
.points
-1) {
174 x
= points
[5+crv
.points
+i
-1];
176 lcdDrawNumber(6+10*FW
+FW
/2, posY
, i
+1, LEFT
);
177 lcdDrawNumber(3+14*FW
, posY
, x
, LEFT
|(selectionMode
==1?attr
:0));
178 lcdDrawNumber(3+18*FW
, posY
, points
[i
], LEFT
|(selectionMode
==2?attr
:0));
182 if (selectionMode
> 0) {
184 lcdDrawFilledRect(point
.x
-FW
-1, point
.y
-2, 5, 5, SOLID
, FORCE
);
185 lcdDrawFilledRect(point
.x
-FW
, point
.y
-1, 3, 3, SOLID
);
186 if (s_editMode
> 0) {
187 if (selectionMode
== 1)
188 CHECK_INCDEC_MODELVAR(event
, points
[5+crv
.points
+i
-1], i
==1 ? -100 : points
[5+crv
.points
+i
-2], i
==5+crv
.points
-2 ? 100 : points
[5+crv
.points
+i
]); // edit X
189 else if (selectionMode
== 2)
190 CHECK_INCDEC_MODELVAR(event
, points
[i
], -100, 100);
194 else if (i
> pointsOfs
+6)