Skip to content

Commit 42232aa

Browse files
committed
improve the performance
1 parent 8f71538 commit 42232aa

File tree

3 files changed

+111
-47
lines changed

3 files changed

+111
-47
lines changed

ARM.Arm-2D.pdsc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -926,11 +926,11 @@
926926
</RTE_Components_h>
927927
</component>
928928

929-
<component Cclass="Acceleration" Cgroup="Arm-2D Demos" Csub="Flight Attitude Instrument" Cversion="1.2.1" condition="Arm-2D-Demos">
929+
<component Cclass="Acceleration" Cgroup="Arm-2D Demos" Csub="Flight Attitude Instrument" Cversion="1.3.0" condition="Arm-2D-Demos">
930930
<description>An demo for the flight attitude instrument. </description>
931931
<files>
932-
<file category="sourceC" name="examples/demos/arm_2d_scene_flight_attitude_instrument.c" attr="config" version="1.2.1" />
933-
<file category="header" name="examples/demos/arm_2d_scene_flight_attitude_instrument.h" attr="config" version="1.2.1" />
932+
<file category="sourceC" name="examples/demos/arm_2d_scene_flight_attitude_instrument.c" attr="config" version="1.3.0" />
933+
<file category="header" name="examples/demos/arm_2d_scene_flight_attitude_instrument.h" attr="config" version="1.3.0" />
934934

935935
<file category="sourceC" name="examples/demos/roll_scale_marker.c" attr="config" version="1.1.0" />
936936
<file category="sourceC" name="examples/demos/rounded_square.c" attr="config" version="1.0.0" />

examples/demos/arm_2d_scene_flight_attitude_instrument.c

Lines changed: 103 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@
7979

8080
#define VISUAL_AREA_MASK c_tileRoundedSquareMask
8181

82-
#define LAND_MASK c_tileSolidSquareMask
83-
#define LAND_MASK_SCARE_RATIO 1.5f
82+
#define LAND_SKY_MASK c_tileSolidSquareMask
83+
#define LAND_SKY_MASK_SCARE_RATIO 1.5f
84+
#define LAND_SKY_MASK_BOARDER_WIDTH 5
85+
8486
#define HORIZON_MASK c_tileSolidLineMask
8587

8688
#define ROLL_SCALE_MARKER_MASK c_tileRollScaleMarkerMask
@@ -90,8 +92,18 @@
9092
#define PITCH_SCALE_MARKER_SCARE_RATIO 1.0f
9193
#define PITCH_SCALE_MARKER_VISUAL_AREA_MASK c_tileSolidCircleSmallMask
9294

95+
#define LAND_COLOUR __RGB(111, 78, 55)
96+
#define SKY_COLOUR GLCD_COLOR_SKY_BLUE
97+
98+
9399

94100
/*============================ TYPES =========================================*/
101+
102+
enum {
103+
HORIZON_LAND,
104+
HORIZON_SKY,
105+
};
106+
95107
/*============================ GLOBAL VARIABLES ==============================*/
96108

97109
extern const arm_2d_tile_t c_tileCMSISLogo;
@@ -144,7 +156,7 @@ END_IMPL_ARM_2D_REGION_LIST(s_tDirtyRegions)
144156

145157
ARM_NOINIT
146158
static
147-
arm_2d_location_t s_tReferencePoints[4];
159+
arm_2d_location_t s_tHorizonReferencePoints[2][4];
148160

149161
ARM_NOINIT
150162
static
@@ -159,9 +171,6 @@ static void __on_scene_flight_attitude_instrument_load(arm_2d_scene_t *ptScene)
159171

160172
spin_zoom_widget_on_load(&this.Roll.tLand);
161173

162-
this.Roll.tLand.tHelper.SourceReference.ptPoints = s_tReferencePoints;
163-
this.Roll.tLand.tHelper.SourceReference.chCount = dimof(s_tReferencePoints);
164-
165174
#if ARM_2D_DEMO_FAI_SHOW_HORIZON
166175
spin_zoom_widget_on_load(&this.Roll.tHorizon);
167176
#endif
@@ -236,11 +245,6 @@ static void __on_scene_flight_attitude_instrument_frame_start(arm_2d_scene_t *pt
236245
int32_t nResult;
237246

238247
arm_2d_helper_time_cos_slider(-450, 450, 7000, 0, &nResult, &this.lTimestamp[0]);
239-
//nResult += 3600;
240-
//if (nResult >= 3600) {
241-
// nResult -= 3600;
242-
//}
243-
244248
this.iRollScale = nResult;
245249

246250
} while(0);
@@ -254,22 +258,46 @@ static void __on_scene_flight_attitude_instrument_frame_start(arm_2d_scene_t *pt
254258
this.iPitchScale = nResult;
255259
} while(0);
256260

