m0zah/GB3TX/GB3TX.ino
Jim Colderwood 8c790fa4e0 GB3TX
2024-04-01 18:21:09 +01:00

129 lines
3.0 KiB
C++

#include "config.h"
#include "repeater.h"
#define PIP_OUT 13
void setup() {
pinMode(3, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(7, INPUT);
pinMode(6, INPUT_PULLUP);
}
void loop() {
repeater rpt;
repeater* myrpt;
myrpt = &rpt;
myrpt->callsign = ID;
myrpt->params.cw_pitch = CW_PITCH;
/* Setup params */
myrpt->params.cw_speed = 1200 / CW_SPEED;
myrpt->params.pip_length = RFPIPLEN;
myrpt->params.pip_pitch = RFPIP;
myrpt->params.pip_gw_length = GWPIPLEN;
myrpt->params.pip_gw_pitch = GWPIP;
myrpt->params.courtesy = COURTESY;
myrpt->params.pip_speed = 1200 / PIP_SPEED;
myrpt->params.pip_letter = PIP_LETTER;
myrpt->params.pip_gw_letter = PIP_GW_LETTER;
delay(1000);
myrpt->state = SLEEP;
digitalWrite(PTT,HIGH);
digitalWrite(GWPTT, false);
unsigned long ht = millis();
unsigned long tot = ht;
unsigned long kc;
unsigned long id = ht;
while (1) {
rx(myrpt);
if (myrpt->state > SLEEP && millis() - id >= IDTIME) {
/* Repeater is IDLE, bring the transmitter up */
if (myrpt->state == IDLE) {
myrpt->state = KEYCHUNK;
tx(myrpt);
myrpt->state = SLEEP;
}
sendID(myrpt);
id = millis();
}
if (((!myrpt->receiver.rx || !myrpt->gateway.receiver.rx)) && myrpt->state < 2) {
myrpt->state = KEYCHUNK;
if (!myrpt->receiver.rx)
kc = millis();
}
if (myrpt->state == KEYCHUNK && millis() - kc > KEYCHUNK_TIME) {
if (!myrpt->receiver.rx) {
myrpt->state = TT;
} else {
myrpt->state = GW;
}
tot = millis();
}
if ((myrpt->receiver.rx && myrpt->gateway.receiver.rx) && myrpt->state == KEYCHUNK) {
myrpt->state = IDLE;
}
if ((myrpt->receiver.rx && myrpt->gateway.receiver.rx) && myrpt->state > HANG) {
myrpt->last = myrpt->state;
myrpt->state = HANG;
ht = millis();
if (ht - tot < PIP_KEYCHUNK)
continue;
delay(350);
if (!digitalRead(COS)) {
continue;
}
courtesyTone(myrpt);
}
if (myrpt->state == HANG && TAILPIPS) {
static unsigned long bc = millis();
if (millis() - bc >= 1000) {
bc = millis();
tone(3, myrpt->params.pip_pitch - 500, myrpt->params.pip_length * 1);
}
}
if (!myrpt->receiver.rx && myrpt->state == HANG) {
myrpt->state = TT;
tot = millis();
}
if (!myrpt->gateway.receiver.rx && myrpt->state == HANG) {
myrpt->state = GW;
tot = millis();
}
if (myrpt->state == HANG && millis() - ht > HANGTIME) {
myrpt->state = IDLE;
}
if (millis() - tot >= TIMEOUT && (myrpt->state == TT || myrpt->state == GW)) {
myrpt->state = TIMEOUT;
tone(3, 440, 1000);
delay(1000);
}
if (myrpt->state == TIMEOUT) {
myrpt->state = IDLE;
tx(myrpt);
while (1) {
rx(myrpt);
if (myrpt->receiver.rx && myrpt->gateway.receiver.rx)
break;
}
}
tx(myrpt);
}
}