Various fixes around Companion trainer mode (#7116)
[opentx.git] / radio / src / haptic.h
blob498a9f541121b54746bb9048d6796eec6da30c25
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 _HAPTIC_H_
22 #define _HAPTIC_H_
24 #define HAPTIC_QUEUE_LENGTH 4
26 class hapticQueue
28 public:
30 hapticQueue();
32 // only difference between these two functions is that one does the
33 // interupt queue (Now) and the other queues for playing ASAP.
34 void play(uint8_t tLen, uint8_t tPause, uint8_t tRepeat=0);
36 inline bool busy() { return (buzzTimeLeft > 0); }
38 void event(uint8_t e);
40 // heartbeat is responsibile for issueing the haptic buzzs and general square waves
41 // it is essentially the life of the class.
42 void heartbeat();
44 // bool freeslots(uint8_t slots);
46 inline bool empty() {
47 return (t_queueRidx == t_queueWidx);
50 protected:
51 inline uint8_t getHapticLength(uint8_t tLen) {
52 return ((g_eeGeneral.hapticLength * 2) + tLen) * 2;
55 private:
56 uint8_t t_queueRidx;
57 uint8_t t_queueWidx;
59 uint8_t buzzTimeLeft;
60 uint8_t buzzPause;
62 uint8_t hapticTick;
64 // queue arrays
65 uint8_t queueHapticLength[HAPTIC_QUEUE_LENGTH];
66 uint8_t queueHapticPause[HAPTIC_QUEUE_LENGTH];
67 uint8_t queueHapticRepeat[HAPTIC_QUEUE_LENGTH];
70 extern hapticQueue haptic;
72 #define IS_HAPTIC_BUSY() haptic.busy()
73 #define HAPTIC_HEARTBEAT() haptic.heartbeat()
76 #endif // _HAPTIC_H_