mirror of
https://github.com/opentx/opentx.git
synced 2025-07-24 00:35:18 +03:00
Commit again as files did not go up!
This commit is contained in:
parent
223677c7ff
commit
f632dd11fa
2 changed files with 286 additions and 0 deletions
171
src/haptic.cpp
Normal file
171
src/haptic.cpp
Normal file
|
@ -0,0 +1,171 @@
|
|||
/*
|
||||
* Authors (alphabetical order)
|
||||
* - Bertrand Songis <bsongis@gmail.com>
|
||||
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
|
||||
* - Cameron Weeks <th9xer@gmail.com>
|
||||
* - Erez Raviv
|
||||
* - Jean-Pierre Parisy
|
||||
* - Karl Szmutny <shadow@privy.de>
|
||||
* - Michael Blandford
|
||||
* - Michal Hlavinka
|
||||
* - Pat Mackenzie
|
||||
* - Philip Moss
|
||||
* - Rob Thomson
|
||||
* - Romolo Manfredini <romolo.manfredini@gmail.com>
|
||||
* - Thomas Husterer
|
||||
*
|
||||
* open9x is based on code named
|
||||
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
|
||||
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
|
||||
* and the original (and ongoing) project by
|
||||
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
|
||||
*
|
||||
* 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
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "open9x.h"
|
||||
|
||||
hapticQueue::hapticQueue()
|
||||
{
|
||||
buzzTimeLeft = 0;
|
||||
buzzPause = 0;
|
||||
|
||||
t_queueRidx = 0;
|
||||
t_queueWidx = 0;
|
||||
|
||||
hapticTick = 0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
#if 0
|
||||
bool hapticQueue::freeslots(uint8_t slots)
|
||||
{
|
||||
return HAPTIC_QUEUE_LENGTH - ((t_queueWidx + HAPTIC_QUEUE_LENGTH - t_queueRidx) % HAPTIC_QUEUE_LENGTH) >= slots;
|
||||
}
|
||||
#endif
|
||||
|
||||
void hapticQueue::heartbeat()
|
||||
{
|
||||
#if defined(SIMU)
|
||||
return;
|
||||
#endif
|
||||
|
||||
#if defined(PCBARM)
|
||||
|
||||
|
||||
if (buzzTimeLeft > 0) {
|
||||
buzzTimeLeft--; //time gets counted down
|
||||
hapticOn((g_eeGeneral.hapticStrength * 2) * 10);
|
||||
}
|
||||
else {
|
||||
hapticOff();
|
||||
|
||||
if (buzzPause > 0) {
|
||||
buzzPause--;
|
||||
}
|
||||
else if (t_queueRidx != t_queueWidx) {
|
||||
buzzTimeLeft = queueHapticLength[t_queueRidx];
|
||||
buzzPause = queueHapticPause[t_queueRidx];
|
||||
if (!queueHapticRepeat[t_queueRidx]--) {
|
||||
t_queueRidx = (t_queueRidx + 1) % HAPTIC_QUEUE_LENGTH;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#else
|
||||
|
||||
if (buzzTimeLeft > 0) {
|
||||
|
||||
buzzTimeLeft--; //time gets counted down
|
||||
//if (buzzHaptic){
|
||||
if (hapticTick-- > 0) {
|
||||
HAPTIC_ON; // haptic output 'high'
|
||||
}
|
||||
else {
|
||||
HAPTIC_OFF; // haptic output 'high'
|
||||
hapticTick = g_eeGeneral.hapticStrength;
|
||||
}
|
||||
//}
|
||||
}
|
||||
else {
|
||||
HAPTIC_OFF; // haptic output 'high'
|
||||
|
||||
if (buzzPause > 0) {
|
||||
buzzPause--;
|
||||
}
|
||||
else if (t_queueRidx != t_queueWidx) {
|
||||
buzzTimeLeft = queueHapticLength[t_queueRidx];
|
||||
buzzPause = queueHapticPause[t_queueRidx];
|
||||
if (!queueHapticRepeat[t_queueRidx]--) {
|
||||
t_queueRidx = (t_queueRidx + 1) % HAPTIC_QUEUE_LENGTH;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
inline uint8_t hapticQueue::getHapticLength(uint8_t tLen)
|
||||
{
|
||||
|
||||
return ((g_eeGeneral.hapticLength * 2) + tLen) * 2;
|
||||
|
||||
}
|
||||
|
||||
void hapticQueue::playNow(uint8_t tLen, uint8_t tPause, uint8_t tRepeat)
|
||||
{
|
||||
buzzTimeLeft = getHapticLength(tLen);
|
||||
buzzPause = tPause;
|
||||
t_queueWidx = t_queueRidx;
|
||||
|
||||
if (tRepeat) {
|
||||
playASAP(tLen, tPause, tRepeat-1);
|
||||
}
|
||||
}
|
||||
|
||||
void hapticQueue::playASAP(uint8_t tLen, uint8_t tPause, uint8_t tRepeat)
|
||||
{
|
||||
uint8_t next_queueWidx = (t_queueWidx + 1) % HAPTIC_QUEUE_LENGTH;
|
||||
if (next_queueWidx != t_queueRidx) {
|
||||
queueHapticLength[t_queueWidx] = getHapticLength(tLen);
|
||||
queueHapticPause[t_queueWidx] = tPause;
|
||||
queueHapticRepeat[t_queueWidx] = tRepeat-1;
|
||||
t_queueWidx = next_queueWidx;
|
||||
}
|
||||
}
|
||||
|
||||
void hapticQueue::event(uint8_t e)
|
||||
{
|
||||
|
||||
switch (e) {
|
||||
case 1: //one buzz
|
||||
playASAP(10,2,1);
|
||||
break;
|
||||
case 2: // two buzz
|
||||
playASAP(10,2,2);
|
||||
break;
|
||||
case 3: // three buzz
|
||||
playASAP(10,2,3);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void hapticDefevent(uint8_t e)
|
||||
{
|
||||
haptic.event(e);
|
||||
}
|
115
src/haptic.h
Normal file
115
src/haptic.h
Normal file
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* Authors (alphabetical order)
|
||||
* - Bertrand Songis <bsongis@gmail.com>
|
||||
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
|
||||
* - Cameron Weeks <th9xer@gmail.com>
|
||||
* - Erez Raviv
|
||||
* - Jean-Pierre Parisy
|
||||
* - Karl Szmutny <shadow@privy.de>
|
||||
* - Michael Blandford
|
||||
* - Michal Hlavinka
|
||||
* - Pat Mackenzie
|
||||
* - Philip Moss
|
||||
* - Rob Thomson
|
||||
* - Romolo Manfredini <romolo.manfredini@gmail.com>
|
||||
* - Thomas Husterer
|
||||
*
|
||||
* open9x is based on code named
|
||||
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
|
||||
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
|
||||
* and the original (and ongoing) project by
|
||||
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
|
||||
*
|
||||
* 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
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef haptic_h
|
||||
#define haptic_h
|
||||
|
||||
|
||||
#if defined(PCBARM)
|
||||
#include "ersky9x/haptic.h"
|
||||
#endif
|
||||
|
||||
|
||||
//haptic
|
||||
#define HAPTIC_QUEUE_LENGTH (8) //8 seems to suit most alerts
|
||||
|
||||
|
||||
|
||||
|
||||
class hapticQueue
|
||||
{
|
||||
public:
|
||||
|
||||
hapticQueue();
|
||||
|
||||
// only difference between these two functions is that one does the
|
||||
// interupt queue (Now) and the other queues for playing ASAP.
|
||||
void playNow(uint8_t tLen, uint8_t tPause, uint8_t tRepeat=0);
|
||||
|
||||
void playASAP(uint8_t tLen, uint8_t tPause, uint8_t tRepeat=0);
|
||||
|
||||
inline bool busy() { return (buzzTimeLeft > 0); }
|
||||
|
||||
void event(uint8_t e);
|
||||
|
||||
|
||||
|
||||
// heartbeat is responsibile for issueing the haptic buzzs and general square waves
|
||||
// it is essentially the life of the class.
|
||||
void heartbeat();
|
||||
|
||||
// bool freeslots(uint8_t slots);
|
||||
|
||||
inline bool empty() {
|
||||
return (t_queueRidx == t_queueWidx);
|
||||
}
|
||||
|
||||
protected:
|
||||
inline uint8_t getHapticLength(uint8_t tLen);
|
||||
|
||||
private:
|
||||
uint8_t t_queueRidx;
|
||||
uint8_t t_queueWidx;
|
||||
|
||||
|
||||
uint8_t buzzTimeLeft;
|
||||
uint8_t buzzPause;
|
||||
|
||||
// queue arrays
|
||||
uint8_t queueHapticLength[HAPTIC_QUEUE_LENGTH];
|
||||
uint8_t queueHapticPause[HAPTIC_QUEUE_LENGTH];
|
||||
uint8_t queueHapticRepeat[HAPTIC_QUEUE_LENGTH];
|
||||
uint8_t buzzHaptic;
|
||||
uint8_t hapticTick;
|
||||
|
||||
|
||||
#if defined(PCBSTD)
|
||||
uint8_t buzzCounter;
|
||||
#endif
|
||||
};
|
||||
|
||||
//wrapper function - dirty but results in a space saving!!!
|
||||
extern hapticQueue haptic;
|
||||
|
||||
void hapticDefevent(uint8_t e);
|
||||
|
||||
#define HAPTIC_SPINUP (10);
|
||||
|
||||
|
||||
|
||||
#define IS_HAPTIC_BUSY() haptic.busy()
|
||||
|
||||
|
||||
#define HAPTIC_HEARTBEAT() haptic.heartbeat()
|
||||
|
||||
#endif // haptic_h
|
Loading…
Add table
Add a link
Reference in a new issue