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.
28 #include "definitions.h"
29 #include "opentx_types.h"
32 #define SWITCH_SIMU(a, b) (a)
34 #define SWITCH_SIMU(a, b) (b)
38 #define IS_PCBSKY9X true
39 #define CASE_PCBSKY9X(x) x,
41 #define IS_PCBSKY9X false
42 #define CASE_PCBSKY9X(x)
46 #define CASE_CPUARM(x) x,
47 #define IF_CPUARM(x) x
49 #define CASE_CPUARM(x)
53 #if defined(VARIO) && defined(CPUARM)
54 #define CASE_VARIO_CPUARM(x) x,
56 #define CASE_VARIO_CPUARM(x)
60 #define CASE_LUA(x) x,
65 #if defined(CPUARM) || defined(CPUM2560)
66 #define CASE_PERSISTENT_TIMERS(x) x,
68 #define CASE_PERSISTENT_TIMERS(x)
72 #define CASE_RTCLOCK(x) x,
74 #define CASE_RTCLOCK(x)
78 #define CASE_BUZZER(x) x,
80 #define CASE_BUZZER(x)
84 #define CASE_AUDIO(x) x,
90 #define CASE_VOICE(x) x,
95 #if defined(PWM_BACKLIGHT)
96 #define CASE_PWM_BACKLIGHT(x) x,
98 #define CASE_PWM_BACKLIGHT(x)
101 #if defined(TELEMETRY_FRSKY) && defined(FRSKY_HUB) && defined(GPS)
102 #define CASE_GPS(x) x,
108 #define CASE_VARIO(x) x,
110 #define CASE_VARIO(x)
114 #define CASE_HAPTIC(x) x,
116 #define CASE_HAPTIC(x)
120 #define CASE_SPLASH(x) x,
122 #define CASE_SPLASH(x)
125 #if defined(TELEMETRY_FRSKY)
126 #define CASE_FRSKY(x) x,
128 #define CASE_FRSKY(x)
131 #if defined(TELEMETRY_MAVLINK)
132 #define CASE_MAVLINK(x) x,
134 #define CASE_MAVLINK(x)
138 #define CASE_PXX(x) x,
144 #define CASE_SDCARD(x) x,
146 #define CASE_SDCARD(x)
149 #if defined(BLUETOOTH) && !(defined(PCBX9E) && !defined(DEBUG))
150 #define CASE_BLUETOOTH(x) x,
152 #define CASE_BLUETOOTH(x)
156 #define CASE_HELI(x) x,
161 #if defined(TEMPLATES)
162 #define CASE_TEMPLATES(x) x,
164 #define CASE_TEMPLATES(x)
167 #if defined(FLIGHT_MODES)
168 #define CASE_FLIGHT_MODES(x) x,
170 #define CASE_FLIGHT_MODES(x)
174 #define CASE_CURVES(x) x,
176 #define CASE_CURVES(x)
180 #define CASE_GVARS(x) x,
182 #define CASE_GVARS(x)
185 #if defined(PCBX9DP) || defined(PCBX9E)
186 #define CASE_PCBX9E_PCBX9DP(x) x,
188 #define CASE_PCBX9E_PCBX9DP(x)
192 #define CASE_PCBX9E(x) x,
194 #define CASE_PCBX9E(x)
197 #if defined(BLUETOOTH) && (!defined(PCBX9E) || defined(DEBUG))
198 #define CASE_BLUETOOTH(x) x,
200 #define CASE_BLUETOOTH(x)
203 #if defined(PCBSKY9X) && !defined(AR9X) && !defined(REVA)
204 #define TX_CAPACITY_MEASUREMENT
205 #define CASE_CAPACITY(x) x,
207 #define CASE_CAPACITY(x)
210 #if ROTARY_ENCODERS > 0
211 #define ROTARY_ENCODER_NAVIGATION
215 #define IS_FAI_ENABLED() true
216 #define IF_FAI_CHOICE(x)
217 #elif defined(FAI_CHOICE)
218 #define IS_FAI_ENABLED() g_eeGeneral.fai
219 #define IF_FAI_CHOICE(x) x,
221 #define IS_FAI_ENABLED() false
222 #define IF_FAI_CHOICE(x)
225 #define IS_FAI_FORBIDDEN(idx) (IS_FAI_ENABLED() && idx >= MIXSRC_FIRST_TELEM)
227 #if defined(BLUETOOTH)
229 #define IS_BLUETOOTH_TRAINER() (g_model.trainerMode == TRAINER_MODE_SLAVE_BLUETOOTH)
231 #define IS_BLUETOOTH_TRAINER() (g_model.trainerMode == TRAINER_MODE_MASTER_BLUETOOTH || g_model.trainerMode == TRAINER_MODE_SLAVE_BLUETOOTH)
234 #define IS_BLUETOOTH_TRAINER() false
238 #define MASTER_VOLUME
241 #if !defined(CPUM64) && !defined(ACCURAT_THROTTLE_TIMER)
242 // code cost is about 16 bytes for higher throttle accuracy for timer
243 // would not be noticable anyway, because all version up to this change had only 16 steps;
244 // now it has already 32 steps; this define would increase to 128 steps
245 #if !defined(ACCURAT_THROTTLE_TIMER)
246 #define ACCURAT_THROTTLE_TIMER
250 // RESX range is used for internal calculation; The menu says -100.0 to 100.0; internally it is -1024 to 1024 to allow some optimizations
251 #define RESX_SHIFT 10
254 #define RESXul 1024ul
259 #if defined(DISK_CACHE)
260 #include "disk_cache.h"
264 #include "targets/simu/simpgmspace.h"
265 #elif defined(CPUARM)
266 typedef const unsigned char pm_uchar
;
267 typedef const char pm_char
;
268 typedef const uint16_t pm_uint16_t
;
269 typedef const uint8_t pm_uint8_t
;
270 typedef const int16_t pm_int16_t
;
271 typedef const int8_t pm_int8_t
;
272 #define pgm_read_byte(address_short) (*(uint8_t*)(address_short))
273 #define PSTR(adr) adr
275 #define pgm_read_adr(x) *(x)
282 #if defined(PCBFLAMENCO)
283 #elif defined(PCBTARANIS) || defined(PCBHORUS)
284 #define SWSRC_THR SWSRC_SF2
285 #define SWSRC_GEA SWSRC_SG2
286 #define SWSRC_ID0 SWSRC_SA0
287 #define SWSRC_ID1 SWSRC_SA1
288 #define SWSRC_ID2 SWSRC_SA2
289 #define IS_MOMENTARY(sw) false // TODO
291 #define SW_DSM2_BIND SW_TRN
294 #define NUM_PSWITCH (SWSRC_LAST_SWITCH-SWSRC_FIRST_SWITCH+1)
296 #include "myeeprom.h"
299 void memclear(void * ptr
, uint8_t size
);
301 #define memclear(p, s) memset(p, 0, s)
304 void memswap(void * a
, void * b
, uint8_t size
);
306 #if defined(PCBX9D) || defined(PCBX9DP) || defined(PCBX9E) || defined(PCBHORUS)
307 #define POT_CONFIG(x) ((g_eeGeneral.potsConfig >> (2*((x)-POT1)))&0x03)
308 #define IS_POT_MULTIPOS(x) (IS_POT(x) && POT_CONFIG(x)==POT_MULTIPOS_SWITCH)
309 #define IS_POT_WITHOUT_DETENT(x) (IS_POT(x) && POT_CONFIG(x)==POT_WITHOUT_DETENT)
310 #define IS_SLIDER_AVAILABLE(x) ((x) == SLIDER1 || (x) == SLIDER2 || (IS_SLIDER(x) && (g_eeGeneral.slidersConfig & (0x01 << ((x)-SLIDER1)))))
311 #define IS_POT_AVAILABLE(x) (IS_POT(x) && POT_CONFIG(x)!=POT_NONE)
312 #define IS_POT_SLIDER_AVAILABLE(x) (IS_POT_AVAILABLE(x) || IS_SLIDER_AVAILABLE(x))
313 #define IS_MULTIPOS_CALIBRATED(cal) (cal->count>0 && cal->count<XPOTS_MULTIPOS_COUNT)
315 #define IS_POT_MULTIPOS(x) (false)
316 #define IS_POT_WITHOUT_DETENT(x) (false)
317 #define IS_POT_SLIDER_AVAILABLE(x) (true)
318 #define IS_MULTIPOS_CALIBRATED(cal) (false)
319 #elif defined(PCBFLAMENCO)
320 #define IS_POT_MULTIPOS(x) (false)
321 #define IS_POT_WITHOUT_DETENT(x) (false)
322 #define IS_POT_SLIDER_AVAILABLE(x) (true)
323 #define IS_MULTIPOS_CALIBRATED(cal) (false)
325 #define IS_POT_MULTIPOS(x) (false)
326 #define IS_POT_WITHOUT_DETENT(x) (true)
327 #define IS_POT_SLIDER_AVAILABLE(x) (true)
328 #define IS_MULTIPOS_CALIBRATED(cal) (false)
331 #if defined(PWR_BUTTON_PRESS)
332 #define pwrOffPressed() pwrPressed()
334 #define pwrOffPressed() (!pwrPressed())
337 #define PWR_PRESS_SHUTDOWN_DELAY 300 // 3s
339 #define GET_LOWRES_POT_POSITION(i) (getValue(MIXSRC_FIRST_POT+(i)) >> 4)
340 #define SAVE_POT_POSITION(i) g_model.potsWarnPosition[i] = GET_LOWRES_POT_POSITION(i)
342 #if ROTARY_ENCODERS > 0
343 #define IF_ROTARY_ENCODERS(x) x,
345 #define IF_ROTARY_ENCODERS(x)
348 #define PPM_CENTER 1500
350 #if defined(PPM_CENTER_ADJUSTABLE)
351 #define PPM_CH_CENTER(ch) (PPM_CENTER + limitAddress(ch)->ppmCenter)
353 #define PPM_CH_CENTER(ch) (PPM_CENTER)
358 #include "io/io_arm.h"
359 // This doesn't need protection on this processor
360 extern volatile tmr10ms_t g_tmr10ms
;
361 #define get_tmr10ms() g_tmr10ms
363 extern volatile tmr10ms_t g_tmr10ms
;
364 extern inline uint16_t get_tmr10ms()
374 #if defined(NAVIGATION_STICKS)
375 extern uint8_t StickScrollAllowed
;
376 extern uint8_t StickScrollTimer
;
377 #define STICK_SCROLL_TIMEOUT 9
378 #define STICK_SCROLL_DISABLE() StickScrollAllowed = 0
380 #define STICK_SCROLL_DISABLE()
388 #include "storage/storage.h"
389 #include "pulses/pulses.h"
392 // Order is the same as in enum Protocols in myeeprom.h (none, ppm, xjt, dsm, crossfire, multi, r9m)
393 static const int8_t maxChannelsModules
[] = { 0, 8, 8, -2, 8, 4, 8}; // relative to 8!
394 static const int8_t maxChannelsXJT
[] = { 0, 8, 0, 4 }; // relative to 8!
395 #define MAX_TRAINER_CHANNELS_M8() (MAX_TRAINER_CHANNELS-8)
398 #if defined(MULTIMODULE)
399 #define IS_MODULE_MULTIMODULE(idx) (idx==EXTERNAL_MODULE && g_model.moduleData[EXTERNAL_MODULE].type==MODULE_TYPE_MULTIMODULE)
401 #define IS_MODULE_MULTIMODULE(idx) (false)
404 #if defined(PCBTARANIS) || defined(PCBHORUS)
405 #if defined(TARANIS_INTERNAL_PPM)
406 #define IS_MODULE_PPM(idx) (idx==TRAINER_MODULE || (idx==INTERNAL_MODULE && g_model.moduleData[INTERNAL_MODULE].type==MODULE_TYPE_PPM)|| (idx==EXTERNAL_MODULE && g_model.moduleData[EXTERNAL_MODULE].type==MODULE_TYPE_PPM))
408 #define IS_MODULE_PPM(idx) (idx==TRAINER_MODULE || (idx==EXTERNAL_MODULE && g_model.moduleData[EXTERNAL_MODULE].type==MODULE_TYPE_PPM))
410 #define IS_MODULE_XJT(idx) (g_model.moduleData[idx].type==MODULE_TYPE_XJT)
412 #define IS_MODULE_DSM2(idx) (idx==EXTERNAL_MODULE && g_model.moduleData[EXTERNAL_MODULE].type==MODULE_TYPE_DSM2)
414 #define IS_MODULE_DSM2(idx) (false)
416 #if defined(CROSSFIRE)
417 #define IS_MODULE_CROSSFIRE(idx) (idx==EXTERNAL_MODULE && g_model.moduleData[EXTERNAL_MODULE].type==MODULE_TYPE_CROSSFIRE)
419 #define IS_MODULE_CROSSFIRE(idx) (false)
421 #if defined(TARANIS_INTERNAL_PPM)
422 #define MAX_INTERNAL_MODULE_CHANNELS() ((g_model.moduleData[INTERNAL_MODULE].type == MODULE_TYPE_XJT) ? maxChannelsXJT[1+g_model.moduleData[0].rfProtocol] : maxChannelsModules[g_model.moduleData[INTERNAL_MODULE].type])
424 #define MAX_INTERNAL_MODULE_CHANNELS() (maxChannelsXJT[1+g_model.moduleData[INTERNAL_MODULE].rfProtocol])
426 #define MAX_EXTERNAL_MODULE_CHANNELS() ((g_model.moduleData[EXTERNAL_MODULE].type == MODULE_TYPE_XJT) ? maxChannelsXJT[1+g_model.moduleData[1].rfProtocol] : maxChannelsModules[g_model.moduleData[EXTERNAL_MODULE].type])
427 #define MAX_CHANNELS(idx) (idx==INTERNAL_MODULE ? MAX_INTERNAL_MODULE_CHANNELS() : (idx==EXTERNAL_MODULE ? MAX_EXTERNAL_MODULE_CHANNELS() : MAX_TRAINER_CHANNELS_M8()))
428 #define NUM_CHANNELS(idx) ((IS_MODULE_CROSSFIRE(idx) || (IS_MODULE_MULTIMODULE(idx) && (g_model.moduleData[idx].getMultiProtocol(true) != MM_RF_PROTO_DSM2))) ? CROSSFIRE_CHANNELS_COUNT : (8+g_model.moduleData[idx].channelsCount))
429 #elif defined(PCBSKY9X) && !defined(REVA)
430 #define IS_MODULE_PPM(idx) (idx==TRAINER_MODULE || idx==EXTRA_MODULE || (idx==EXTERNAL_MODULE && g_model.moduleData[EXTERNAL_MODULE].type==MODULE_TYPE_PPM))
431 #define IS_MODULE_XJT(idx) (idx==EXTERNAL_MODULE && g_model.moduleData[EXTERNAL_MODULE].type==MODULE_TYPE_XJT)
432 #define IS_MODULE_DSM2(idx) (idx==EXTERNAL_MODULE && g_model.moduleData[EXTERNAL_MODULE].type==MODULE_TYPE_DSM2)
433 #define MAX_EXTERNAL_MODULE_CHANNELS() ((g_model.moduleData[EXTERNAL_MODULE].type == MODULE_TYPE_XJT) ? maxChannelsXJT[1+g_model.moduleData[0].rfProtocol] : maxChannelsModules[g_model.moduleData[EXTERNAL_MODULE].type])
434 #define MAX_EXTRA_MODULE_CHANNELS() (8) // Only PPM (16ch PPM)
435 #define MAX_CHANNELS(idx) (idx==EXTERNAL_MODULE ? MAX_EXTERNAL_MODULE_CHANNELS() : (idx==EXTRA_MODULE ? MAX_EXTRA_MODULE_CHANNELS() : MAX_TRAINER_CHANNELS_M8()))
436 #define NUM_CHANNELS(idx) (8+g_model.moduleData[idx].channelsCount)
437 #define IS_MODULE_CROSSFIRE(idx) (false)
439 #define IS_MODULE_PPM(idx) (idx==TRAINER_MODULE || (idx==EXTERNAL_MODULE && g_model.moduleData[EXTERNAL_MODULE].type==MODULE_TYPE_PPM))
440 #define IS_MODULE_XJT(idx) (idx==EXTERNAL_MODULE && g_model.moduleData[EXTERNAL_MODULE].type==MODULE_TYPE_XJT)
441 #define IS_MODULE_DSM2(idx) (idx==EXTERNAL_MODULE && g_model.moduleData[EXTERNAL_MODULE].type==MODULE_TYPE_DSM2)
442 #define MAX_EXTERNAL_MODULE_CHANNELS() ((g_model.moduleData[EXTERNAL_MODULE].type == MODULE_TYPE_XJT) ? maxChannelsXJT[1+g_model.moduleData[EXTERNAL_MODULE].rfProtocol] : maxChannelsModules[g_model.moduleData[EXTERNAL_MODULE].type])
443 #define MAX_CHANNELS(idx) (idx==EXTERNAL_MODULE ? MAX_EXTERNAL_MODULE_CHANNELS() : MAX_TRAINER_CHANNELS_M8())
444 #define NUM_CHANNELS(idx) (8+g_model.moduleData[idx].channelsCount)
446 #define IS_MODULE_R9M(idx) (g_model.moduleData[idx].type==MODULE_TYPE_R9M)
447 #define IS_MODULE_PXX(idx) (IS_MODULE_XJT(idx) || IS_MODULE_R9M(idx))
450 #if defined(MULTIMODULE)
451 #define IS_MULTIMODULE_DSM(idx) (IS_MODULE_MULTIMODULE(idx) && g_model.moduleData[idx].getMultiProtocol(true) == MM_RF_PROTO_DSM2)
452 #define DEFAULT_CHANNELS(idx) (IS_MODULE_PPM(idx) ? 0 : IS_MULTIMODULE_DSM(idx) ? -1 : MAX_CHANNELS(idx))
454 #define DEFAULT_CHANNELS(idx) (IS_MODULE_PPM(idx) ? 0 : MAX_CHANNELS(idx))
458 #define MASK_CFN_TYPE uint64_t // current max = 64 function switches
459 #define MASK_FUNC_TYPE uint32_t // current max = 32 functions
460 #elif defined(CPUM64)
461 #define MASK_CFN_TYPE uint16_t // current max = 16 function switches
462 #define MASK_FUNC_TYPE uint8_t // current max = 8 functions
464 #define MASK_CFN_TYPE uint32_t // current max = 32 function switches
465 #define MASK_FUNC_TYPE uint8_t // current max = 8 functions
469 MASK_FUNC_TYPE activeFunctions
;
470 MASK_CFN_TYPE activeSwitches
;
471 tmr10ms_t lastFunctionTime
[MAX_SPECIAL_FUNCTIONS
];
473 inline bool isFunctionActive(uint8_t func
)
475 return activeFunctions
& ((MASK_FUNC_TYPE
)1 << func
);
480 memclear(this, sizeof(*this));
482 } CustomFunctionsContext
;
484 #include "strhelpers.h"
487 #if defined(TEMPLATES)
488 #include "templates.h"
493 #if !defined(CPUARM) || !defined(DEBUG)
494 #define printf printf_not_allowed
498 extern const pm_uint8_t bchout_ar
[];
499 extern const pm_uint8_t modn12x3
[];
501 //convert from mode 1 to mode stickMode
502 //NOTICE! => 0..3 -> 0..3
507 #define CONVERT_MODE(x) (((x)<=AIL_STICK) ? pgm_read_byte(modn12x3 + 4*g_eeGeneral.stickMode + (x)) : (x) )
509 extern uint8_t channel_order(uint8_t x
);
511 #define THRCHK_DEADBAND 16
513 #if defined(COLORLCD)
514 #define SPLASH_NEEDED() (false)
515 #elif defined(PCBTARANIS)
516 #define SPLASH_NEEDED() (g_eeGeneral.splashMode != 3)
517 #elif defined(CPUARM)
518 #define SPLASH_NEEDED() (g_model.moduleData[EXTERNAL_MODULE].type != MODULE_TYPE_DSM2 && !g_eeGeneral.splashMode)
520 #define SPLASH_NEEDED() (!IS_DSM2_PROTOCOL(g_model.protocol) && !g_eeGeneral.splashMode)
523 #if defined(PCBHORUS)
524 #define SPLASH_TIMEOUT 0 /* we use the splash duration to load stuff from the SD */
525 #elif defined(FSPLASH)
526 #define SPLASH_TIMEOUT (g_eeGeneral.splashMode == 0 ? 60000/*infinite=10mn*/ : ((4*100) * (g_eeGeneral.splashMode & 0x03)))
527 #elif defined(PCBTARANIS) || defined(PCBFLAMENCO)
528 #define SPLASH_TIMEOUT (g_eeGeneral.splashMode==-4 ? 1500 : (g_eeGeneral.splashMode<=0 ? (400-g_eeGeneral.splashMode*200) : (400-g_eeGeneral.splashMode*100)))
530 #define SPLASH_TIMEOUT (4*100) // 4 seconds
533 #if defined(ROTARY_ENCODERS)
534 #define IS_ROTARY_ENCODER_NAVIGATION_ENABLE() g_eeGeneral.reNavigation
535 extern volatile rotenc_t rotencValue
[ROTARY_ENCODERS
];
536 #define ROTARY_ENCODER_NAVIGATION_VALUE rotencValue[g_eeGeneral.reNavigation - 1]
537 #elif defined(ROTARY_ENCODER_NAVIGATION)
538 #define IS_ROTARY_ENCODER_NAVIGATION_ENABLE() true
539 extern volatile rotenc_t rotencValue
[1];
540 #define ROTARY_ENCODER_NAVIGATION_VALUE rotencValue[0]
543 #if defined(CPUARM) && defined(ROTARY_ENCODER_NAVIGATION)
544 extern uint8_t rotencSpeed
;
545 #define ROTENC_LOWSPEED 1
546 #define ROTENC_MIDSPEED 5
547 #define ROTENC_HIGHSPEED 50
548 #define ROTENC_DELAY_MIDSPEED 32
549 #define ROTENC_DELAY_HIGHSPEED 16
552 #define HEART_TIMER_10MS 1
553 #define HEART_TIMER_PULSES 2 // when multiple modules this is the first one
554 #if defined(PCBTARANIS) || defined(PCBFLAMENCO) || defined(PCBHORUS)
555 #define HEART_WDT_CHECK (HEART_TIMER_10MS + (HEART_TIMER_PULSES << 0) + (HEART_TIMER_PULSES << 1))
557 #define HEART_WDT_CHECK (HEART_TIMER_10MS + HEART_TIMER_PULSES)
559 extern uint8_t heartbeat
;
561 #if defined(CPUARM) && !defined(BOOT)
562 void watchdogSuspend(uint32_t timeout
);
563 #define WATCHDOG_SUSPEND(x) watchdogSuspend(x)
565 #define WATCHDOG_SUSPEND(...)
568 #define MAX_ALERT_TIME 60
576 extern struct t_inactivity inactivity
;
578 #define LEN_STD_CHARS 40
580 #if defined(TRANSLATIONS_CZ)
581 #define ZCHAR_MAX (LEN_STD_CHARS)
583 #define ZCHAR_MAX (LEN_STD_CHARS + LEN_SPECIAL_CHARS)
586 char hex2zchar(uint8_t hex
);
587 char idx2char(int8_t idx
);
588 #if defined(CPUARM) || defined(SIMU)
589 int8_t char2idx(char c
);
590 void str2zchar(char *dest
, const char *src
, int size
);
591 int zchar2str(char *dest
, const char *src
, int size
);
597 #if defined(PCBTARANIS) || defined(PCBFLAMENCO) || defined(PCBHORUS)
598 div_t switchInfo(int switchPosition
);
599 extern uint8_t potsPos
[NUM_XPOTS
];
602 #if defined(PCBHORUS)
603 uint16_t trimDown(uint16_t idx
); // TODO why?
605 uint8_t trimDown(uint8_t idx
);
607 void readKeysAndTrims();
609 uint16_t evalChkSum();
612 #define RAISE_ALERT(...)
615 #define RAISE_ALERT(title, msg, info, sound) showAlertBox(title, msg, info, sound)
616 #define ALERT(title, msg, sound) alert(title, msg, sound)
618 #define RAISE_ALERT(title, msg, info, sound) showAlertBox(title, msg, info)
619 #define ALERT(title, msg, sound) alert(title, msg)
622 void alert(const pm_char
* t
, const pm_char
* s ALERT_SOUND_ARG
);
625 e_perout_mode_normal
= 0,
626 e_perout_mode_inactive_flight_mode
= 1,
627 e_perout_mode_notrainer
= 2,
628 e_perout_mode_notrims
= 4,
629 e_perout_mode_nosticks
= 8,
630 e_perout_mode_noinput
= e_perout_mode_notrainer
+e_perout_mode_notrims
+e_perout_mode_nosticks
634 #if defined(MODULE_ALWAYS_SEND_PULSES)
635 extern uint8_t startupWarningState
;
637 enum StartupWarningStates
{
638 STARTUP_WARNING_THROTTLE
,
639 STARTUP_WARNING_SWITCHES
,
640 STARTUP_WARNING_DONE
,
645 // Fiddle to force compiler to use a pointer
646 #if defined(CPUARM) || defined(SIMU)
647 #define FORCE_INDIRECT(ptr)
649 #define FORCE_INDIRECT(ptr) __asm__ __volatile__ ("" : "=e" (ptr) : "0" (ptr))
652 extern uint8_t mixerCurrentFlightMode
;
653 extern uint8_t lastFlightMode
;
654 extern uint8_t flightModeTransitionLast
;
657 #define bitfield_channels_t uint32_t
659 #define bitfield_channels_t uint16_t
663 inline int availableMemory() { return 1000; }
664 #elif defined(CPUARM) && !defined(SIMU)
665 extern unsigned char *heap
;
668 extern int _main_stack_start
;
669 extern int _heap_end
;
670 #define availableMemory() ((unsigned int)((unsigned char *)&_heap_end - heap))
673 void evalFlightModeMixes(uint8_t mode
, uint8_t tick10ms
);
674 void evalMixes(uint8_t tick10ms
);
675 void doMixerCalculations();
676 void scheduleNextMixerCalculation(uint8_t module
, uint16_t delay
);
682 NOINLINE
void per10ms();
684 getvalue_t
getValue(mixsrc_t i
);
687 #define GETSWITCH_MIDPOS_DELAY 1
688 bool getSwitch(swsrc_t swtch
, uint8_t flags
=0);
690 bool getSwitch(swsrc_t swtch
);
693 void logicalSwitchesTimerTick();
694 void logicalSwitchesReset();
697 void evalLogicalSwitches(bool isCurrentPhase
=true);
698 void logicalSwitchesCopyState(uint8_t src
, uint8_t dst
);
699 #define LS_RECURSIVE_EVALUATION_RESET()
701 #define evalLogicalSwitches(xxx)
702 #define GETSWITCH_RECURSIVE_TYPE uint16_t
703 extern volatile GETSWITCH_RECURSIVE_TYPE s_last_switch_used
;
704 extern volatile GETSWITCH_RECURSIVE_TYPE s_last_switch_value
;
705 #define LS_RECURSIVE_EVALUATION_RESET() s_last_switch_used = 0
708 #if defined(PCBTARANIS) || defined(PCBFLAMENCO) || defined(PCBHORUS)
709 void getSwitchesPosition(bool startup
);
711 #define getSwitchesPosition(...)
714 extern swarnstate_t switches_states
;
715 swsrc_t
getMovedSwitch();
718 #define GET_MOVED_SOURCE_PARAMS uint8_t min
719 int8_t getMovedSource(GET_MOVED_SOURCE_PARAMS
);
720 #define GET_MOVED_SOURCE(min, max) getMovedSource(min)
722 #define GET_MOVED_SOURCE_PARAMS
723 int8_t getMovedSource();
724 #define GET_MOVED_SOURCE(min, max) getMovedSource()
727 #if defined(FLIGHT_MODES)
728 extern uint8_t getFlightMode();
730 #define getFlightMode() 0
734 uint8_t getTrimFlightMode(uint8_t phase
, uint8_t idx
);
736 #define getTrimFlightMode(phase, idx) (phase)
740 extern int8_t trimGvar
[NUM_STICKS
+NUM_AUX_TRIMS
];
741 #define TRIM_REUSED(idx) trimGvar[idx] >= 0
743 #define TRIM_REUSED(idx) 0
746 trim_t
getRawTrimValue(uint8_t phase
, uint8_t idx
);
747 int getTrimValue(uint8_t phase
, uint8_t idx
);
750 bool setTrimValue(uint8_t phase
, uint8_t idx
, int trim
);
752 void setTrimValue(uint8_t phase
, uint8_t idx
, int trim
);
755 #if defined(ROTARY_ENCODERS)
756 int16_t getRotaryEncoder(uint8_t idx
);
757 void incRotaryEncoder(uint8_t idx
, int8_t inc
);
760 #if defined(PCBGRUVIN9X) || defined(PCBMEGA2560)
761 #define ROTARY_ENCODER_GRANULARITY (1)
762 #elif defined(PCBSKY9X)
763 #define ROTARY_ENCODER_GRANULARITY (2 << g_eeGeneral.rotarySteps)
765 #define ROTARY_ENCODER_GRANULARITY (2)
770 extern uint16_t sessionTimer
;
771 extern uint16_t s_timeCumThr
;
772 extern uint16_t s_timeCum16ThrP
;
774 #if defined(OVERRIDE_CHANNEL_FUNCTION)
776 #define OVERRIDE_CHANNEL_UNDEFINED -4096
778 #define OVERRIDE_CHANNEL_UNDEFINED -128
780 extern safetych_t safetyCh
[MAX_OUTPUT_CHANNELS
];
783 extern uint8_t trimsCheckTimer
;
786 extern uint8_t trimsDisplayTimer
;
787 extern uint8_t trimsDisplayMask
;
790 void flightReset(uint8_t check
=true);
792 extern uint8_t unexpectedShutdown
;
794 extern uint16_t maxMixerDuration
;
797 extern uint8_t g_tmr1Latency_max
;
798 extern uint8_t g_tmr1Latency_min
;
799 extern uint16_t lastMixerDuration
;
803 #define DURATION_MS_PREC2(x) ((x)/20)
805 #define DURATION_MS_PREC2(x) ((x)*100)/16
808 #if defined(THRTRACE)
809 #if defined(COLORLCD)
810 #define MAXTRACE (LCD_W-2*10)
812 #define MAXTRACE (LCD_W - 8)
814 extern uint8_t s_traceBuf
[MAXTRACE
];
815 extern uint16_t s_traceWr
;
816 extern uint8_t s_cnt_10s
;
817 extern uint16_t s_cnt_samples_thr_10s
;
818 extern uint16_t s_sum_samples_thr_10s
;
819 #define RESET_THR_TRACE() s_traceWr = s_cnt_10s = s_cnt_samples_thr_10s = s_sum_samples_thr_10s = s_timeCum16ThrP = s_timeCumThr = 0
821 #define RESET_THR_TRACE() s_timeCum16ThrP = s_timeCumThr = 0
825 uint16_t getTmr2MHz();
826 uint16_t getTmr16KHz();
828 static inline uint16_t getTmr2MHz() { return TIMER_2MHz_TIMER
->CNT
; }
829 #elif defined(PCBSKY9X)
830 static inline uint16_t getTmr2MHz() { return TC1
->TC_CHANNEL
[0].TC_CV
; }
832 uint16_t getTmr16KHz();
836 uint16_t stackAvailable();
844 extern bool readonly
;
845 extern bool readonlyUnlocked();
846 #define READ_ONLY() readonly
847 #define READ_ONLY_UNLOCKED() readonlyUnlocked()
849 #define READ_ONLY() false
850 #define READ_ONLY_UNLOCKED() true
853 void checkLowEEPROM();
855 void checkSwitches();
862 #define GET_ADC_IF_MIXER_NOT_RUNNING() do { if (s_pulses_paused) getADC(); } while(0)
864 #define GET_ADC_IF_MIXER_NOT_RUNNING() getADC()
873 void checkBacklight();
874 void doLoopCommonActions();
876 #define BITMASK(bit) (1<<(bit))
879 #define UNUSED(x) ((void)(x)) /* to avoid warnings */
882 /// returns the number of elements of an array
883 #define DIM(arr) (sizeof((arr))/sizeof((arr)[0]))
885 template<class t
> FORCEINLINE t
min(t a
, t b
) { return a
<b
?a
:b
; }
886 template<class t
> FORCEINLINE t
max(t a
, t b
) { return a
>b
?a
:b
; }
887 template<class t
> FORCEINLINE t
sgn(t a
) { return a
>0 ? 1 : (a
< 0 ? -1 : 0); }
888 template<class t
> FORCEINLINE t
limit(t mi
, t x
, t ma
) { return min(max(mi
,x
),ma
); }
889 template<class t
> void SWAP(t
& a
, t
& b
) { t tmp
= b
; b
= a
; a
= tmp
; }
891 uint16_t isqrt32(uint32_t n
);
893 #if defined(CPUARM) && !defined(BOOT)
894 #include "tasks_arm.h"
895 extern OS_MutexID mixerMutex
;
896 inline void pauseMixerCalculations()
898 CoEnterMutexSection(mixerMutex
);
901 inline void resumeMixerCalculations()
903 CoLeaveMutexSection(mixerMutex
);
906 #define pauseMixerCalculations()
907 #define resumeMixerCalculations()
910 void generalDefault();
911 void modelDefault(uint8_t id
);
914 void checkModelIdUnique(uint8_t index
, uint8_t module
);
918 uint32_t hash(const void * ptr
, uint32_t size
);
919 inline int divRoundClosest(const int n
, const int d
)
924 return ((n
< 0) ^ (d
< 0)) ? ((n
- d
/2)/d
) : ((n
+ d
/2)/d
);
927 #define calc100to256_16Bits(x) calc100to256(x)
928 #define calc100toRESX_16Bits(x) calc100toRESX(x)
930 inline int calc100to256(int x
)
932 return divRoundClosest(x
*256, 100);
935 inline int calc100toRESX(int x
)
937 return divRoundClosest(x
*RESX
, 100);
940 inline int calc1000toRESX(int x
)
942 return divRoundClosest(x
*RESX
, 1000);
945 inline int calcRESXto1000(int x
)
947 return divRoundClosest(x
*1000, RESX
);
950 inline int calcRESXto100(int x
)
952 return divRoundClosest(x
*100, RESX
);
956 extern int16_t calc100to256_16Bits(int16_t x
); // @@@2 open.20.fsguruh: return x*2.56
957 extern int16_t calc100to256(int8_t x
); // @@@2 open.20.fsguruh: return x*2.56
958 extern int16_t calc100toRESX_16Bits(int16_t x
); // @@@ open.20.fsguruh
959 extern int16_t calc100toRESX(int8_t x
);
960 extern int16_t calc1000toRESX(int16_t x
);
961 extern int16_t calcRESXto1000(int16_t x
);
962 extern int8_t calcRESXto100(int16_t x
);
965 #if defined(COLORLCD)
966 extern const char vers_stamp
[];
967 extern const char date_stamp
[];
968 extern const char time_stamp
[];
969 extern const char eeprom_stamp
[];
971 extern const char vers_stamp
[];
974 extern uint8_t g_vbat100mV
;
976 #define GET_TXBATT_BARS() (limit<int8_t>(0, div_and_round(10 * (g_vbat100mV - g_eeGeneral.vBatMin - 90), 30 + g_eeGeneral.vBatMax - g_eeGeneral.vBatMin), 10))
978 #define GET_TXBATT_BARS() (limit<int8_t>(2, 20 * (g_vbat100mV - g_eeGeneral.vBatMin - 90) / (30 + g_eeGeneral.vBatMax - g_eeGeneral.vBatMin), 20))
980 #define IS_TXBATT_WARNING() (g_vbat100mV <= g_eeGeneral.vBatWarn)
983 #define g_blinkTmr10ms (*(uint8_t*)&g_tmr10ms)
984 extern uint8_t g_beepCnt
;
985 extern uint8_t g_beepVal
[5];
987 #include "trainer_input.h"
989 extern int32_t chans
[MAX_OUTPUT_CHANNELS
];
990 extern int16_t ex_chans
[MAX_OUTPUT_CHANNELS
]; // Outputs (before LIMITS) of the last perMain
991 extern int16_t channelOutputs
[MAX_OUTPUT_CHANNELS
];
992 extern uint16_t BandGap
;
995 #define NUM_INPUTS (MAX_INPUTS)
997 #define NUM_INPUTS (NUM_STICKS)
1000 int expo(int x
, int k
);
1003 inline int getMaximumValue(int source
)
1005 if (source
< MIXSRC_FIRST_CH
)
1007 else if (source
<= MIXSRC_LAST_CH
)
1008 return g_model
.extendedLimits
? 150 : 100;
1009 else if (source
>= MIXSRC_FIRST_TIMER
&& source
<= MIXSRC_LAST_TIMER
)
1027 int8_t * curveAddress(uint8_t idx
);
1033 point_t
getPoint(uint8_t i
);
1034 #if !defined(CURVES)
1035 #define LOAD_MODEL_CURVES()
1036 #define applyCurve(x, idx) (x)
1037 #elif defined(CPUARM)
1038 typedef CurveData CurveInfo
;
1040 #define LOAD_MODEL_CURVES() loadCurves()
1041 int intpol(int x
, uint8_t idx
);
1042 int applyCurve(int x
, CurveRef
& curve
);
1043 int applyCustomCurve(int x
, uint8_t idx
);
1044 int applyCurrentCurve(int x
);
1045 int8_t getCurveX(int noPoints
, int point
);
1046 void resetCustomCurveX(int8_t * points
, int noPoints
);
1047 bool moveCurve(uint8_t index
, int8_t shift
); // TODO bool?
1054 CurveInfo
curveInfo(uint8_t idx
);
1055 int intpol(int x
, uint8_t idx
);
1056 int applyCurve(int x
, int8_t idx
);
1057 #define LOAD_MODEL_CURVES()
1058 #define applyCustomCurve(x, idx) intpol(x, idx)
1059 int applyCurrentCurve(int x
);
1060 bool moveCurve(uint8_t index
, int8_t shift
, int8_t custom
=0);
1064 #define APPLY_EXPOS_EXTRA_PARAMS_INC , uint8_t ovwrIdx=0, int16_t ovwrValue=0
1065 #define APPLY_EXPOS_EXTRA_PARAMS , uint8_t ovwrIdx, int16_t ovwrValue
1067 #define APPLY_EXPOS_EXTRA_PARAMS_INC
1068 #define APPLY_EXPOS_EXTRA_PARAMS
1073 void defaultInputs();
1076 void applyExpos(int16_t * anas
, uint8_t mode APPLY_EXPOS_EXTRA_PARAMS_INC
);
1077 int16_t applyLimits(uint8_t channel
, int32_t value
);
1079 void evalInputs(uint8_t mode
);
1080 uint16_t anaIn(uint8_t chan
);
1082 extern int16_t calibratedAnalogs
[NUM_CALIBRATED_ANALOGS
];
1084 #define FLASH_DURATION 20 /*200ms*/
1086 extern uint8_t beepAgain
;
1087 extern uint16_t lightOffCounter
;
1088 extern uint8_t flashCounter
;
1089 extern uint8_t mixWarning
;
1091 FlightModeData
* flightModeAddress(uint8_t idx
);
1092 ExpoData
* expoAddress(uint8_t idx
);
1093 MixData
* mixAddress(uint8_t idx
);
1094 LimitData
* limitAddress(uint8_t idx
);
1095 LogicalSwitchData
* lswAddress(uint8_t idx
);
1097 // static variables used in evalFlightModeMixes - moved here so they don't interfere with the stack
1098 // It's also easier to initialize them here.
1100 extern int8_t virtualInputsTrims
[NUM_INPUTS
];
1102 extern int16_t rawAnas
[NUM_INPUTS
];
1105 extern int16_t anas
[NUM_INPUTS
];
1106 extern int16_t trims
[NUM_STICKS
+NUM_AUX_TRIMS
];
1107 extern BeepANACenter bpanaCenter
;
1109 extern uint8_t s_mixer_first_run_done
;
1111 void applyDefaultTemplate();
1113 void incSubtrim(uint8_t idx
, int16_t inc
);
1116 void copyTrimsToOffset(uint8_t ch
);
1117 void copySticksToOffset(uint8_t ch
);
1118 void moveTrimsToOffsets();
1121 #define ACTIVE_PHASES_TYPE uint16_t
1122 #define DELAY_POS_SHIFT 0
1123 #define DELAY_POS_MARGIN 3
1124 #define delayval_t int16_t
1125 PACK(typedef struct {
1127 int16_t now
; // timer trigger source -> off, abs, stk, stk%, sw/!sw, !m_sw/!m_sw
1133 #define ACTIVE_PHASES_TYPE uint8_t
1134 #define DELAY_POS_SHIFT 10
1135 #define DELAY_POS_MARGIN 0
1136 #define delayval_t int8_t
1137 PACK(typedef struct {
1139 int16_t now
:2; // timer trigger source -> off, abs, stk, stk%, sw/!sw, !m_sw/!m_sw
1141 int16_t activeMix
:1;
1142 int16_t activeExpo
:1;
1146 extern SwOn swOn
[MAX_MIXERS
];
1147 extern int24_t act
[MAX_MIXERS
];
1149 #if defined(BOLD_FONT)
1150 inline bool isExpoActive(uint8_t expo
)
1152 return swOn
[expo
].activeExpo
;
1155 inline bool isMixActive(uint8_t mix
)
1157 return swOn
[mix
].activeMix
;
1160 #define isExpoActive(x) false
1161 #define isMixActive(x) false
1164 enum LogicalSwitchFamilies
{
1175 uint8_t lswFamily(uint8_t func
);
1176 int16_t lswTimerValue(delayval_t val
);
1178 enum FunctionsActive
{
1180 FUNCTION_INSTANT_TRIM
= FUNCTION_TRAINER
+4,
1187 FUNCTION_BACKGND_MUSIC
,
1188 FUNCTION_BACKGND_MUSIC_PAUSE
,
1192 #define VARIO_FREQUENCY_ZERO 700/*Hz*/
1193 #define VARIO_FREQUENCY_RANGE 1000/*Hz*/
1194 #define VARIO_REPEAT_ZERO 500/*ms*/
1195 #define VARIO_REPEAT_MAX 80/*ms*/
1198 extern CustomFunctionsContext modelFunctionsContext
;
1199 extern CustomFunctionsContext globalFunctionsContext
;
1200 inline bool isFunctionActive(uint8_t func
)
1202 return globalFunctionsContext
.isFunctionActive(func
) || modelFunctionsContext
.isFunctionActive(func
);
1204 void evalFunctions(const CustomFunctionData
* functions
, CustomFunctionsContext
& functionsContext
);
1205 inline void customFunctionsReset()
1207 globalFunctionsContext
.reset();
1208 modelFunctionsContext
.reset();
1211 extern CustomFunctionsContext modelFunctionsContext
;
1212 #define isFunctionActive(func) modelFunctionsContext.isFunctionActive(func)
1213 void evalFunctions();
1214 #define customFunctionsReset() modelFunctionsContext.reset()
1217 #include "telemetry/telemetry.h"
1220 uint8_t crc8(const uint8_t * ptr
, uint32_t len
);
1221 uint16_t crc16(const uint8_t * ptr
, uint32_t len
);
1224 #define PLAY_REPEAT(x) (x) /* Range 0 to 15 */
1225 #define PLAY_NOW 0x10
1226 #define PLAY_BACKGROUND 0x20
1227 #define PLAY_INCREMENT(x) ((uint8_t)(((uint8_t)x) << 6)) /* -1, 0, 1, 2 */
1252 AU_MODEL_STILL_POWERED
,
1254 #if defined(PCBSKY9X)
1273 #if defined(PCBTARANIS) || defined(PCBFLAMENCO) || defined(PCBHORUS)
1282 #elif defined(CPUARM)
1298 AU_SPECIAL_SOUND_FIRST
,
1299 AU_SPECIAL_SOUND_BEEP1
= AU_SPECIAL_SOUND_FIRST
,
1300 AU_SPECIAL_SOUND_BEEP2
,
1301 AU_SPECIAL_SOUND_BEEP3
,
1302 AU_SPECIAL_SOUND_WARN1
,
1303 AU_SPECIAL_SOUND_WARN2
,
1304 AU_SPECIAL_SOUND_CHEEP
,
1305 AU_SPECIAL_SOUND_RATATA
,
1306 AU_SPECIAL_SOUND_TICK
,
1307 AU_SPECIAL_SOUND_SIREN
,
1308 AU_SPECIAL_SOUND_RING
,
1309 AU_SPECIAL_SOUND_SCIFI
,
1310 AU_SPECIAL_SOUND_ROBOT
,
1311 AU_SPECIAL_SOUND_CHIRP
,
1312 AU_SPECIAL_SOUND_TADA
,
1313 AU_SPECIAL_SOUND_CRICKET
,
1314 AU_SPECIAL_SOUND_ALARMC
,
1315 AU_SPECIAL_SOUND_LAST
,
1322 #include "audio_arm.h"
1324 #include "audio_avr.h"
1330 #if defined(PCBSTD) && defined(VOICE)
1331 #include "targets/9x/voice.h"
1334 #if defined(PCBGRUVIN9X) && defined(VOICE)
1335 #include "targets/gruvin9x/voice.h"
1338 #if defined(PCBMEGA2560) && defined(VOICE)
1339 #include "targets/mega2560/voice.h"
1342 #include "translations.h"
1353 #if defined(RTCLOCK)
1363 extern uint8_t requiredSpeakerVolume
;
1369 REQUEST_FLIGHT_RESET
,
1372 extern uint8_t mainRequestFlags
;
1375 void checkBattery();
1376 void opentxClose(uint8_t shutdown
=true);
1378 void opentxResume();
1380 #if defined(PCBHORUS) || defined(PCBX7)
1381 #define LED_ERROR_BEGIN() ledRed()
1382 #define LED_ERROR_END() ledBlue()
1384 #define LED_ERROR_BEGIN()
1385 #define LED_ERROR_END()
1388 // Re-useable byte array to save having multiple buffers
1390 #define SD_SCREEN_FILE_LENGTH 32
1392 #define SD_SCREEN_FILE_LENGTH 64
1394 union ReusableBuffer
1399 #if !defined(CPUARM)
1400 char listnames
[NUM_BODY_LINES
][LEN_MODEL_NAME
];
1402 #if defined(EEPROM_RLC) && LCD_W < 212
1403 uint16_t eepromfree
;
1406 char menu_bss
[POPUP_MENU_MAX_LINES
][MENU_LINE_LENGTH
];
1407 char mainname
[45]; // because reused for SD backup / restore, max backup filename 44 chars: "/MODELS/MODEL0134353-2014-06-19-04-51-27.bin"
1409 char mainname
[LEN_MODEL_NAME
];
1420 int16_t midVals
[NUM_STICKS
+NUM_POTS
+NUM_SLIDERS
+NUM_MOUSE_ANALOGS
];
1421 int16_t loVals
[NUM_STICKS
+NUM_POTS
+NUM_SLIDERS
+NUM_MOUSE_ANALOGS
];
1422 int16_t hiVals
[NUM_STICKS
+NUM_POTS
+NUM_SLIDERS
+NUM_MOUSE_ANALOGS
];
1424 #if defined(PCBTARANIS) || defined(PCBFLAMENCO) || defined(PCBHORUS)
1427 int16_t steps
[XPOTS_MULTIPOS_COUNT
];
1429 int16_t lastPosition
;
1430 } xpotsCalib
[NUM_XPOTS
];
1438 char lines
[NUM_BODY_LINES
][SD_SCREEN_FILE_LENGTH
+1+1]; // the last char is used to store the flags (directory) of the line
1442 char originalName
[SD_SCREEN_FILE_LENGTH
+1];
1458 extern union ReusableBuffer reusableBuffer
;
1460 void checkFlashOnBeep();
1463 uint8_t zlen(const char *str
, uint8_t size
);
1464 bool zexist(const char *str
, uint8_t size
);
1465 unsigned int effectiveLen(const char * str
, unsigned int size
);
1466 char * strcat_zchar(char *dest
, const char *name
, uint8_t size
, const char *defaultName
=NULL
, uint8_t defaultNameSize
=0, uint8_t defaultIdx
=0);
1467 #define strcat_phasename(dest, idx) strcat_zchar(dest, g_model.flightModeData[idx].name, LEN_FLIGHT_MODE_NAME, STR_FP, PSIZE(TR_FP), idx+1)
1469 #define strcat_modelname(dest, idx) strcat_zchar(dest, modelHeaders[idx].name, LEN_MODEL_NAME, STR_MODEL, PSIZE(TR_MODEL), idx+1)
1470 #define strcat_currentmodelname(dest) strcat_modelname(dest, g_eeGeneral.currModel)
1472 #define strcat_currentmodelname(dest) strcat_zchar(dest, g_model.header.name, LEN_MODEL_NAME)
1474 #define ZLEN(s) zlen(s, sizeof(s))
1475 #define ZEXIST(s) zexist(s, sizeof(s))
1478 // Stick tolerance varies between transmitters, Higher is better
1479 #if defined (PCB9XR) || defined (PCB9XR128)
1480 #define STICK_TOLERANCE 16
1482 #define STICK_TOLERANCE 64
1485 #if defined(FRSKY_HUB) && defined(GAUGES)
1486 enum BarThresholdIdx
{
1504 #define FILL_THRESHOLD(idx, val) barsThresholds[idx] = (val)
1506 #define FILL_THRESHOLD(idx, val) barsThresholds[idx] = 128 + (val)
1509 extern bar_threshold_t barsThresholds
[THLD_MAX
];
1511 #define FILL_THRESHOLD(idx, val)
1514 #if defined(TELEMETRY_FRSKY)
1515 ls_telemetry_value_t
minTelemValue(source_t channel
);
1516 ls_telemetry_value_t
maxTelemValue(source_t channel
);
1518 #define minTelemValue(channel) 255
1519 #define maxTelemValue(channel) 255
1523 getvalue_t
convert16bitsTelemValue(source_t channel
, ls_telemetry_value_t value
);
1524 ls_telemetry_value_t
max8bitsTelemValue(source_t channel
);
1527 getvalue_t
convert8bitsTelemValue(source_t channel
, ls_telemetry_value_t value
);
1528 getvalue_t
convertLswTelemValue(LogicalSwitchData
* cs
);
1531 #define convertTelemValue(channel, value) convert16bitsTelemValue(channel, value)
1532 #define convertBarTelemValue(channel, value) convert8bitsTelemValue(channel, value)
1533 #define maxBarTelemValue(channel) max8bitsTelemValue(channel)
1535 #define convertTelemValue(channel, value) convert8bitsTelemValue(channel, value)
1536 #define convertBarTelemValue(channel, value) convert8bitsTelemValue(channel, value)
1537 #define maxBarTelemValue(channel) maxTelemValue(channel)
1540 #if defined(TELEMETRY_FRSKY) || defined(CPUARM)
1541 lcdint_t
applyChannelRatio(source_t channel
, lcdint_t val
);
1542 #define ANA_CHANNEL_UNIT(channel) g_model.frsky.channels[channel].type
1545 inline int div_and_round(int num
, int den
)
1550 else if (num
>= 0) {
1559 #if defined(TELEMETRY_FRSKY)
1560 #if !defined(CPUARM)
1561 NOINLINE
uint8_t getRssiAlarmValue(uint8_t alarm
);
1564 extern const pm_uint8_t bchunit_ar
[];
1567 #define FRSKY_MULTIPLIER_MAX 5
1569 #define FRSKY_MULTIPLIER_MAX 3
1572 enum TelemetryViews
{
1573 TELEMETRY_CUSTOM_SCREEN_1
,
1574 TELEMETRY_CUSTOM_SCREEN_2
,
1576 TELEMETRY_CUSTOM_SCREEN_3
,
1577 TELEMETRY_CUSTOM_SCREEN_4
,
1578 TELEMETRY_VIEW_MAX
= TELEMETRY_CUSTOM_SCREEN_4
1580 TELEMETRY_VOLTAGES_SCREEN
,
1581 TELEMETRY_AFTER_FLIGHT_SCREEN
,
1582 TELEMETRY_VIEW_MAX
= TELEMETRY_AFTER_FLIGHT_SCREEN
1586 extern uint8_t s_frsky_view
;
1590 #define EARTH_RADIUSKM ((uint32_t)6371)
1591 #define EARTH_RADIUS ((uint32_t)111194) // meters * pi / 180°
1593 void getGpsPilotPosition();
1594 void getGpsDistance();
1597 #if defined(AUDIO) && defined(BUZZER)
1598 #define IS_SOUND_OFF() (g_eeGeneral.buzzerMode==e_mode_quiet && g_eeGeneral.beepMode==e_mode_quiet)
1600 #define IS_SOUND_OFF() (g_eeGeneral.beepMode == e_mode_quiet)
1604 #define IS_IMPERIAL_ENABLE() (g_eeGeneral.imperial)
1605 #elif defined(IMPERIAL_UNITS)
1606 #define IS_IMPERIAL_ENABLE() (1)
1608 #define IS_IMPERIAL_ENABLE() (0)
1612 #elif defined(TELEMETRY_FRSKY)
1613 FORCEINLINE
void convertUnit(getvalue_t
& val
, uint8_t & unit
)
1615 if (IS_IMPERIAL_ENABLE()) {
1616 if (unit
== UNIT_TEMPERATURE
) {
1621 if (unit
== UNIT_DIST
) {
1623 val
= val
* 3 + (val
>> 2) + (val
>> 5);
1625 if (unit
== UNIT_FEET
) {
1628 if (unit
== UNIT_KTS
) {
1631 val
= (val
* 23) / 20;
1635 if (unit
== UNIT_KTS
) {
1638 val
= (val
* 50) / 27;
1642 if (unit
== UNIT_HDG
) {
1643 unit
= UNIT_TEMPERATURE
;
1647 #define convertUnit(...)
1650 #if !defined(CPUARM)
1651 #define IS_USR_PROTO_FRSKY_HUB() (g_model.frsky.usrProto == USR_PROTO_FRSKY)
1652 #define IS_USR_PROTO_WS_HOW_HIGH() (g_model.frsky.usrProto == USR_PROTO_WS_HOW_HIGH)
1655 #if defined(TELEMETRY_FRSKY) && defined(FRSKY_HUB) && defined(GPS)
1656 #define IS_GPS_AVAILABLE() IS_USR_PROTO_FRSKY_HUB()
1658 #define IS_GPS_AVAILABLE() (0)
1661 #if defined(PCBTARANIS)
1662 extern const pm_uchar logo_taranis
[];
1665 #if defined(USB_MASS_STORAGE)
1666 void usbPluggedIn();
1669 #include "lua/lua_api.h"
1672 enum ClipboardType
{
1673 CLIPBOARD_TYPE_NONE
,
1674 CLIPBOARD_TYPE_CUSTOM_SWITCH
,
1675 CLIPBOARD_TYPE_CUSTOM_FUNCTION
,
1676 CLIPBOARD_TYPE_SD_FILE
,
1680 #define CLIPBOARD_PATH_LEN 1024
1682 #define CLIPBOARD_PATH_LEN 32
1688 LogicalSwitchData csw
;
1689 CustomFunctionData cfn
;
1691 char directory
[CLIPBOARD_PATH_LEN
];
1692 char filename
[CLIPBOARD_PATH_LEN
];
1697 extern Clipboard clipboard
;
1701 extern uint16_t s_anaFilt
[NUM_ANALOGS
];
1704 #if defined(JITTER_MEASURE)
1705 extern JitterMeter
<uint16_t> rawJitter
[NUM_ANALOGS
];
1706 extern JitterMeter
<uint16_t> avgJitter
[NUM_ANALOGS
];
1707 #if defined(PCBHORUS)
1708 #define JITTER_MEASURE_ACTIVE() (menuHandlers[menuLevel] == menuStatsAnalogs)
1709 #elif defined(PCBTARANIS)
1710 #define JITTER_MEASURE_ACTIVE() (menuHandlers[menuLevel] == menuRadioDiagAnalogs)
1712 #define JITTER_MEASURE_ACTIVE() (1)
1714 #define JITTER_MEASURE_ACTIVE() (0)
1718 #if defined(INTERNAL_GPS)
1722 #if defined(BLUETOOTH)
1723 #include "bluetooth.h"
1726 #endif // _OPENTX_H_