commit a89bc612968c8870a1c1c3c3a3358d46f6857e7c Author: JimZAH Date: Sat Sep 14 14:05:32 2024 +0100 init diff --git a/cw.h b/cw.h new file mode 100644 index 0000000..a49a3b5 --- /dev/null +++ b/cw.h @@ -0,0 +1,44 @@ +#ifndef CW_H +#define CW_H + +int morse[] = { + 0b00101001, // / + 0b00111111, // 0 + 0b00111110, // 1 + 0b00111100, // 2 + 0b00111000, // 3 + 0b00110000, // 4 + 0b00100000, // 5 + 0b00100001, // 6 + 0b00100011, // 7 + 0b00100111, // 8 + 0b00101111, // 9 + 0b00000110, // A + 0b00010001, // B + 0b00010101, // C + 0b00001001, // D + 0b00000010, // E + 0b00010100, // F + 0b00001011, // G + 0b00010000, // H + 0b00000100, // I + 0b00011110, // J + 0b00001101, // K + 0b00010010, // L + 0b00000111, // M + 0b00000101, // N + 0b00001111, // O + 0b00010110, // P + 0b00011011, // Q + 0b00001010, // R + 0b00001000, // S + 0b00000011, // T + 0b00001100, // U + 0b00011000, // V + 0b00001110, // W + 0b00011001, // X + 0b00011101, // Y + 0b00010011, // Z +}; + +#endif diff --git a/cw.ino b/cw.ino new file mode 100644 index 0000000..2fed1d8 --- /dev/null +++ b/cw.ino @@ -0,0 +1,52 @@ +#include "cw.h" + +void sendChar(rpt* myrpt, char c) { + if (c < 47 || c > 90) { + delay(myrpt->cw_speed * 3 * 2); + return; + } + + if (c > 57 && c < 65) { + return; + } + + int index = c - 47; + if (c >= 65) { + index = c - 54; + } + + if (index >= sizeof morse/sizeof morse[0]) + return; + + int dd = morse[index]; + + for (int i=0; i < 8; i++) { + if (dd == 1) { + return; + } + tone(PIP, myrpt->cw_pitch); + if (dd&1) { + delay(myrpt->cw_speed * 3); + } else { + delay(myrpt->cw_speed); + } + dd >>= 1; + noTone(PIP); + delay(myrpt->cw_speed); + } +} + +void sendID(rpt* myrpt) { + myrpt->id = millis(); + if (myrpt->callsign == NULL) { + return; + } + + delay(500); + + for (int i=0; i < sizeof ID/sizeof ID[0]; i++) { + sendChar(myrpt, myrpt->callsign[i]); + delay(myrpt->cw_speed * 3); + } + myrpt->is_id = false; +} diff --git a/mb5nn.ino b/mb5nn.ino new file mode 100644 index 0000000..e9d4bef --- /dev/null +++ b/mb5nn.ino @@ -0,0 +1,100 @@ +/* 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); + } + } +}