257-
spin_zoom_widget_set_source(&this.Roll.tLand,
258-
NULL,
259-
&LAND_MASK,
260-
(arm_2d_location_t) {
261-
LAND_MASK.tRegion.tSize.iWidth >> 1,
262-
reinterpret_s16_q16(
263-
mul_n_q16( this.Roll.q16PitchRatio,
264-
this.iPitchScale))
265-
});
261+
this.bTransformSky = this.iPitchScale > 0;
262+
263+
if (this.bTransformSky) {
264+
spin_zoom_widget_set_source(&this.Roll.tLand,
265+
NULL,
266+
&LAND_SKY_MASK,
267+
(arm_2d_location_t) {
268+
LAND_SKY_MASK.tRegion.tSize.iWidth >> 1,
269+
(LAND_SKY_MASK.tRegion.tSize.iHeight - 1)
270+
- LAND_SKY_MASK_BOARDER_WIDTH
271+
+ reinterpret_s16_q16(
272+
mul_n_q16( this.Roll.q16PitchRatio,
273+
this.iPitchScale))
274+
});
275+
spin_zoom_widget_set_colour(&this.Roll.tLand, SKY_COLOUR);
276+
277+
this.Roll.tLand.tHelper.SourceReference.ptPoints = s_tHorizonReferencePoints[HORIZON_SKY];
278+
this.Roll.tLand.tHelper.SourceReference.chCount = dimof(s_tHorizonReferencePoints[HORIZON_SKY]);
279+
} else {
280+
spin_zoom_widget_set_source(&this.Roll.tLand,
281+
NULL,
282+
&LAND_SKY_MASK,
283+
(arm_2d_location_t) {
284+
LAND_SKY_MASK.tRegion.tSize.iWidth >> 1,
285+
LAND_SKY_MASK_BOARDER_WIDTH +
286+
reinterpret_s16_q16(
287+
mul_n_q16( this.Roll.q16PitchRatio,
288+
this.iPitchScale))
289+
});
290+
spin_zoom_widget_set_colour(&this.Roll.tLand, LAND_COLOUR);
291+
this.Roll.tLand.tHelper.SourceReference.ptPoints = s_tHorizonReferencePoints[HORIZON_LAND];
292+
this.Roll.tLand.tHelper.SourceReference.chCount = dimof(s_tHorizonReferencePoints[HORIZON_LAND]);
293+
}
266294

