fix models list reload after USB mass storage connection (#5963)
[opentx.git] / radio / src / buzzer.h
blob9e28745332266fed3508f39244f38c73478169ab
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
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.
21 #ifndef _BUZZER_H_
22 #define _BUZZER_H_
24 #if defined(BUZZER)
25 extern uint8_t g_beepCnt;
26 extern uint8_t beepAgain;
27 extern uint8_t beepAgainOrig;
28 extern uint8_t beepOn;
29 extern bool warble;
30 extern bool warbleC;
31 #if defined(HAPTIC)
32 extern uint8_t hapticTick;
33 #endif /* HAPTIC */
34 #endif /* BUZZER */
36 #if defined(BUZZER)
38 #if defined(CPUARM) && !defined(SIMU)
39 inline void _beep(uint8_t b)
41 buzzerSound(b);
43 #else /* CPUARM && !SIMU */
44 inline void _beep(uint8_t b)
46 g_beepCnt = b;
48 #endif /* CPUARM && !SIMU */
50 void beep(uint8_t val);
51 #else /* BUZZER */
52 inline void beep(uint8_t) { }
53 #endif /* BUZZER */
55 #if !defined(AUDIO)
57 #if defined(BUZZER)
58 #if defined(VOICE)
59 #define AUDIO_HELLO() PUSH_SYSTEM_PROMPT(AUDIO_HELLO)
60 #define AUDIO_BYE()
61 #define AUDIO_TX_BATTERY_LOW() PUSH_SYSTEM_PROMPT(AU_TX_BATTERY_LOW)
62 #define AUDIO_INACTIVITY() PUSH_SYSTEM_PROMPT(AU_INACTIVITY)
63 #define AUDIO_ERROR_MESSAGE(e) PUSH_SYSTEM_PROMPT((e))
64 #define AUDIO_TIMER_MINUTE(t) playDuration(t)
65 // TODO
66 #define AUDIO_TIMER_30() PUSH_SYSTEM_PROMPT(AU_TIMER_30)
67 #define AUDIO_TIMER_20() PUSH_SYSTEM_PROMPT(AU_TIMER_20)
68 #else
69 #define AUDIO_HELLO()
70 #define AUDIO_BYE()
71 #define AUDIO_TX_BATTERY_LOW() beep(4)
72 #define AUDIO_INACTIVITY() beep(3)
73 #define AUDIO_ERROR_MESSAGE(e) beep(4)
74 #define AUDIO_TIMER_MINUTE(t) beep(2)
75 // TODO
76 #define AUDIO_TIMER_30() { beepAgain=2; beep(2); }
77 #define AUDIO_TIMER_20() { beepAgain=1; beep(2); }
78 #endif
80 #define AUDIO_KEY_PRESS() beep(0)
81 #define AUDIO_KEY_ERROR() beep(2)
82 #define AUDIO_WARNING2() beep(2)
83 #define AUDIO_WARNING1() beep(3)
84 #define AUDIO_ERROR() beep(4)
85 #define AUDIO_MIX_WARNING(x) beep(1)
86 #define AUDIO_POT_MIDDLE() beep(2)
87 #define AUDIO_TIMER_COUNTDOWN(idx, val) beep(2)
88 #define AUDIO_TIMER_ELAPSED(idx) beep(3)
89 #define AUDIO_VARIO_UP() _beep(1)
90 #define AUDIO_VARIO_DOWN() _beep(1)
91 #define AUDIO_TRIM_PRESS(f) { if (!IS_KEY_FIRST(event)) warble = true; beep(1); }
92 #define AUDIO_TRIM_MIDDLE() beep(2)
93 #define AUDIO_TRIM_MIN() beep(2)
94 #define AUDIO_TRIM_MAX() beep(2)
95 #define AUDIO_PLAY(p) beep(3)
97 #define IS_AUDIO_BUSY() (g_beepCnt || beepAgain || beepOn)
98 #else /* BUZZER */
99 #define AUDIO_HELLO()
100 #define AUDIO_BYE()
101 #define AUDIO_TX_BATTERY_LOW()
102 #define AUDIO_INACTIVITY()
103 #define AUDIO_ERROR_MESSAGE(e)
104 #define AUDIO_TIMER_MINUTE(t)
105 #define AUDIO_TIMER_30()
106 #define AUDIO_TIMER_20()
107 #define AUDIO_WARNING2()
108 #define AUDIO_WARNING1()
109 #define AUDIO_ERROR()
110 #define AUDIO_MIX_WARNING(x)
111 #define AUDIO_POT_MIDDLE()
112 #define AUDIO_TIMER_LT10(m, x)
113 #define AUDIO_TIMER_00(m)
114 #define AUDIO_VARIO_UP()
115 #define AUDIO_VARIO_DOWN()
116 #define AUDIO_TRIM(event, f)
117 #define AUDIO_TRIM_MIDDLE(f)
118 #define AUDIO_TRIM_END(f)
119 #define AUDIO_PLAY(p)
120 #define IS_AUDIO_BUSY() false
121 #endif /* BUZZER */
123 #define AUDIO_RESET()
124 #define AUDIO_FLUSH()
126 #define PLAY_PHASE_OFF(phase)
127 #define PLAY_PHASE_ON(phase)
128 #define PLAY_SWITCH_MOVED(sw)
129 #define PLAY_LOGICAL_SWITCH_OFF(sw)
130 #define PLAY_LOGICAL_SWITCH_ON(sw)
131 #define PLAY_MODEL_NAME()
132 #define START_SILENCE_PERIOD()
133 #endif /* !AUDIO */
135 #if !defined(CPUARM)
136 #if defined(BUZZER)
137 inline void BUZZER_HEARTBEAT()
139 if (g_beepCnt) {
140 if (!beepAgainOrig) {
141 beepAgainOrig = g_beepCnt;
142 beepOn = true;
144 g_beepCnt--;
146 else {
147 if (beepAgain && beepAgainOrig) {
148 beepOn = !beepOn;
149 g_beepCnt = beepOn ? beepAgainOrig : 8;
150 if (beepOn) beepAgain--;
152 else {
153 beepAgainOrig = 0;
154 beepOn = false;
155 warble = false;
159 if (beepOn) {
160 warbleC = warble && !warbleC;
161 if (warbleC)
162 buzzerOff();
163 else
164 buzzerOn();
166 else {
167 buzzerOff();
170 #else // BUZZER
171 #define BUZZER_HEARTBEAT()
172 #endif // BUZZER
173 #endif // CPUARM
175 #endif // _BUZZER_H_