mb5nn/mb5nn.ino

101 lines
1.6 KiB
Arduino
Raw Normal View History

2024-09-14 14:05:32 +01:00
/* Copywrite M0ZAH - simple morse ID */
/* IO */
#define IDTIME 10000
#define COS 0
#define PTT 1
#define PIP 3
/* CW ID SETTINGS */
#define ID "MB5NN"
#define CW_SPEED 22
#define CW_PITCH 1000
typedef enum {
STBY,
HANG,
IN_USE,
CW,
}state;
typedef struct {
char* callsign;
int cw_pitch;
int cw_speed;
unsigned long id;
bool is_id;
state state;
}rpt;
rpt *myrpt;
unsigned long tick;
void setup() {
pinMode(COS, INPUT_PULLUP);
pinMode(PIP, OUTPUT);
pinMode(PTT, OUTPUT);
static rpt repeater = {
.callsign = ID,
.cw_pitch = CW_PITCH,
.cw_speed = 1200 / CW_SPEED,
.id = 0,
.is_id = false,
.state = STBY,
};
myrpt = &repeater;
}
void loop() {
tick = millis();
switch (myrpt->state) {
case STBY:
if (!digitalRead(COS)) {
digitalWrite(PTT, LOW);
myrpt->state = IN_USE;
}
if (!digitalRead(PTT))
digitalWrite(PTT, HIGH);
break;
case HANG:
delay(250);
tone(PIP, 875, 75);
unsigned long hang = tick;
for(;;) {
if (!digitalRead(COS)) {
myrpt->state = IN_USE;
break;
}
if (millis() - hang >= 1000) {
myrpt->state = STBY;
break;
}
}
break;
case IN_USE:
if (digitalRead(COS)) {
delay(250);
if (!digitalRead(COS))
break;
myrpt->state = HANG;
}
break;
case CW:
/* This is not used at this time */
break;
}
/* Is it time to ID? */
if (tick - myrpt->id > IDTIME) {
if (myrpt->state > STBY) {
myrpt->is_id = true;
sendID(myrpt);
}
}
}