forked from RespawnDespair/wifibroadcast-osd-orig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender.c
1359 lines (1096 loc) · 49.4 KB
/
render.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// characters osdicons.ttf
// round triangle
// satellite
// cpu
// bars ▁▂▃▄▅▆▇█
// arrows ↥ ↦ ↤
// warning
// down/up stream
// RSSI
// cam
// double caret
// please wait
// wind
// thermometer
// time
// pressure
// speed
// windhose
// cog
#include <stdint.h>
#include "render.h"
#include "telemetry.h"
#include "osdconfig.h"
#define TO_FEET 3.28084
#define TO_MPH 0.621371
#define CELL_WARNING_PCT1 (CELL_WARNING1-CELL_MIN)/(CELL_MAX-CELL_MIN)*100
#define CELL_WARNING_PCT2 (CELL_WARNING2-CELL_MIN)/(CELL_MAX-CELL_MIN)*100
int width, height;
float scale_factor_font;
bool setting_home;
bool home_set;
float home_lat;
float home_lon;
int home_counter;
char buffer[40];
Fontinfo myfont,osdicons;
int packetslost_last[6];
int fecs_skipped_last;
int injection_failed_last;
int tx_restart_count_last;
bool no_signal = false;
long long current_ts() {
struct timeval te;
gettimeofday(&te, NULL); // get current time
long long milliseconds = te.tv_sec*1000LL + te.tv_usec/1000; // calculate milliseconds
return milliseconds;
}
int getWidth(float pos_x_percent) {
return (width * 0.01f * pos_x_percent);
}
int getHeight(float pos_y_percent) {
return (height * 0.01f * pos_y_percent);
}
float getOpacity(int r, int g, int b, float o) {
if (o<0.5) o = o*2;
return o;
}
void setfillstroke() {
Fill(COLOR);
Stroke(OUTLINECOLOR);
StrokeWidth(OUTLINEWIDTH);
}
void render_init() {
char filename[100] = "/boot/osdfonts/";
InitShapes(&width, &height);
strcat(filename, FONT);
myfont = LoadTTFFile(filename);
if (!myfont) {
fputs("ERROR: Failed to load font!", stderr);
exit(1);
}
osdicons = LoadTTFFile("/boot/osdfonts/osdicons.ttf");
if (!osdicons) {
fputs("ERROR: Failed to load osdicons.ttf font!", stderr);
exit(1);
}
home_counter = 0;
// vgSeti(VG_MATRIX_MODE, VG_MATRIX_GLYPH_USER_TO_SURFACE);
}
void render(telemetry_data_t *td, uint8_t cpuload_gnd, uint8_t temp_gnd, uint8_t undervolt, int osdfps) {
Start(width,height); // render start
setfillstroke();
if (td->rx_status_sysair->undervolt == 1) draw_message(0,"Undervoltage on TX","Check wiring/power-supply","Bitrate limited to 1 Mbit",WARNING_POS_X, WARNING_POS_Y, GLOBAL_SCALE);
if (undervolt == 1) draw_message(0,"Undervoltage on RX","Check wiring/power-supply"," ",WARNING_POS_X, WARNING_POS_Y, GLOBAL_SCALE);
#if defined(FRSKY)
//we assume that we have a fix if we get the NS and EW values from frsky protocol
if (((td->ew == 'E' || td->ew == 'W') && (td->ns == 'N' || td->ns == 'S')) && !home_set){
setting_home = true;
} else { //no fix
setting_home = false;
home_counter = 0;
}
if (setting_home && !home_set){
//if 20 packages after each other have a fix set home
if (++home_counter == 20){
home_set = true;
home_lat = (td->ns == 'N'? 1:-1) * td->latitude;
home_lon = (td->ew == 'E'? 1:-1) * td->longitude;
}
}
#endif
#if defined(MAVLINK) || defined(SMARTPORT)
// if atleast 2D satfix is reported by flightcontrol
if (td->fix > 2 && !home_set){
setting_home = true;
} else { //no fix
setting_home = false;
home_counter = 0;
}
if (setting_home && !home_set){
//if 20 packages after each other have a fix set home
if (++home_counter == 20){
home_set = true;
home_lat = td->latitude;
home_lon = td->longitude;
}
}
#endif
#if defined(LTM)
//LTM makes it easy: If LTM O-frame reports home fix,
//set home position and use home lat/long from LTM O-frame
if (td->home_fix == 1){
home_set = true;
home_lat = td->ltm_home_latitude;
home_lon = td->ltm_home_longitude;
}
#endif
// draw_osdinfos(osdfps, 20, 20, 1);
#ifdef UPLINK_RSSI
draw_uplink_signal(td->rx_status_uplink->adapter[0].current_signal_dbm, td->rx_status_uplink->lost_packet_cnt, td->rx_status_rc->adapter[0].current_signal_dbm, td->rx_status_rc->lost_packet_cnt, UPLINK_RSSI_POS_X, UPLINK_RSSI_POS_Y, UPLINK_RSSI_SCALE * GLOBAL_SCALE);
#endif
#ifdef KBITRATE
draw_kbitrate(td->rx_status_sysair->cts, td->rx_status->kbitrate, td->rx_status_sysair->bitrate_measured_kbit, td->rx_status_sysair->bitrate_kbit, td->rx_status_sysair->skipped_fec_cnt, td->rx_status_sysair->injection_fail_cnt,td->rx_status_sysair->injection_time_block,KBITRATE_POS_X, KBITRATE_POS_Y, KBITRATE_SCALE * GLOBAL_SCALE);
#endif
#ifdef SYS
draw_sys(td->rx_status_sysair->cpuload, td->rx_status_sysair->temp, cpuload_gnd, temp_gnd, SYS_POS_X, SYS_POS_Y, SYS_SCALE * GLOBAL_SCALE);
#endif
#ifdef FLIGHTMODE
#ifdef MAVLINK
draw_mode(td->mav_flightmode, td->armed, FLIGHTMODE_POS_X, FLIGHTMODE_POS_Y, FLIGHTMODE_SCALE * GLOBAL_SCALE);
#endif
#endif
#if defined(RSSI)
draw_rssi(td->rssi, RSSI_POS_X, RSSI_POS_Y, RSSI_SCALE * GLOBAL_SCALE);
#endif
#if defined(CLIMB) && defined(MAVLINK)
draw_climb(td->mav_climb, CLIMB_POS_X, CLIMB_POS_Y, CLIMB_SCALE * GLOBAL_SCALE);
#endif
#ifdef AIRSPEED
draw_airspeed((int)td->airspeed, AIRSPEED_POS_X, AIRSPEED_POS_Y, AIRSPEED_SCALE * GLOBAL_SCALE);
#endif
#ifdef GPSSPEED
draw_gpsspeed((int)td->speed, GPSSPEED_POS_X, GPSSPEED_POS_Y, GPSSPEED_SCALE * GLOBAL_SCALE);
#endif
#ifdef BAROALT
draw_baroalt(td->baro_altitude, BAROALT_POS_X, BAROALT_POS_Y, BAROALT_SCALE * GLOBAL_SCALE);
#endif
#ifdef GPSALT
draw_gpsalt(td->altitude, GPSALT_POS_X, GPSALT_POS_Y, GPSALT_SCALE * GLOBAL_SCALE);
#endif
#ifdef COURSE_OVER_GROUND
draw_cog((int)td->cog, COURSE_OVER_GROUND_POS_X, COURSE_OVER_GROUND_POS_Y, COURSE_OVER_GROUND_SCALE * GLOBAL_SCALE);
#endif
#ifdef ALTLADDER
#if IMPERIAL == true
#if ALTLADDER_USEBAROALT == true
draw_alt_ladder((int)(td->baro_altitude * TO_FEET), ALTLADDER_POS_X, 50, ALTLADDER_SCALE * GLOBAL_SCALE);
#else
draw_alt_ladder((int)(td->altitude * TO_FEET), ALTLADDER_POS_X, 50, ALTLADDER_SCALE * GLOBAL_SCALE);
#endif
#else
#if ALTLADDER_USEBAROALT == true
draw_alt_ladder((int)td->baro_altitude, ALTLADDER_POS_X, 50, ALTLADDER_SCALE * GLOBAL_SCALE);
#else
draw_alt_ladder((int)td->altitude, ALTLADDER_POS_X, 50, ALTLADDER_SCALE * GLOBAL_SCALE);
#endif
#endif
#endif
#ifdef SPEEDLADDER
#if IMPERIAL == true
#if SPEEDLADDER_USEAIRSPEED == true
draw_speed_ladder((int)td->airspeed*TO_MPH, SPEEDLADDER_POS_X, 50, SPEEDLADDER_SCALE * GLOBAL_SCALE);
#else
draw_speed_ladder((int)td->speed*TO_MPH, SPEEDLADDER_POS_X, 50, SPEEDLADDER_SCALE * GLOBAL_SCALE);
#endif
#else
#if SPEEDLADDER_USEAIRSPEED == true
draw_speed_ladder((int)td->airspeed, SPEEDLADDER_POS_X, 50, SPEEDLADDER_SCALE * GLOBAL_SCALE);
#else
draw_speed_ladder((int)td->speed, SPEEDLADDER_POS_X, 50, SPEEDLADDER_SCALE * GLOBAL_SCALE);
#endif
#endif
#endif
#ifdef HOME_ARROW
#ifdef FRSKY
// draw_home_arrow((int)course_to((td->ns == 'N'? 1:-1) *td->latitude, (td->ns == 'E'? 1:-1) *td->longitude, home_lat, home_lon), HOME_ARROW_POS_X, HOME_ARROW_POS_Y, HOME_ARROW_SCALE * GLOBAL_SCALE);
#else
#if HOME_ARROW_USECOG == true
draw_home_arrow(course_to(home_lat, home_lon, td->latitude, td->longitude), td->cog, HOME_ARROW_POS_X, HOME_ARROW_POS_Y, HOME_ARROW_SCALE * GLOBAL_SCALE);
#else
draw_home_arrow(course_to(home_lat, home_lon, td->latitude, td->longitude), td->heading, HOME_ARROW_POS_X, HOME_ARROW_POS_Y, HOME_ARROW_SCALE * GLOBAL_SCALE);
#endif
if(td->heading>=360) td->heading=td->heading-360; // ?
#endif
#endif
#ifdef COMPASS
#if COMPASS_USECOG == true
draw_compass(td->cog, course_to(home_lat, home_lon, td->latitude, td->longitude), 50, COMPASS_POS_Y, COMPASS_SCALE * GLOBAL_SCALE);
#else
draw_compass(td->heading, course_to(home_lat, home_lon, td->latitude, td->longitude), 50, COMPASS_POS_Y, COMPASS_SCALE * GLOBAL_SCALE);
#endif
#endif
#ifdef BATT_STATUS
draw_batt_status(td->voltage, td->ampere, BATT_STATUS_POS_X, BATT_STATUS_POS_Y, BATT_STATUS_SCALE * GLOBAL_SCALE);
#endif
#ifdef POSITION
#if defined(FRSKY)
draw_position((td->ns == 'N'? 1:-1) * td->latitude, (td->ew == 'E'? 1:-1) * td->longitude, POSITION_POS_X, POSITION_POS_Y, POSITION_SCALE * GLOBAL_SCALE);
#endif
draw_position(td->latitude, td->longitude, POSITION_POS_X, POSITION_POS_Y, POSITION_SCALE * GLOBAL_SCALE);
#endif
#ifdef DISTANCE
#ifdef FRSKY
draw_home_distance((int)distance_between(home_lat, home_lon, (td->ns == 'N'? 1:-1) *td->latitude, (td->ns == 'E'? 1:-1) *td->longitude), home_set, DISTANCE_POS_X, DISTANCE_POS_Y, DISTANCE_SCALE * GLOBAL_SCALE);
#elif defined(LTM) || defined(MAVLINK) || defined(SMARTPORT)
draw_home_distance((int)distance_between(home_lat, home_lon, td->latitude, td->longitude), home_set, DISTANCE_POS_X, DISTANCE_POS_Y, DISTANCE_SCALE * GLOBAL_SCALE);
#endif
#endif
#ifdef DOWNLINK_RSSI
int i;
int best_dbm = -1000;
int ac = td->rx_status->wifi_adapter_cnt;
no_signal=true;
for(i=0; i<ac; ++i) { // find out which card has best signal (and if atleast one card has a signal)
if (td->rx_status->adapter[i].signal_good == 1) {
if (best_dbm < td->rx_status->adapter[i].current_signal_dbm) best_dbm = td->rx_status->adapter[i].current_signal_dbm;
}
if (td->rx_status->adapter[i].signal_good == 1) no_signal=false;
}
draw_total_signal(best_dbm, td->rx_status->received_block_cnt, td->rx_status->damaged_block_cnt, td->rx_status->lost_packet_cnt, td->rx_status->received_packet_cnt, td->rx_status->lost_per_block_cnt, DOWNLINK_RSSI_POS_X, DOWNLINK_RSSI_POS_Y, DOWNLINK_RSSI_SCALE * GLOBAL_SCALE);
#ifdef DOWNLINK_RSSI_DETAILED
for(i=0; i<ac; ++i) {
draw_card_signal(td->rx_status->adapter[i].current_signal_dbm, td->rx_status->adapter[i].signal_good, i, ac, td->rx_status->tx_restart_cnt, td->rx_status->adapter[i].received_packet_cnt, td->rx_status->adapter[i].wrong_crc_cnt, td->rx_status->adapter[i].type, td->rx_status->received_packet_cnt, td->rx_status->lost_packet_cnt, DOWNLINK_RSSI_DETAILED_POS_X, DOWNLINK_RSSI_DETAILED_POS_Y, DOWNLINK_RSSI_DETAILED_SCALE * GLOBAL_SCALE);
}
#endif
#endif
#ifdef SAT
#if defined(FRSKY)
//we assume that we have a fix if we get the NS and EW values from frsky protocol
if ((td->ew == 'E' || td->ew == 'W') && (td->ns == 'N' || td->ns == 'S')){
draw_sat(0, 2, SAT_POS_X, SAT_POS_Y, SAT_SCALE * GLOBAL_SCALE);
} else { //no fix
draw_sat(0, 0, SAT_POS_X, SAT_POS_Y, SAT_SCALE * GLOBAL_SCALE);
}
#elif defined(MAVLINK) || defined(SMARTPORT) || defined(LTM)
draw_sat(td->sats, td->fix, SAT_POS_X, SAT_POS_Y, SAT_SCALE * GLOBAL_SCALE);
#endif
#endif
#ifdef BATT_GAUGE
draw_batt_gauge(((td->voltage/CELLS)-CELL_MIN)/(CELL_MAX-CELL_MIN)*100, BATT_GAUGE_POS_X, BATT_GAUGE_POS_Y, BATT_GAUGE_SCALE * GLOBAL_SCALE);
#endif
#ifdef AHI
#if defined(FRSKY) || defined(SMARTPORT)
float x_val, y_val, z_val;
x_val = td->x;
y_val = td->y;
z_val = td->z;
#if AHI_SWAP_ROLL_AND_PITCH == true
draw_ahi(AHI_INVERT_ROLL * TO_DEG * (atan(y_val / sqrt((x_val*x_val) + (z_val*z_val)))), AHI_INVERT_PITCH * TO_DEG * (atan(x_val / sqrt((y_val*y_val)+(z_val*z_val)))), AHI_SCALE * GLOBAL_SCALE);
#else
draw_ahi(AHI_INVERT_ROLL * TO_DEG * (atan(x_val / sqrt((y_val*y_val) + (z_val*z_val)))), AHI_INVERT_PITCH * TO_DEG * (atan(y_val / sqrt((x_val*x_val)+(z_val*z_val)))), AHI_SCALE * GLOBAL_SCALE);
#endif // AHI_SWAP_ROLL_AND_PITCH
#elif defined(LTM) || defined(MAVLINK)
draw_ahi(AHI_INVERT_ROLL * td->roll, AHI_INVERT_PITCH * td->pitch, AHI_SCALE * GLOBAL_SCALE);
#endif //protocol
#endif //AHI
End(); // Render end (causes everything to be drawn on next vsync)
}
void draw_mode(int mode, int armed, float pos_x, float pos_y, float scale){
//autopilot mode, mavlink specific, could be used if mode is in telemetry data of other protocols as well
float text_scale = getWidth(2) * scale;
if (armed == 1){
switch (mode) {
#if COPTER == true
case 0: sprintf(buffer, "STAB"); break;
case 1: sprintf(buffer, "ACRO"); break;
case 2: sprintf(buffer, "ALTHOLD"); break;
case 3: sprintf(buffer, "AUTO"); break;
case 4: sprintf(buffer, "GUIDED"); break;
case 5: sprintf(buffer, "LOITER"); break;
case 6: sprintf(buffer, "RTL"); break;
case 7: sprintf(buffer, "CIRCLE"); break;
case 9: sprintf(buffer, "LAND"); break;
case 11: sprintf(buffer, "DRIFT"); break;
case 13: sprintf(buffer, "SPORT"); break;
case 14: sprintf(buffer, "FLIP"); break;
case 15: sprintf(buffer, "AUTOTUNE"); break;
case 16: sprintf(buffer, "POSHOLD"); break;
case 17: sprintf(buffer, "BRAKE"); break;
case 18: sprintf(buffer, "THROW"); break;
case 19: sprintf(buffer, "AVOIDADSB"); break;
case 20: sprintf(buffer, "GUIDEDNOGPS"); break;
case 255: sprintf(buffer, "-----"); break;
#else
case 0: sprintf(buffer, "MAN"); break;
case 1: sprintf(buffer, "CIRC"); break;
case 2: sprintf(buffer, "STAB"); break;
case 3: sprintf(buffer, "TRAI"); break;
case 4: sprintf(buffer, "ACRO"); break;
case 5: sprintf(buffer, "FBWA"); break;
case 6: sprintf(buffer, "FBWB"); break;
case 7: sprintf(buffer, "CRUZ"); break;
case 8: sprintf(buffer, "TUNE"); break;
case 10: sprintf(buffer, "AUTO"); break;
case 11: sprintf(buffer, "RTL"); break;
case 12: sprintf(buffer, "LOIT"); break;
case 15: sprintf(buffer, "GUID"); break;
case 16: sprintf(buffer, "INIT"); break;
case 255: sprintf(buffer, "-----"); break;
#endif
default: sprintf(buffer, "-----"); break; // TODO: find out why strange numbers when using zs6bujs telemetry logs, default to something more sensible like "unknown mode"
}
} else {
switch (mode) {
#if COPTER == true
case 0: sprintf(buffer, "[STAB]"); break;
case 1: sprintf(buffer, "[ACRO]"); break;
case 2: sprintf(buffer, "[ALTHOLD]"); break;
case 3: sprintf(buffer, "[AUTO]"); break;
case 4: sprintf(buffer, "[GUID]"); break;
case 5: sprintf(buffer, "[LOIT]"); break;
case 6: sprintf(buffer, "[RTL]"); break;
case 7: sprintf(buffer, "[CIRCLE]"); break;
case 9: sprintf(buffer, "[LAND]"); break;
case 11: sprintf(buffer, "[DRIFT]"); break;
case 13: sprintf(buffer, "[SPORT]"); break;
case 14: sprintf(buffer, "[FLIP]"); break;
case 15: sprintf(buffer, "[AUTOTUNE]"); break;
case 16: sprintf(buffer, "[POSHOLD]"); break;
case 17: sprintf(buffer, "[BRAKE]"); break;
case 18: sprintf(buffer, "[THROW]"); break;
case 19: sprintf(buffer, "[AVOIDADSB]"); break;
case 20: sprintf(buffer, "[GUIDEDNOGPS]"); break;
case 255: sprintf(buffer, "[-----]"); break;
#else
case 0: sprintf(buffer, "[MAN]"); break;
case 1: sprintf(buffer, "[CIRC]"); break;
case 2: sprintf(buffer, "[STAB]"); break;
case 3: sprintf(buffer, "[TRAI]"); break;
case 4: sprintf(buffer, "[ACRO]"); break;
case 5: sprintf(buffer, "[FBWA]"); break;
case 6: sprintf(buffer, "[FBWB]"); break;
case 7: sprintf(buffer, "[CRUZ]"); break;
case 8: sprintf(buffer, "[TUNE]"); break;
case 10: sprintf(buffer, "[AUTO]"); break;
case 11: sprintf(buffer, "[RTL]"); break;
case 12: sprintf(buffer, "[LOIT]"); break;
case 15: sprintf(buffer, "[GUID]"); break;
case 16: sprintf(buffer, "[INIT]"); break;
case 255: sprintf(buffer, "[-----]"); break;
#endif
default: sprintf(buffer, "[-----]"); break; // TODO: find out why strange numbers when using zs6bujs telemetry logs, default to something more sensible like "unknown mode"
}
}
TextMid(getWidth(pos_x), getHeight(pos_y), buffer, myfont, text_scale);
}
void draw_rssi(int rssi, float pos_x, float pos_y, float scale){
float text_scale = getWidth(2) * scale;
VGfloat width_value = TextWidth("00", myfont, text_scale);
TextEnd(getWidth(pos_x)-width_value, getHeight(pos_y), "", osdicons, text_scale * 0.6);
sprintf(buffer, "%02d", rssi);
TextEnd(getWidth(pos_x), getHeight(pos_y), buffer, myfont, text_scale);
Text(getWidth(pos_x), getHeight(pos_y), "%", myfont, text_scale*0.6);
}
void draw_cog(int cog, float pos_x, float pos_y, float scale){
float text_scale = getWidth(2) * scale;
VGfloat width_value = TextWidth("000°", myfont, text_scale);
TextEnd(getWidth(pos_x)-width_value, getHeight(pos_y), "", osdicons, text_scale*0.7);
sprintf(buffer, "%d°", cog);
TextEnd(getWidth(pos_x), getHeight(pos_y), buffer, myfont, text_scale);
}
void draw_climb(float climb, float pos_x, float pos_y, float scale){
float text_scale = getWidth(2) * scale;
VGfloat width_value = TextWidth("-00.0", myfont, text_scale);
TextEnd(getWidth(pos_x)-width_value, getHeight(pos_y), "", osdicons, text_scale*0.6);
if (climb > 0.0f) {
sprintf(buffer, "+%.1f", climb);
} else {
sprintf(buffer, "%.1f", climb);
}
TextEnd(getWidth(pos_x), getHeight(pos_y), buffer, myfont, text_scale);
Text(getWidth(pos_x)+getWidth(0.4), getHeight(pos_y), "m/s", myfont, text_scale*0.6);
}
void draw_baroalt(float baroalt, float pos_x, float pos_y, float scale){
float text_scale = getWidth(2) * scale;
#if IMPERIAL == true
VGfloat width_value = TextWidth("0000", myfont, text_scale);
sprintf(buffer, "%.0f", baroalt*TO_FEET);
#else
VGfloat width_value = TextWidth("000.0", myfont, text_scale);
sprintf(buffer, "%.1f", baroalt);
#endif
TextEnd(getWidth(pos_x), getHeight(pos_y), buffer, myfont, text_scale);
TextEnd(getWidth(pos_x)-width_value-getWidth(0.3)*scale, getHeight(pos_y), " ", osdicons, text_scale*0.7);
#if IMPERIAL == true
Text(getWidth(pos_x)+getWidth(0.4), getHeight(pos_y), "ft", myfont, text_scale*0.6);
#else
Text(getWidth(pos_x)+getWidth(0.4), getHeight(pos_y), "m", myfont, text_scale*0.6);
#endif
}
void draw_gpsalt(float gpsalt, float pos_x, float pos_y, float scale){
float text_scale = getWidth(2) * scale;
#if IMPERIAL == true
VGfloat width_value = TextWidth("0000", myfont, text_scale);
sprintf(buffer, "%.0f", gpsalt*TO_FEET);
#else
VGfloat width_value = TextWidth("000.0", myfont, text_scale);
sprintf(buffer, "%.1f", gpsalt);
#endif
TextEnd(getWidth(pos_x), getHeight(pos_y), buffer, myfont, text_scale);
TextEnd(getWidth(pos_x)-width_value-getWidth(0.3)*scale, getHeight(pos_y), " ", osdicons, text_scale*0.7);
#if IMPERIAL == true
Text(getWidth(pos_x)+getWidth(0.4), getHeight(pos_y), "ft", myfont, text_scale*0.6);
#else
Text(getWidth(pos_x)+getWidth(0.4), getHeight(pos_y), "m", myfont, text_scale*0.6);
#endif
}
void draw_airspeed(int airspeed, float pos_x, float pos_y, float scale){
float text_scale = getWidth(2) * scale;
VGfloat width_value = TextWidth("100", myfont, text_scale);
VGfloat width_speedo = TextWidth("", osdicons, text_scale*0.65) + getWidth(0.5)*scale;
TextEnd(getWidth(pos_x)-width_value, getHeight(pos_y), "", osdicons, text_scale*0.65);
TextEnd(getWidth(pos_x)-width_value-width_speedo, getHeight(pos_y), "", osdicons, text_scale*0.65);
#if IMPERIAL == true
sprintf(buffer, "%d", airspeed*TO_MPH);
#else
sprintf(buffer, "%d", airspeed);
#endif
TextEnd(getWidth(pos_x), getHeight(pos_y), buffer, myfont, text_scale);
#if IMPERIAL == true
Text(getWidth(pos_x)+getWidth(0.4), getHeight(pos_y), "mph", myfont, text_scale*0.6);
#else
Text(getWidth(pos_x)+getWidth(0.4), getHeight(pos_y), "km/h", myfont, text_scale*0.6);
#endif
}
void draw_gpsspeed(int gpsspeed, float pos_x, float pos_y, float scale){
float text_scale = getWidth(2) * scale;
VGfloat width_value = TextWidth("100", myfont, text_scale);
VGfloat width_speedo = TextWidth("", osdicons, text_scale*0.65);
TextEnd(getWidth(pos_x)-width_value, getHeight(pos_y), "", osdicons, text_scale*0.65);
TextEnd(getWidth(pos_x)-width_value-width_speedo, getHeight(pos_y), "", osdicons, text_scale*0.7);
#if IMPERIAL == true
sprintf(buffer, "%d", gpsspeed*TO_MPH);
#else
sprintf(buffer, "%d", gpsspeed);
#endif
TextEnd(getWidth(pos_x), getHeight(pos_y), buffer, myfont, text_scale);
#if IMPERIAL == true
Text(getWidth(pos_x)+getWidth(0.4), getHeight(pos_y), "mph", myfont, text_scale*0.6);
#else
Text(getWidth(pos_x)+getWidth(0.4), getHeight(pos_y), "km/h", myfont, text_scale*0.6);
#endif
}
void draw_uplink_signal(int8_t uplink_signal, int uplink_lostpackets, int8_t rc_signal, int rc_lostpackets, float pos_x, float pos_y, float scale){
float text_scale = getWidth(2) * scale;
VGfloat height_text = TextHeight(myfont, text_scale*0.6)+getHeight(0.3)*scale;
VGfloat width_value = TextWidth("-00", myfont, text_scale);
VGfloat width_symbol = TextWidth(" ", osdicons, text_scale*0.7);
StrokeWidth(OUTLINEWIDTH);
if ((uplink_signal < -125) && (rc_signal < -125)) { // both no signal, display red dashes
Fill(255,20,20,getOpacity(COLOR)); // red
Stroke(255,20,20,getOpacity(OUTLINECOLOR));
sprintf(buffer, "-- ");
} else if (rc_signal < -125) { // only r/c no signal, so display uplink signal
Fill(COLOR);
Stroke(OUTLINECOLOR);
sprintf(buffer, "%02d", uplink_signal);
} else { // if both have signal, display r/c signal
Fill(COLOR);
Stroke(OUTLINECOLOR);
sprintf(buffer, "%02d", rc_signal);
}
TextEnd(getWidth(pos_x), getHeight(pos_y), buffer, myfont, text_scale);
Fill(COLOR);
Stroke(OUTLINECOLOR);
Text(getWidth(pos_x), getHeight(pos_y), "dBm", myfont, text_scale*0.6);
sprintf(buffer, "%d/%d", rc_lostpackets, uplink_lostpackets);
Text(getWidth(pos_x)-width_value-width_symbol, getHeight(pos_y)-height_text, buffer, myfont, text_scale*0.6);
TextEnd(getWidth(pos_x)-width_value - getWidth(0.3) * scale, getHeight(pos_y), "", osdicons, text_scale * 0.7);
}
void draw_kbitrate(int cts, int kbitrate, uint16_t kbitrate_measured_tx, uint16_t kbitrate_tx, uint32_t fecs_skipped, uint32_t injection_failed, long long injection_time,float pos_x, float pos_y, float scale){
float text_scale = getWidth(2) * scale;
VGfloat height_text_small = TextHeight(myfont, text_scale*0.6)+getHeight(0.3)*scale;
VGfloat width_value = TextWidth("10.0", myfont, text_scale);
VGfloat width_symbol = TextWidth("", osdicons, text_scale*0.8);
// VGfloat width_value_ms = TextWidth("0.0", myfont, text_scale*0.6);
float mbit = (float)kbitrate / 1000;
float mbit_measured = (float)kbitrate_measured_tx / 1000;
float mbit_tx = (float)kbitrate_tx / 1000;
float ms = (float)injection_time / 1000;
if (cts == 0) {
sprintf(buffer, "%.1f (%.1f)", mbit_tx, mbit_measured);
} else {
sprintf(buffer, "%.1f (%.1f) CTS", mbit_tx, mbit_measured);
}
Text(getWidth(pos_x)-width_value-width_symbol, getHeight(pos_y)-height_text_small, buffer, myfont, text_scale*0.6);
if (fecs_skipped > fecs_skipped_last) {
Fill(255,20,20,getOpacity(COLOR)); // red
Stroke(255,20,20,getOpacity(OUTLINECOLOR));
} else {
Fill(COLOR);
Stroke(OUTLINECOLOR);
}
fecs_skipped_last = fecs_skipped;
TextEnd(getWidth(pos_x)-width_value, getHeight(pos_y), "", osdicons, text_scale * 0.8);
if (mbit > mbit_measured*0.98) {
Fill(255,20,20,getOpacity(COLOR)); // red
Stroke(255,20,20,getOpacity(OUTLINECOLOR));
} else if (mbit > mbit_measured*0.90) {
Fill(229,255,20,getOpacity(COLOR)); // yellow
Stroke(229,255,20,getOpacity(OUTLINECOLOR));
} else {
Fill(COLOR);
Stroke(OUTLINECOLOR);
}
sprintf(buffer, "%.1f", mbit);
TextEnd(getWidth(pos_x), getHeight(pos_y), buffer, myfont, text_scale);
Fill(COLOR);
Stroke(OUTLINECOLOR);
Text(getWidth(pos_x), getHeight(pos_y), "Mbit", myfont, text_scale*0.6);
// sprintf(buffer, "%.1f", ms);
// TextEnd(getWidth(pos_x)-width_value-width_symbol+width_value_ms, getHeight(pos_y)-height_text-height_text_small, buffer, myfont, text_scale*0.6);
// sprintf(buffer, "ms");
// Text(getWidth(pos_x)-width_value-width_symbol+width_value_ms, getHeight(pos_y)-height_text-height_text_small, buffer, myfont, text_scale*0.4);
sprintf(buffer, "%d/%d",injection_failed,fecs_skipped);
Text(getWidth(pos_x)-width_value-width_symbol, getHeight(pos_y)-height_text_small-height_text_small, buffer, myfont, text_scale*0.6);
}
void draw_sys(uint8_t cpuload_air, uint8_t temp_air, uint8_t cpuload_gnd, uint8_t temp_gnd, float pos_x, float pos_y, float scale) {
float text_scale = getWidth(2) * scale;
VGfloat height_text = TextHeight(myfont, text_scale)+getHeight(0.3)*scale;
VGfloat width_value = TextWidth("00", myfont, text_scale) + getWidth(0.5)*scale;
VGfloat width_label = TextWidth("%", myfont, text_scale*0.6) + getWidth(0.5)*scale;
VGfloat width_ag = TextWidth("A", osdicons, text_scale*0.4) - getWidth(0.3)*scale;
TextEnd(getWidth(pos_x)-width_value-width_ag, getHeight(pos_y), "", osdicons, text_scale*0.7);
TextEnd(getWidth(pos_x)-width_value, getHeight(pos_y), "A", myfont, text_scale*0.4);
if (cpuload_air > 95) {
Fill(255,20,20,getOpacity(COLOR)); // red
Stroke(255,20,20,getOpacity(OUTLINECOLOR));
} else if (cpuload_air > 85) {
Fill(229,255,20,getOpacity(COLOR)); // yellow
Stroke(229,255,20,getOpacity(OUTLINECOLOR));
} else {
Fill(COLOR);
Stroke(OUTLINECOLOR);
}
sprintf(buffer, "%d", cpuload_air);
TextEnd(getWidth(pos_x), getHeight(pos_y), buffer, myfont, text_scale);
sprintf(buffer, "%%");
Text(getWidth(pos_x), getHeight(pos_y), buffer, myfont, text_scale*0.6);
if (temp_air > 79) {
Fill(255,20,20,getOpacity(COLOR)); // red
Stroke(255,20,20,getOpacity(OUTLINECOLOR));
} else if (temp_air > 74) {
Fill(229,255,20,getOpacity(COLOR)); // yellow
Stroke(229,255,20,getOpacity(OUTLINECOLOR));
} else {
Fill(COLOR);
Stroke(OUTLINECOLOR);
}
sprintf(buffer, "%d°", temp_air);
TextEnd(getWidth(pos_x)+width_value+width_label+getWidth(0.7), getHeight(pos_y), buffer, myfont, text_scale);
Fill(COLOR);
Stroke(OUTLINECOLOR);
TextEnd(getWidth(pos_x)-width_value-width_ag, getHeight(pos_y)-height_text, "", osdicons, text_scale*0.7);
TextEnd(getWidth(pos_x)-width_value, getHeight(pos_y)-height_text, "G", myfont, text_scale*0.4);
if (cpuload_gnd > 95) {
Fill(255,20,20,getOpacity(COLOR)); // red
Stroke(255,20,20,getOpacity(OUTLINECOLOR));
} else if (cpuload_gnd > 85) {
Fill(229,255,20,getOpacity(COLOR)); // yellow
Stroke(229,255,20,getOpacity(OUTLINECOLOR));
} else {
Fill(COLOR);
Stroke(OUTLINECOLOR);
}
sprintf(buffer, "%d", cpuload_gnd);
TextEnd(getWidth(pos_x), getHeight(pos_y)-height_text, buffer, myfont, text_scale);
Text(getWidth(pos_x), getHeight(pos_y)-height_text, "%", myfont, text_scale*0.6);
if (temp_gnd > 79) {
Fill(255,20,20,getOpacity(COLOR)); // red
Stroke(255,20,20,getOpacity(OUTLINECOLOR));
} else if (temp_gnd > 74) {
Fill(229,255,20,getOpacity(COLOR)); // yellow
Stroke(229,255,20,getOpacity(OUTLINECOLOR));
} else {
Fill(COLOR);
Stroke(OUTLINECOLOR);
}
sprintf(buffer, "%d°", temp_gnd);
TextEnd(getWidth(pos_x)+width_value+width_label+getWidth(0.7), getHeight(pos_y)-height_text, buffer, myfont, text_scale);
Fill(COLOR);
Stroke(OUTLINECOLOR);
}
void draw_message(int severity, char line1[30], char line2[30], char line3[30], float pos_x, float pos_y, float scale) {
float text_scale = getWidth(2) * scale;
VGfloat height_text = TextHeight(myfont, text_scale*0.7)+getHeight(0.3)*scale;
VGfloat height_text_small = TextHeight(myfont, text_scale*0.55)+getHeight(0.3)*scale;
VGfloat width_text = TextWidth(line1, myfont, text_scale*0.7);
if (severity == 0) { // high severity
Fill(255,20,20,getOpacity(COLOR)); // red
Stroke(255,20,20,getOpacity(OUTLINECOLOR));
TextEnd(getWidth(pos_x)-width_text/2 - getWidth(0.3)*scale, getHeight(pos_y), "", osdicons, text_scale*0.8);
Text(getWidth(pos_x)+width_text/2 + getWidth(0.3)*scale, getHeight(pos_y), "", osdicons, text_scale*0.8);
} else if (severity == 1) { // medium
Fill(229,255,20,getOpacity(COLOR)); // yellow
Stroke(229,255,20,getOpacity(OUTLINECOLOR));
TextEnd(getWidth(pos_x)-width_text/2 - getWidth(0.3)*scale, getHeight(pos_y), "", osdicons, text_scale*0.8);
Text(getWidth(pos_x)+width_text/2 + getWidth(0.3)*scale, getHeight(pos_y), "", osdicons, text_scale*0.8);
} else { // low
Fill(COLOR);
Stroke(OUTLINECOLOR);
}
Fill(COLOR);
Stroke(OUTLINECOLOR);
TextMid(getWidth(pos_x), getHeight(pos_y), line1, myfont, text_scale*0.7);
TextMid(getWidth(pos_x), getHeight(pos_y) - height_text, line2, myfont, text_scale*0.55);
TextMid(getWidth(pos_x), getHeight(pos_y) - height_text-height_text_small, line3, myfont, text_scale*0.55);
}
void draw_home_arrow(float abs_heading, float craft_heading, float pos_x, float pos_y, float scale){
//abs_heading is the absolute direction/bearing the arrow should point eg bearing to home could be 45 deg
//because arrow is drawn relative to the osd/camera view we need to offset by craft's heading
#if HOME_ARROW_INVERT == true
abs_heading = abs_heading - 180;
#endif
float rel_heading = abs_heading - craft_heading; //direction arrow needs to point relative to camera/osd/craft
if (rel_heading < 0) rel_heading += 360;
if (rel_heading >= 360) rel_heading -=360;
pos_x = getWidth(pos_x);
pos_y = getHeight(pos_y);
//offset for arrow, so middle of the arrow is at given position
pos_x -= getWidth(1.25) * scale;
pos_y -= getWidth(1.25) * scale;
float x[8] = {getWidth(0.5)*scale+pos_x, getWidth(0.5)*scale+pos_x, pos_x, getWidth(1.25)*scale+pos_x, getWidth(2.5)*scale+pos_x, getWidth(2)*scale+pos_x, getWidth(2)*scale+pos_x, getWidth(0.5)*scale+pos_x};
float y[8] = {pos_y, getWidth(1.5)*scale+pos_y, getWidth(1.5)*scale+pos_y, getWidth(2.5)*scale+pos_y, getWidth(1.5)*scale+pos_y, getWidth(1.5)*scale+pos_y, pos_y, pos_y};
rotatePoints(x, y, rel_heading, 8, pos_x+getWidth(1.25)*scale,pos_y+getWidth(1.25)*scale);
Polygon(x, y, 8);
Polyline(x, y, 8);
}
void draw_compass(float heading, float home_heading, float pos_x, float pos_y, float scale){
float text_scale = getHeight(1.5) * scale;
float width_ladder = getHeight(16) * scale;
float width_element = getWidth(0.25) * scale;
float height_element = getWidth(0.50) * scale;
float ratio = width_ladder / 180;
VGfloat height_text = TextHeight(myfont, text_scale*1.5)+getHeight(0.1)*scale;
sprintf(buffer, "%.0f°", heading);
TextMid(getWidth(pos_x), getHeight(pos_y) - height_element - height_text, buffer, myfont, text_scale*1.5);
int i = heading - 90;
char* c;
bool draw = false;
while (i <= heading + 90) { //find all values from heading - 90 to heading + 90 that are % 15 == 0
float x = getWidth(pos_x) + (i - heading) * ratio;
if (i % 30 == 0) {
Rect(x-width_element/2, getHeight(pos_y), width_element, height_element*2);
}else if (i % 15 == 0) {
Rect(x-width_element/2, getHeight(pos_y), width_element, height_element);
}else{
i++;
continue;
}
int j = i;
if (j < 0) j += 360;
if (j >= 360) j -= 360;
switch (j) {
case 0:
draw = true;
c = "N";
break;
case 90:
draw = true;
c = "E";
break;
case 180:
draw = true;
c = "S";
break;
case 270:
draw = true;
c = "W";
break;
}
if (draw == true) {
TextMid(x, getHeight(pos_y) + height_element*3.5, c, myfont, text_scale*1.5);
draw = false;
}
if (j == home_heading) {
TextMid(x, getHeight(pos_y) + height_element, "", osdicons, text_scale*1.3);
}
i++;
}
float rel_home = home_heading-heading;
if (rel_home<0) rel_home+= 360;
if ((rel_home > 90) && (rel_home <= 180)) { TextMid(getWidth(pos_x)+width_ladder/2 * 1.2, getHeight(pos_y), "", osdicons, text_scale * 0.8); }
else if ((rel_home > 180) && (rel_home < 270)) { TextMid(getWidth(pos_x)-width_ladder/2 * 1.2, getHeight(pos_y), "", osdicons, text_scale * 0.8); }
TextMid(getWidth(pos_x), getHeight(pos_y) + height_element*2.5+height_text, "", osdicons, text_scale*2);
}
void draw_batt_status(float voltage, float current, float pos_x, float pos_y, float scale){
float text_scale = getWidth(2) * scale;
VGfloat height_text = TextHeight(myfont, text_scale)+getHeight(0.3)*scale;
#if BATT_STATUS_CURRENT == true
sprintf(buffer, "%.1f", current);
TextEnd(getWidth(pos_x), getHeight(pos_y), buffer, myfont, text_scale);
Text(getWidth(pos_x), getHeight(pos_y), " A", myfont, text_scale*0.6);
#endif
sprintf(buffer, "%.1f", voltage);
TextEnd(getWidth(pos_x), getHeight(pos_y)+height_text, buffer, myfont, text_scale);
Text(getWidth(pos_x), getHeight(pos_y)+height_text, " V", myfont, text_scale*0.6);
}
void draw_position(float lat, float lon, float pos_x, float pos_y, float scale){
float text_scale = getWidth(2) * scale;
VGfloat height_text = TextHeight(myfont, text_scale)+getHeight(0.3)*scale;
VGfloat width_value = TextWidth("-100.000000", myfont, text_scale);
TextEnd(getWidth(pos_x) - width_value, getHeight(pos_y), " ", osdicons, text_scale*0.6);
sprintf(buffer, "%.6f", lon);
TextEnd(getWidth(pos_x), getHeight(pos_y), buffer, myfont, text_scale);
TextEnd(getWidth(pos_x) - width_value, getHeight(pos_y)+height_text, " ", osdicons, text_scale*0.6);
sprintf(buffer, "%.6f", lat);
TextEnd(getWidth(pos_x), getHeight(pos_y)+height_text, buffer, myfont, text_scale);
}
void draw_home_distance(int distance, bool home_fixed, float pos_x, float pos_y, float scale){
float text_scale = getWidth(2) * scale;
VGfloat width_value = TextWidth("00000", myfont, text_scale);
if (!home_fixed){
Fill(255,20,20,getOpacity(COLOR)); // red
Stroke(255,20,20,getOpacity(OUTLINECOLOR));
}else{
Fill(COLOR);
Stroke(OUTLINECOLOR);
}
TextEnd(getWidth(pos_x)-width_value-getWidth(0.2), getHeight(pos_y), "", osdicons, text_scale * 0.6);
Fill(COLOR);
Stroke(OUTLINECOLOR);
#if IMPERIAL == true
Text(getWidth(pos_x)+getWidth(0.4), getHeight(pos_y), "ft", myfont, text_scale*0.6);
sprintf(buffer, "%05d", (int)(distance*TO_FEET));
#else
Text(getWidth(pos_x)+getWidth(0.4), getHeight(pos_y), "m", myfont, text_scale*0.6);
sprintf(buffer, "%05d", distance);
#endif
TextEnd(getWidth(pos_x), getHeight(pos_y), buffer, myfont, text_scale);
}
void draw_alt_ladder(int alt, float pos_x, float pos_y, float scale){
float text_scale = getHeight(1.3) * scale;
float width_element = getWidth(0.50) * scale;
float height_element = getWidth(0.25) * scale;
float height_ladder = height_element * 21 * 4;
float px = getWidth(pos_x); // ladder x position
float pxlabel = getWidth(pos_x) + width_element*2; // alt labels on ladder x position
float range = 100; // alt range range of display, i.e. lowest and highest number on the ladder
float range_half = range / 2;
float ratio_alt = height_ladder / range;
VGfloat offset_text_ladder = (TextHeight(myfont, text_scale) / 2) - height_element/2 - getHeight(0.25)*scale;
VGfloat offset_symbol = (TextHeight(osdicons, text_scale*2) / 2) - height_element/2 - getHeight(0.18)*scale;
VGfloat offset_alt_value = (TextHeight(myfont, text_scale*2) / 2) -height_element/2 - getHeight(0.4)*scale;
VGfloat width_symbol = TextWidth("", osdicons, text_scale*2);
VGfloat width_ladder_value = TextWidth("000", myfont, text_scale);
sprintf(buffer, "%d", alt); // large alt number
Text(pxlabel+width_ladder_value+width_symbol, getHeight(pos_y)-offset_alt_value, buffer, myfont, text_scale*2);
Text(pxlabel+width_ladder_value, getHeight(pos_y)-offset_symbol, "", osdicons, text_scale*2);
int k;
for (k = (int) (alt - range / 2); k <= alt + range / 2; k++) {
int y = getHeight(pos_y) + (k - alt) * ratio_alt;
if (k % 50 == 0) {
Rect(px-width_element, y, width_element*2, height_element);
sprintf(buffer, "%d", k);
Text(pxlabel, y-offset_text_ladder, buffer, myfont, text_scale);
} else if (k % 5 == 0) {
Rect(px-width_element, y, width_element, height_element);
}
}
}
void draw_speed_ladder(int speed, float pos_x, float pos_y, float scale){
float text_scale = getHeight(1.3) * scale;
float width_element = getWidth(0.50) * scale;
float height_element = getWidth(0.25) * scale;
float height_ladder = height_element * 21 * 4;
float px = getWidth(pos_x); // ladder x position
float pxlabel = getWidth(pos_x) - width_element*2; // speed labels on ladder x position
float range = 40; // speed range of display, i.e. lowest and highest number on the ladder
float range_half = range / 2;
float ratio_speed = height_ladder / range;
VGfloat offset_text_ladder = (TextHeight(myfont, text_scale) / 2) - height_element/2 - getHeight(0.25)*scale;
VGfloat offset_symbol = (TextHeight(osdicons, text_scale*2) / 2) - height_element/2 - getHeight(0.18)*scale;
VGfloat offset_speed_value = (TextHeight(myfont, text_scale*2) / 2) -height_element/2 - getHeight(0.4)*scale;
VGfloat width_symbol = TextWidth("", osdicons, text_scale*2);
VGfloat width_ladder_value = TextWidth("0", myfont, text_scale);