ubitx-v5x/TeensyDSP/TR.h

170 lines
3.9 KiB
C++

//======================================================================
// TR.h
//======================================================================
#ifndef __TR_h__
#define __TR_h__
#include <Bounce2.h>
#include "Debug.h"
#include "DSP.h"
#define UBITX_TR_OUT_PIN 2
#define UBITX_TR_PTT_PIN 3
#define UBITX_TR_VOX_PIN 4
#define UBITX_TR_KEY_PIN 5
const int uBitxTROutPin = UBITX_TR_OUT_PIN;
const int uBitxTRPttPin = UBITX_TR_PTT_PIN;
const int uBitxTRVoxPin = UBITX_TR_VOX_PIN;
const int uBitxTRKeyPin = UBITX_TR_KEY_PIN;
class UBitxTR {
public:
UBitxTR(UBitxDSP& d, int out = uBitxTROutPin, int p = uBitxTRPttPin, int v = uBitxTRVoxPin, int k = uBitxTRKeyPin):
dsp(d), outPin(out), pttPin(p), voxPin(v), keyPin(k) {}
void begin() {
pinMode(outPin, OUTPUT);
pinMode(voxPin, INPUT_PULLUP);
pinMode(keyPin, INPUT_PULLUP);
ptt.attach(pttPin, INPUT_PULLUP);
ptt.interval(5);
// default configuration: PTT, key, and CAT enabled; VOX disabled
DBGCMD( enablePTT() );
DBGCMD( disableVOX() );
DBGCMD( enableKey() );
DBGCMD( enableCAT() );
}
inline void enablePTT() { pttEnabled = true; }
inline void enableVOX() { voxEnabled = true; }
inline void enableKey() { keyEnabled = true; }
inline void enableCAT() { catEnabled = true; }
inline void disablePTT() { pttEnabled = false; }
inline void disableVOX() { voxEnabled = false; }
inline void disableKey() { keyEnabled = false; }
inline void disableCAT() { catEnabled = false; }
inline void catTX() {
L_catActive = catActive;
catActive = true;
}
inline void catRX() {
L_catActive = catActive;
catActive = false;
}
//======================================================================
inline bool transmitting() { return isTX; }
inline bool receiving() { return !isTX; }
/*!
* @brief Check if any of the PTT's have been pressed or released
* since the last update. Only one thing is allowed to occur
* based on an order of precedence. The highest priority is
* to stop transmitting.
*
* @param cw
* True if CW mode is currently active; false otherwise.
* Different/faster logic is used in CW mode.
*/
void update(bool cw = false);
void end() {
}
private:
inline void setTX() {
digitalWrite(outPin, LOW);
isTX = true;
}
inline void setRX() {
isTX = false;
digitalWrite(outPin, HIGH);
}
inline void updatePTT() {
ptt.update();
}
inline bool pttPressed() {
return ptt.fell();
}
inline bool pttReleased() {
return ptt.rose();
}
inline void updateVOX() {
L_voxActive = voxActive;
voxActive = (digitalRead(voxPin) == LOW);
}
inline bool voxActivated() {
return (L_voxActive != voxActive) && L_voxActive;
}
inline bool voxDeactivated() {
return (L_voxActive != voxActive) && voxActive;
}
inline void updateKey() {
L_keyDown = keyDown;
keyDown = (digitalRead(keyPin) == LOW);
}
inline bool keyPressed() {
return (L_keyDown != keyDown) && L_keyDown;
}
inline bool keyReleased() {
return (L_keyDown != keyDown) && keyDown;
}
inline bool catActivated() {
return (L_catActive != catActive) && L_catActive;
}
inline bool catDeactivated() {
return (L_catActive != catActive) && catActive;
}
UBitxDSP& dsp;
Bounce ptt;
int outPin;
int pttPin;
int voxPin;
int keyPin;
bool isTX = false;
bool pttEnabled = false;
bool voxEnabled = false;
bool keyEnabled = false;
bool catEnabled = false;
bool voxActive = false;
bool L_voxActive = false;
bool keyDown = false;
bool L_keyDown = false;
bool catActive = false;
bool L_catActive = false;
};
extern UBitxTR TR;
#endif
//======================================================================
// EOF
//======================================================================