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.
23 hapticQueue::hapticQueue()
34 void hapticQueue::heartbeat()
39 if (buzzTimeLeft
> 0) {
40 buzzTimeLeft
--; // time gets counted down
41 #if defined(PCBSKY9X) || defined(PCBX9DP) || defined(PCBX9E) || defined(PCBFLAMENCO) || defined(PCBHORUS)
42 // TODO define HAPTIC_PWM option
43 hapticOn(HAPTIC_STRENGTH() * 20);
45 if (hapticTick
-- > 0) {
50 hapticTick
= HAPTIC_STRENGTH();
59 else if (t_queueRidx
!= t_queueWidx
) {
60 buzzTimeLeft
= queueHapticLength
[t_queueRidx
];
61 buzzPause
= queueHapticPause
[t_queueRidx
];
62 if (!queueHapticRepeat
[t_queueRidx
]--) {
63 t_queueRidx
= (t_queueRidx
+ 1) & (HAPTIC_QUEUE_LENGTH
-1);
67 #endif // defined(SIMU)
70 void hapticQueue::play(uint8_t tLen
, uint8_t tPause
, uint8_t tFlags
)
72 tLen
= getHapticLength(tLen
);
74 if ((tFlags
& PLAY_NOW
) || (!busy() && empty())) {
77 t_queueWidx
= t_queueRidx
;
85 uint8_t next_queueWidx
= (t_queueWidx
+ 1) & (HAPTIC_QUEUE_LENGTH
-1);
86 if (next_queueWidx
!= t_queueRidx
) {
87 queueHapticLength
[t_queueWidx
] = tLen
;
88 queueHapticPause
[t_queueWidx
] = tPause
;
89 queueHapticRepeat
[t_queueWidx
] = tFlags
-1;
90 t_queueWidx
= next_queueWidx
;
95 void hapticQueue::event(uint8_t e
)
97 if (g_eeGeneral
.hapticMode
>= e_mode_nokeys
|| (g_eeGeneral
.hapticMode
>= e_mode_alarms
&& e
<= AU_ERROR
)) {
99 play(15, 3, PLAY_NOW
);
100 else if (e
<= AU_MIX_WARNING_3
)
101 play(15, 3, PLAY_NOW
);
102 else if (e
>= AU_SPECIAL_SOUND_LAST
&& empty()) {
104 play(10, 50-10*(e
-AU_SPECIAL_SOUND_LAST
), (e
-AU_SPECIAL_SOUND_LAST
));