267295
#if ARM_2D_DEMO_FAI_SHOW_HORIZON
268296
spin_zoom_widget_set_source(&this.Roll.tHorizon,
269297
NULL,
270298
&HORIZON_MASK,
271299
(arm_2d_location_t) {
272-
LAND_MASK.tRegion.tSize.iWidth >> 1,
300+
LAND_SKY_MASK.tRegion.tSize.iWidth >> 1,
273301
reinterpret_s16_q16(
274302
mul_n_q16( this.Roll.q16PitchRatio,
275303
this.iPitchScale))
@@ -289,12 +317,12 @@ static void __on_scene_flight_attitude_instrument_frame_start(arm_2d_scene_t *pt
289317

290318
spin_zoom_widget_on_frame_start(&this.Roll.tLand,
291319
this.iRollScale,
292-
LAND_MASK_SCARE_RATIO);
320+
LAND_SKY_MASK_SCARE_RATIO);
293321

294322
#if ARM_2D_DEMO_FAI_SHOW_HORIZON
295323
spin_zoom_widget_on_frame_start(&this.Roll.tHorizon,
296324
this.iRollScale,
297-
LAND_MASK_SCARE_RATIO);
325+
LAND_SKY_MASK_SCARE_RATIO);
298326
#endif
299327

300328
spin_zoom_widget_on_frame_start(&this.Roll.tMarker,
@@ -336,19 +364,36 @@ IMPL_PFB_ON_DRAW(__pfb_draw_scene_flight_attitude_instrument_handler)
336364

337365
int16_t iVisualAreaWidth = VISUAL_AREA_MASK.tRegion.tSize.iWidth;
338366

339-
arm_2d_fill_colour_with_mask(
367+
if (this.bTransformSky) {
368+
/* draw land */
369+
arm_2d_fill_colour_with_mask(
340370
ptTile,
341371
&__centre_region,
342372
&VISUAL_AREA_MASK,
343-
(__arm_2d_color_t) {GLCD_COLOR_SKY_BLUE});
373+
(__arm_2d_color_t) {LAND_COLOUR});
344374

345-
/* draw land */
346-
spin_zoom_widget_show( &this.Roll.tLand,
347-
ptTile,
348-
&__centre_region,
349-
NULL,
350-
255);
375+
/* draw sky */
376+
spin_zoom_widget_show( &this.Roll.tSky,
377+
ptTile,
378+
&__centre_region,
379+
NULL,
380+
255);
381+
382+
} else {
383+
/* draw sky */
384+
arm_2d_fill_colour_with_mask(
385+
ptTile,
386+
&__centre_region,
387+
&VISUAL_AREA_MASK,
388+
(__arm_2d_color_t) {SKY_COLOUR});
351389

390+
/* draw land */
391+
spin_zoom_widget_show( &this.Roll.tLand,
392+
ptTile,
393+
&__centre_region,
394+
NULL,
395+
255);
396+
}
352397
#if ARM_2D_DEMO_FAI_SHOW_HORIZON
353398
/* draw horizon */
354399
spin_zoom_widget_show( &this.Roll.tHorizon,
@@ -525,12 +570,12 @@ user_scene_flight_attitude_instrument_t *__arm_2d_scene_flight_attitude_instrume
525570
},
526571
.ptTransformMode = &SPIN_ZOOM_MODE_FILL_COLOUR_WITH_TARGET_MASK,
527572
.Source = {
528-
.ptMask = &LAND_MASK,
573+
.ptMask = &LAND_SKY_MASK,
529574
.tCentre = (arm_2d_location_t){
530-
.iX = LAND_MASK.tRegion.tSize.iWidth >> 1,
575+
.iX = LAND_SKY_MASK.tRegion.tSize.iWidth >> 1,
531576
.iY = 0,
532577
},
533-
.tColourToFill = __RGB(111, 78, 55),
578+
.tColourToFill = LAND_COLOUR,
534579
},
535580
.Target.ptMask = &VISUAL_AREA_MASK,
536581

@@ -539,24 +584,39 @@ user_scene_flight_attitude_instrument_t *__arm_2d_scene_flight_attitude_instrume
539584
};
540585
spin_zoom_widget_init(&this.Roll.tLand, &tCFG);
541586

542-
float fPitchHeight = ((float)VISUAL_AREA_MASK.tRegion.tSize.iHeight / LAND_MASK_SCARE_RATIO) / 2.0f;
587+
float fPitchHeight = ((float)VISUAL_AREA_MASK.tRegion.tSize.iHeight / LAND_SKY_MASK_SCARE_RATIO) / 2.0f;
543588

544589
this.Roll.q16PitchRatio = reinterpret_q16_f32(fPitchHeight / 900.0f);
545590

546591
/* update reference points*/
547592
do {
548-
s_tReferencePoints[0].iX = 0;
549-
s_tReferencePoints[0].iY = 0;
593+
s_tHorizonReferencePoints[HORIZON_LAND][0].iX = 0;
594+
s_tHorizonReferencePoints[HORIZON_LAND][0].iY = 0;
595+
596+
s_tHorizonReferencePoints[HORIZON_LAND][1].iX = LAND_SKY_MASK.tRegion.tSize.iWidth - 1;
597+
s_tHorizonReferencePoints[HORIZON_LAND][1].iY = 0;
598+
599+
s_tHorizonReferencePoints[HORIZON_LAND][2].iX = 0;
600+
s_tHorizonReferencePoints[HORIZON_LAND][2].iY = 3;
550601

551-
s_tReferencePoints[1].iX = LAND_MASK.tRegion.tSize.iWidth - 1;
552-
s_tReferencePoints[1].iY = 0;
602+
s_tHorizonReferencePoints[HORIZON_LAND][3].iX = LAND_SKY_MASK.tRegion.tSize.iWidth - 1;
603+
s_tHorizonReferencePoints[HORIZON_LAND][3].iY = 3;
553604

554-
s_tReferencePoints[2].iX = 0;
555-
s_tReferencePoints[2].iY = 3;
556605

557-
s_tReferencePoints[3].iX = LAND_MASK.tRegion.tSize.iWidth - 1;
558-
s_tReferencePoints[3].iY = 3;
606+
s_tHorizonReferencePoints[HORIZON_SKY][0].iX = 0;
607+
s_tHorizonReferencePoints[HORIZON_SKY][0].iY = LAND_SKY_MASK.tRegion.tSize.iHeight - 1;
608+
609+
s_tHorizonReferencePoints[HORIZON_SKY][1].iX = LAND_SKY_MASK.tRegion.tSize.iWidth - 1;
610+
s_tHorizonReferencePoints[HORIZON_SKY][1].iY = LAND_SKY_MASK.tRegion.tSize.iHeight - 1;
611+
612+
s_tHorizonReferencePoints[HORIZON_SKY][2].iX = 0;
613+
s_tHorizonReferencePoints[HORIZON_SKY][2].iY = LAND_SKY_MASK.tRegion.tSize.iHeight - 4;
614+
615+
s_tHorizonReferencePoints[HORIZON_SKY][3].iX = LAND_SKY_MASK.tRegion.tSize.iWidth - 1;
616+
s_tHorizonReferencePoints[HORIZON_SKY][3].iY = LAND_SKY_MASK.tRegion.tSize.iHeight - 4;
559617
} while(0);
618+
619+
this.bTransformSky = true;
560620
} while(0);
561621

562622
#if ARM_2D_DEMO_FAI_SHOW_HORIZON

examples/demos/arm_2d_scene_flight_attitude_instrument.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,13 @@ ARM_PRIVATE(
8989
/* place your private member here, following two are examples */
9090
int64_t lTimestamp[2];
9191
bool bUserAllocated;
92+
bool bTransformSky;
9293

9394
struct {
94-
spin_zoom_widget_t tLand;
95+
union {
96+
spin_zoom_widget_t tLand;
97+
spin_zoom_widget_t tSky;
98+
};
9599
#if ARM_2D_DEMO_FAI_SHOW_HORIZON
96100
spin_zoom_widget_t tHorizon;
97101
#endif

0 commit comments

Comments
 (0)