Audible alarms on TX side
This commit is contained in:
43
crossbow.ino
43
crossbow.ino
@@ -178,7 +178,7 @@ void setup(void)
|
|||||||
pinMode(TX_BUZZER_PIN, OUTPUT);
|
pinMode(TX_BUZZER_PIN, OUTPUT);
|
||||||
|
|
||||||
//Play single tune to indicate power up
|
//Play single tune to indicate power up
|
||||||
buzzerSingleMode(BUZZER_MODE_CHIRP, TX_BUZZER_PIN, millis(), &buzzer);
|
buzzerSingleMode(BUZZER_MODE_CHIRP, &buzzer);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pinMode(LED_BUILTIN, OUTPUT);
|
pinMode(LED_BUILTIN, OUTPUT);
|
||||||
@@ -275,6 +275,7 @@ int8_t getFrameToTransmit(QspConfiguration_t *qsp) {
|
|||||||
|
|
||||||
void loop(void)
|
void loop(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifdef DEVICE_MODE_TX
|
#ifdef DEVICE_MODE_TX
|
||||||
if (txDeviceState.readPacket) {
|
if (txDeviceState.readPacket) {
|
||||||
int incomingByte = LoRa.read();
|
int incomingByte = LoRa.read();
|
||||||
@@ -290,6 +291,7 @@ void loop(void)
|
|||||||
|
|
||||||
uint32_t currentMillis = millis();
|
uint32_t currentMillis = millis();
|
||||||
bool transmitPayload = false;
|
bool transmitPayload = false;
|
||||||
|
static uint32_t previousAnyFrameReceivedAt = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Watchdog for frame decoding stuck somewhere in the middle of a process
|
* Watchdog for frame decoding stuck somewhere in the middle of a process
|
||||||
@@ -401,6 +403,45 @@ void loop(void)
|
|||||||
|
|
||||||
buzzerProcess(TX_BUZZER_PIN, currentMillis, &buzzer);
|
buzzerProcess(TX_BUZZER_PIN, currentMillis, &buzzer);
|
||||||
|
|
||||||
|
// This routing enables when TX starts to receive signal from RX for a first time or after
|
||||||
|
// failsafe
|
||||||
|
if (txDeviceState.isReceiving == false && qsp.anyFrameRecivedAt != 0) {
|
||||||
|
//TX module started to receive data
|
||||||
|
buzzerSingleMode(BUZZER_MODE_DOUBLE_CHIRP, &buzzer);
|
||||||
|
txDeviceState.isReceiving = true;
|
||||||
|
qsp.deviceState = DEVICE_STATE_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Here we detect failsafe state on TX module
|
||||||
|
if (txDeviceState.isReceiving && abs(currentMillis - qsp.anyFrameRecivedAt) > TX_FAILSAFE_DELAY) {
|
||||||
|
txDeviceState.isReceiving = false;
|
||||||
|
rxDeviceState.a1Voltage = 0;
|
||||||
|
rxDeviceState.a2Voltage = 0;
|
||||||
|
rxDeviceState.rxVoltage = 0;
|
||||||
|
rxDeviceState.rssi = 0;
|
||||||
|
rxDeviceState.snr = 0;
|
||||||
|
rxDeviceState.flags = 0;
|
||||||
|
qsp.deviceState = DEVICE_STATE_FAILSAFE;
|
||||||
|
qsp.anyFrameRecivedAt = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//FIXME rxDeviceState should be resetted also in RC_HEALT frame is not received in a long period
|
||||||
|
|
||||||
|
//Handle audible alarms
|
||||||
|
if (qsp.deviceState == DEVICE_STATE_FAILSAFE) {
|
||||||
|
//Failsafe detected by TX
|
||||||
|
buzzerContinousMode(BUZZER_MODE_SLOW_BEEP, &buzzer);
|
||||||
|
} else if (txDeviceState.isReceiving && (rxDeviceState.flags & 0x1) == 1) {
|
||||||
|
//Failsafe reported by RX module
|
||||||
|
buzzerContinousMode(BUZZER_MODE_SLOW_BEEP, &buzzer);
|
||||||
|
} else if (txDeviceState.isReceiving && txDeviceState.rssi < 100) {
|
||||||
|
buzzerContinousMode(BUZZER_MODE_DOUBLE_CHIRP, &buzzer);
|
||||||
|
} else if (txDeviceState.isReceiving && txDeviceState.rssi < 128) {
|
||||||
|
buzzerContinousMode(BUZZER_MODE_CHIRP, &buzzer);
|
||||||
|
} else {
|
||||||
|
buzzerContinousMode(BUZZER_MODE_OFF, &buzzer);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef FEATURE_TX_OLED
|
#ifdef FEATURE_TX_OLED
|
||||||
if (
|
if (
|
||||||
currentMillis - lastOledTaskTime > OLED_UPDATE_RATE
|
currentMillis - lastOledTaskTime > OLED_UPDATE_RATE
|
||||||
|
|||||||
1
qsp.cpp
1
qsp.cpp
@@ -218,6 +218,7 @@ void qspDecodeIncomingFrame(
|
|||||||
if (frameId < QSP_FRAME_COUNT) {
|
if (frameId < QSP_FRAME_COUNT) {
|
||||||
qsp->lastFrameReceivedAt[frameId] = millis();
|
qsp->lastFrameReceivedAt[frameId] = millis();
|
||||||
}
|
}
|
||||||
|
qsp->anyFrameRecivedAt = millis();
|
||||||
|
|
||||||
switch (frameId) {
|
switch (frameId) {
|
||||||
case QSP_FRAME_RC_DATA:
|
case QSP_FRAME_RC_DATA:
|
||||||
|
|||||||
@@ -5,18 +5,17 @@
|
|||||||
* This method plays selected pattern only once
|
* This method plays selected pattern only once
|
||||||
* It disables continious mode
|
* It disables continious mode
|
||||||
*/
|
*/
|
||||||
void buzzerSingleMode(uint8_t mode, uint8_t pin, uint32_t timestamp, BuzzerState_t *buzzer) {
|
void buzzerSingleMode(uint8_t mode, BuzzerState_t *buzzer) {
|
||||||
buzzer->singleModeEnabled = true;
|
buzzer->singleModeEnabled = true;
|
||||||
buzzer->enabled = false;
|
buzzer->enabled = false;
|
||||||
buzzer->mode = mode;
|
buzzer->mode = mode;
|
||||||
buzzer->tick = 0;
|
buzzer->tick = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void buzzerContinousMode(uint8_t mode, uint8_t pin, uint32_t timestamp, BuzzerState_t *buzzer) {
|
void buzzerContinousMode(uint8_t mode, BuzzerState_t *buzzer) {
|
||||||
buzzer->singleModeEnabled = false;
|
buzzer->singleModeEnabled = false;
|
||||||
buzzer->enabled = true;
|
buzzer->enabled = true;
|
||||||
buzzer->mode = mode;
|
buzzer->mode = mode;
|
||||||
buzzer->tick = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void buzzerProcess(uint8_t pin, uint32_t timestamp, BuzzerState_t *buzzer)
|
void buzzerProcess(uint8_t pin, uint32_t timestamp, BuzzerState_t *buzzer)
|
||||||
|
|||||||
@@ -41,6 +41,6 @@ struct BuzzerState_t {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void buzzerSingleMode(uint8_t mode, uint8_t pin, uint32_t timestamp, BuzzerState_t *buzzer);
|
void buzzerSingleMode(uint8_t mode, BuzzerState_t *buzzer);
|
||||||
void buzzerContinousMode(uint8_t mode, uint8_t pin, uint32_t timestamp, BuzzerState_t *buzzer);
|
void buzzerContinousMode(uint8_t mode, BuzzerState_t *buzzer);
|
||||||
void buzzerProcess(uint8_t pin, uint32_t timestamp, BuzzerState_t *buzzer);
|
void buzzerProcess(uint8_t pin, uint32_t timestamp, BuzzerState_t *buzzer);
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#define TX_TRANSMIT_SLOT_RATE 50 //ms
|
#define TX_TRANSMIT_SLOT_RATE 50 //ms
|
||||||
#define RX_FAILSAFE_DELAY (TX_TRANSMIT_SLOT_RATE * 8)
|
#define RX_FAILSAFE_DELAY (TX_TRANSMIT_SLOT_RATE * 8)
|
||||||
|
#define TX_FAILSAFE_DELAY (RX_FAILSAFE_DELAY * 4)
|
||||||
|
|
||||||
#define CHANNEL_ID 0x01
|
#define CHANNEL_ID 0x01
|
||||||
#define QSP_PREAMBLE 0x51
|
#define QSP_PREAMBLE 0x51
|
||||||
@@ -44,7 +45,8 @@ enum dataStates {
|
|||||||
|
|
||||||
enum deviceStates {
|
enum deviceStates {
|
||||||
DEVICE_STATE_OK,
|
DEVICE_STATE_OK,
|
||||||
DEVICE_STATE_FAILSAFE
|
DEVICE_STATE_FAILSAFE,
|
||||||
|
DEVICE_STATE_UNDETERMINED
|
||||||
};
|
};
|
||||||
|
|
||||||
enum debugConfigFlags {
|
enum debugConfigFlags {
|
||||||
@@ -74,7 +76,8 @@ struct QspConfiguration_t {
|
|||||||
uint8_t payloadLength = 0;
|
uint8_t payloadLength = 0;
|
||||||
uint8_t frameToSend = 0;
|
uint8_t frameToSend = 0;
|
||||||
uint32_t lastFrameReceivedAt[QSP_FRAME_COUNT] = {0};
|
uint32_t lastFrameReceivedAt[QSP_FRAME_COUNT] = {0};
|
||||||
uint8_t deviceState = DEVICE_STATE_OK;
|
uint32_t anyFrameRecivedAt = 0;
|
||||||
|
uint8_t deviceState = DEVICE_STATE_UNDETERMINED;
|
||||||
void (* hardwareWriteFunction)(uint8_t, QspConfiguration_t*);
|
void (* hardwareWriteFunction)(uint8_t, QspConfiguration_t*);
|
||||||
bool canTransmit = false;
|
bool canTransmit = false;
|
||||||
bool forcePongFrame = false;
|
bool forcePongFrame = false;
|
||||||
@@ -90,6 +93,7 @@ struct TxDeviceState_t {
|
|||||||
uint8_t flags = 0;
|
uint8_t flags = 0;
|
||||||
uint32_t roundtrip = 0;
|
uint32_t roundtrip = 0;
|
||||||
bool readPacket = false;
|
bool readPacket = false;
|
||||||
|
bool isReceiving = false; //Indicates that TX module is receiving frames from RX module
|
||||||
};
|
};
|
||||||
|
|
||||||
struct RxDeviceState_t {
|
struct RxDeviceState_t {
|
||||||
|
|||||||
Reference in New Issue
Block a user