1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-21 15:25:17 +03:00

Haptic 0,1,2,3

This commit is contained in:
gbirkus@gmail.com 2012-05-04 10:24:04 +00:00
parent 2eeedf6c55
commit 0d4911a0d4

View file

@ -1,124 +1,125 @@
/* /*
* Authors (alphabetical order) * Authors (alphabetical order)
* - Bertrand Songis <bsongis@gmail.com> * - Bertrand Songis <bsongis@gmail.com>
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com> * - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
* - Cameron Weeks <th9xer@gmail.com> * - Cameron Weeks <th9xer@gmail.com>
* - Erez Raviv * - Erez Raviv
* - Jean-Pierre Parisy * - Jean-Pierre Parisy
* - Karl Szmutny <shadow@privy.de> * - Karl Szmutny <shadow@privy.de>
* - Michael Blandford * - Michael Blandford
* - Michal Hlavinka * - Michal Hlavinka
* - Pat Mackenzie * - Pat Mackenzie
* - Philip Moss * - Philip Moss
* - Rob Thomson * - Rob Thomson
* - Romolo Manfredini <romolo.manfredini@gmail.com> * - Romolo Manfredini <romolo.manfredini@gmail.com>
* - Thomas Husterer * - Thomas Husterer
* *
* open9x is based on code named * open9x is based on code named
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/, * gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
* er9x by Erez Raviv: http://code.google.com/p/er9x/, * er9x by Erez Raviv: http://code.google.com/p/er9x/,
* and the original (and ongoing) project by * and the original (and ongoing) project by
* Thomas Husterer, th9x: http://code.google.com/p/th9x/ * Thomas Husterer, th9x: http://code.google.com/p/th9x/
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as * it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. * published by the Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
*/ */
#include "open9x.h" #include "open9x.h"
hapticQueue::hapticQueue() hapticQueue::hapticQueue()
{ {
buzzTimeLeft = 0; buzzTimeLeft = 0;
buzzPause = 0; buzzPause = 0;
t_queueRidx = 0; t_queueRidx = 0;
t_queueWidx = 0; t_queueWidx = 0;
hapticTick = 0; hapticTick = 0;
} }
void hapticQueue::heartbeat() void hapticQueue::heartbeat()
{ {
#if defined(SIMU) #if defined(SIMU)
return; return;
#endif #endif
if (buzzTimeLeft > 0) { if (buzzTimeLeft > 0) {
buzzTimeLeft--; // time gets counted down buzzTimeLeft--; // time gets counted down
#if defined(PCBARM) #if defined(PCBARM)
hapticOn(g_eeGeneral.hapticStrength * 20); hapticOn(g_eeGeneral.hapticStrength * 20);
#else #else
if (hapticTick-- > 0) { if (hapticTick-- > 0) {
HAPTIC_ON; // haptic output 'high' HAPTIC_ON; // haptic output 'high'
} }
else { else {
HAPTIC_OFF; // haptic output 'high' HAPTIC_OFF; // haptic output 'high'
hapticTick = g_eeGeneral.hapticStrength; hapticTick = g_eeGeneral.hapticStrength;
} }
#endif #endif
} }
else { else {
HAPTIC_OFF; // haptic output 'high' HAPTIC_OFF; // haptic output 'high'
if (buzzPause > 0) { if (buzzPause > 0) {
buzzPause--; buzzPause--;
} }
else if (t_queueRidx != t_queueWidx) { else if (t_queueRidx != t_queueWidx) {
buzzTimeLeft = queueHapticLength[t_queueRidx]; buzzTimeLeft = queueHapticLength[t_queueRidx];
buzzPause = queueHapticPause[t_queueRidx]; buzzPause = queueHapticPause[t_queueRidx];
if (!queueHapticRepeat[t_queueRidx]--) { if (!queueHapticRepeat[t_queueRidx]--) {
t_queueRidx = (t_queueRidx + 1) % HAPTIC_QUEUE_LENGTH; t_queueRidx = (t_queueRidx + 1) % HAPTIC_QUEUE_LENGTH;
} }
} }
} }
} }
void hapticQueue::play(uint8_t tLen, uint8_t tPause, uint8_t tFlags) void hapticQueue::play(uint8_t tLen, uint8_t tPause, uint8_t tFlags)
{ {
tLen = getHapticLength(tLen); tLen = getHapticLength(tLen);
if ((tFlags & PLAY_NOW) || (!busy() && empty())) { if ((tFlags & PLAY_NOW) || (!busy() && empty())) {
buzzTimeLeft = tLen; buzzTimeLeft = tLen;
buzzPause = tPause; buzzPause = tPause;
t_queueWidx = t_queueRidx; t_queueWidx = t_queueRidx;
} }
else { else {
tFlags += 1; tFlags += 1;
} }
tFlags &= 0x0f; tFlags &= 0x0f;
if (tFlags) { if (tFlags) {
uint8_t next_queueWidx = (t_queueWidx + 1) % HAPTIC_QUEUE_LENGTH; uint8_t next_queueWidx = (t_queueWidx + 1) % HAPTIC_QUEUE_LENGTH;
if (next_queueWidx != t_queueRidx) { if (next_queueWidx != t_queueRidx) {
queueHapticLength[t_queueWidx] = tLen; queueHapticLength[t_queueWidx] = tLen;
queueHapticPause[t_queueWidx] = tPause; queueHapticPause[t_queueWidx] = tPause;
queueHapticRepeat[t_queueWidx] = tFlags-1; queueHapticRepeat[t_queueWidx] = tFlags-1;
t_queueWidx = next_queueWidx; t_queueWidx = next_queueWidx;
} }
} }
} }
void hapticQueue::event(uint8_t e) void hapticQueue::event(uint8_t e)
{ {
if (g_eeGeneral.hapticMode>0 || (g_eeGeneral.hapticMode==0 && e>=AU_WARNING1) || (g_eeGeneral.hapticMode>=-1 && e<=AU_ERROR)) { if (g_eeGeneral.hapticMode>0 || (g_eeGeneral.hapticMode==0 && e>=AU_WARNING1) || (g_eeGeneral.hapticMode>=-1 && e<=AU_ERROR)) {
if (e <= AU_ERROR) if (e <= AU_ERROR)
play(15, 3, PLAY_NOW); play(15, 3, PLAY_NOW);
else if (e <= AU_TRIM_MOVE) else if (e <= AU_TRIM_MOVE)
play(5, 0, PLAY_NOW); play(5, 0, PLAY_NOW);
else if (e <= AU_TIMER_LT3) else if (e <= AU_TIMER_LT3)
play(15, 3, PLAY_NOW); play(15, 3, PLAY_NOW);
else if (e < AU_FRSKY_FIRST) else if (e < AU_FRSKY_FIRST)
play(15, 3, (e-AU_TIMER_10)|PLAY_NOW); play(15, 3, (e-AU_TIMER_10)|PLAY_NOW);
else if (e >= AU_FRSKY_LAST && empty()) { else if (e >= AU_FRSKY_LAST && empty()) {
play(15, 3, e-AU_FRSKY_LAST); play(30, 10, 0);
} play(10,50-10*(e-AU_FRSKY_LAST),(e-AU_FRSKY_LAST));
} }
} }
}
hapticQueue haptic;
hapticQueue haptic;