2626#include " sliders.h"
2727#include " view_main_decoration.h"
2828#include " hw_inputs.h"
29+ #include < math.h>
2930
3031#include < memory>
3132
3233uint8_t menuCalibrationState;
3334
34- static const uint8_t stick_pointer[] __FLASH = {
35- #include " bmp_radio_stick_pointer.lbm"
36- };
37- static const uint8_t stick_background[] __FLASH = {
38- #include " bmp_radio_stick_background.lbm"
39- };
40-
4135class StickCalibrationWindow : public Window
4236{
4337 public:
4438 StickCalibrationWindow (Window *parent, const rect_t &rect, uint8_t stickX,
4539 uint8_t stickY) :
4640 Window (parent, rect), stickX(stickX), stickY(stickY)
4741 {
48- new StaticLZ4Image (this , 0 , 0 , (LZ4Bitmap *)stick_background);
49- calibStick = new StaticLZ4Image (this , 0 , 0 , (LZ4Bitmap *)stick_pointer);
42+ lv_obj_t * bg = lv_obj_create (lvobj);
43+ etx_obj_add_style (bg, styles->rounded , LV_PART_MAIN );
44+ etx_obj_add_style (bg, styles->border , LV_PART_MAIN );
45+ etx_obj_add_style (bg, styles->border_color [COLOR_BLACK_INDEX ], LV_PART_MAIN );
46+ lv_obj_set_size (bg, CAL_SIZ + PAD_BORDER * 2 , CAL_SIZ + PAD_BORDER * 2 );
47+ lv_obj_add_flag (bg, LV_OBJ_FLAG_OVERFLOW_VISIBLE );
48+
49+ axis[0 ] = {PAD_SMALL , CAL_SIZ / 2 };
50+ axis[1 ] = {CAL_SIZ - PAD_SMALL , CAL_SIZ / 2 };
51+ addLine (bg, COLOR_GREY_INDEX , &axis[0 ]);
52+
53+ axis[2 ] = {CAL_SIZ / 2 , PAD_SMALL };
54+ axis[3 ] = {CAL_SIZ / 2 , CAL_SIZ - PAD_SMALL };
55+ addLine (bg, COLOR_GREY_INDEX , &axis[2 ]);
56+
57+ lv_obj_t * bgCircle = lv_obj_create (bg);
58+ etx_obj_add_style (bgCircle, styles->circle , LV_PART_MAIN );
59+ etx_obj_add_style (bgCircle, styles->border , LV_PART_MAIN );
60+ etx_obj_add_style (bgCircle, styles->border_color [COLOR_GREY_INDEX ], LV_PART_MAIN );
61+ lv_obj_set_style_border_width (bgCircle, CIRC_W , LV_PART_MAIN );
62+ lv_obj_set_size (bgCircle, CAL_SIZ - PAD_TINY * 2 , CAL_SIZ - PAD_TINY * 2 );
63+ lv_obj_set_pos (bgCircle, PAD_TINY , PAD_TINY );
64+
65+ for (int i = 0 ; i < MKR_CNT ; i += 1 ) {
66+ float angle = (i * 360 .0f / MKR_CNT ) / 180 .0f * M_PI ;
67+ float x = cos (angle);
68+ float y = sin (angle);
69+ float r1 = (CAL_SIZ - PAD_SMALL ) / 2 ;
70+ float r2 = r1 - CIRC_W ;
71+ mkr[i * 2 ] = {(lv_coord_t )(x * r1) + CAL_SIZ / 2 , (lv_coord_t )(y * r1) + CAL_SIZ / 2 };
72+ mkr[i * 2 + 1 ] = {(lv_coord_t )(x * r2) + CAL_SIZ / 2 , (lv_coord_t )(y * r2) + CAL_SIZ / 2 };
73+ addLine (bg, COLOR_WHITE_INDEX , &mkr[i * 2 ]);
74+ }
75+
76+ calibShadow = lv_obj_create (bg);
77+ etx_solid_bg (calibShadow, COLOR_BLACK_INDEX );
78+ etx_obj_add_style (calibShadow, styles->circle , LV_PART_MAIN );
79+ lv_obj_set_style_bg_opa (calibShadow, LV_OPA_50 , LV_PART_MAIN );
80+ lv_obj_set_size (calibShadow, CAL_PTR_W , CAL_PTR_W );
81+
82+ calibStick = lv_obj_create (bg);
83+ etx_solid_bg (calibStick, COLOR_WHITE_INDEX );
84+ etx_obj_add_style (calibStick, styles->circle , LV_PART_MAIN );
85+ etx_obj_add_style (calibStick, styles->border , LV_PART_MAIN );
86+ etx_obj_add_style (calibStick, styles->border_color [COLOR_RED_INDEX ], LV_PART_MAIN );
87+ lv_obj_set_style_border_width (calibStick, PAD_SMALL , LV_PART_MAIN );
88+ lv_obj_set_size (calibStick, CAL_PTR_W , CAL_PTR_W );
89+
5090 checkEvents ();
5191 }
5292
93+ void addLine (lv_obj_t * parent, LcdColorIndex color, lv_point_t * points)
94+ {
95+ lv_obj_t * lin = lv_line_create (parent);
96+ etx_obj_add_style (lin, styles->line_color [color], LV_PART_MAIN );
97+ lv_obj_set_style_line_opa (lin, LV_OPA_COVER , LV_PART_MAIN );
98+ lv_obj_set_style_line_width (lin, 2 , LV_PART_MAIN );
99+ lv_line_set_points (lin, points, 2 );
100+ }
101+
53102 void checkEvents () override
54103 {
55104 int32_t x = calibratedAnalogs[stickX];
56105 int32_t y = calibratedAnalogs[stickY];
57- coord_t dx = width () / 2 - CAL_CTR + (CAL_SIZ / 2 * x) / RESX ;
58- coord_t dy = height () / 2 - CAL_CTR - (CAL_SIZ / 2 * y) / RESX ;
59- lv_obj_set_pos (calibStick->getLvObj (), dx, dy);
106+ coord_t w = (CAL_SIZ - CAL_PTR_W ) / 2 ;
107+ coord_t h = (CAL_SIZ - CAL_PTR_W ) / 2 ;
108+ coord_t dx = w + (w * x) / RESX ;
109+ coord_t dy = h - (h * y) / RESX ;
110+ lv_obj_set_pos (calibStick, dx, dy);
111+ lv_obj_set_pos (calibShadow, dx + 1 , dy + 1 );
60112 }
61113
62- static LAYOUT_VAL_SCALED (CAL_CTR , 9 )
63- static LAYOUT_VAL_SCALED(CAL_SIZ , 68 )
114+ static LAYOUT_VAL_SCALED_EVEN (CAL_PTR_W , 18 );
115+ static LAYOUT_VAL_SCALED_EVEN (CAL_SIZ , 120 )
116+ static LAYOUT_VAL_SCALED_EVEN(CIRC_W , 10 )
117+ static constexpr int MKR_CNT = 24;
64118
65119 protected:
66120 uint8_t stickX, stickY;
67- StaticLZ4Image *calibStick = nullptr ;
121+ lv_obj_t * calibStick = nullptr ;
122+ lv_obj_t * calibShadow = nullptr ;
123+ lv_point_t axis[4 ];
124+ lv_point_t mkr[MKR_CNT * 2 ];
68125};
69126
70127RadioCalibrationPage::RadioCalibrationPage () :
@@ -89,21 +146,15 @@ void RadioCalibrationPage::buildBody(Window *window)
89146
90147 // The two sticks
91148
92- LZ4Bitmap *bg = (LZ4Bitmap *)stick_background;
149+ coord_t w = StickCalibrationWindow::CAL_SIZ + PAD_BORDER * 2 ;
150+ coord_t x = (window->width () - w * 2 ) / 3 ;
151+ coord_t y = (window->height () - w) / 2 ;
93152
94- new StickCalibrationWindow (
95- window,
96- {window->width () / 3 - bg->width / 2 ,
97- window->height () / 2 - bg->height / 2 , bg->width , bg->height },
98- 0 , 1 );
153+ new StickCalibrationWindow (window, {x, y, w, w}, 0 , 1 );
99154
100155 auto max_sticks = adcGetMaxInputs (ADC_INPUT_MAIN );
101156 if (max_sticks > 2 ) {
102- new StickCalibrationWindow (
103- window,
104- {window->width () * 2 / 3 - bg->width / 2 ,
105- window->height () / 2 - bg->height / 2 , bg->width , bg->height },
106- 3 , 2 );
157+ new StickCalibrationWindow (window, {x * 2 + w, y, w, w}, 3 , 2 );
107158 }
108159
109160 new ViewMainDecoration (window, true );
0 commit comments