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(HAPTIC_PWM)
42 hapticOn(HAPTIC_STRENGTH() * 20);
44 if (hapticTick
-- > 0) {
49 hapticTick
= HAPTIC_STRENGTH();
58 else if (t_queueRidx
!= t_queueWidx
) {
59 buzzTimeLeft
= queueHapticLength
[t_queueRidx
];
60 buzzPause
= queueHapticPause
[t_queueRidx
];
61 if (!queueHapticRepeat
[t_queueRidx
]--) {
62 t_queueRidx
= (t_queueRidx
+ 1) & (HAPTIC_QUEUE_LENGTH
-1);
66 #endif // defined(SIMU)
69 void hapticQueue::play(uint8_t tLen
, uint8_t tPause
, uint8_t tFlags
)
71 tLen
= getHapticLength(tLen
);
73 if ((tFlags
& PLAY_NOW
) || (!busy() && empty())) {
76 t_queueWidx
= t_queueRidx
;
84 uint8_t next_queueWidx
= (t_queueWidx
+ 1) & (HAPTIC_QUEUE_LENGTH
-1);
85 if (next_queueWidx
!= t_queueRidx
) {
86 queueHapticLength
[t_queueWidx
] = tLen
;
87 queueHapticPause
[t_queueWidx
] = tPause
;
88 queueHapticRepeat
[t_queueWidx
] = tFlags
-1;
89 t_queueWidx
= next_queueWidx
;
94 void hapticQueue::event(uint8_t e
)
96 if (g_eeGeneral
.hapticMode
>= e_mode_nokeys
|| (g_eeGeneral
.hapticMode
>= e_mode_alarms
&& e
<= AU_ERROR
)) {
98 play(15, 3, PLAY_NOW
);
99 else if (e
<= AU_MIX_WARNING_3
)
100 play(15, 3, PLAY_NOW
);
101 else if (e
>= AU_SPECIAL_SOUND_LAST
&& empty()) {
103 play(10, 50-10*(e
-AU_SPECIAL_SOUND_LAST
), (e
-AU_SPECIAL_SOUND_LAST
));