Skip to content

Commit

Permalink
store speed, pause for each device
Browse files Browse the repository at this point in the history
  • Loading branch information
topquark22 committed Oct 5, 2023
1 parent e0fce1f commit 2d45ca7
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 47 deletions.
30 changes: 19 additions & 11 deletions morse/morse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,22 @@ void clearMessage() {
message_len = 0;
}

void initNewArduino() {
if (NOT_SET == readIntFromEEPROM(ADDR_SPEED)) { // new Arduino

void showSettings() {
Serial.print(F("Dot duration: "));
Serial.print(t_dot);
Serial.println(F(" ms"));
Serial.print(F("Pause duration: "));
Serial.print(t_pause);
Serial.println(F(" ms"));
Serial.println();
}

void prepareDevice() {
if (NOT_SET == readIntFromEEPROM(msgBankAddr + OFFSET_ADDR_SPEED)) {
setSpeed(t_DOT);
setPause(t_PAUSE);
// clear all message banks
for (int i = 0; i < 4; i++) {
EEPROM.update(MSG_BANK_SIZE * i, 0);
}
EEPROM.update(msgBankAddr, 0);
}
}

Expand Down Expand Up @@ -99,7 +107,7 @@ void setupRadio() {

void writeMessageToEEPROM() {
int i;
for (i = 0; i < message_len && i < EEPROM_LEN - 1; i++) {
for (i = 0; i < message_len && i < MESSAGE_SIZE - 1; i++) {
EEPROM.update(msgBankAddr + i, message[i]);
}
EEPROM.update(msgBankAddr + i, 0);
Expand Down Expand Up @@ -142,21 +150,21 @@ int readIntFromEEPROM(int addr) {
return value;
}
void writeSpeedToEEPROM() {
writeIntToEEPROM(ADDR_SPEED, t_dot);
writeIntToEEPROM(msgBankAddr + OFFSET_ADDR_SPEED, t_dot);
}

void readSpeedFromEEPROM() {
t_dot = readIntFromEEPROM(ADDR_SPEED);
t_dot = readIntFromEEPROM(msgBankAddr + OFFSET_ADDR_SPEED);
t_dash = 3 * t_dot;
t_space = 6 * t_dot;
}

void writePauseToEEPROM() {
writeIntToEEPROM(ADDR_PAUSE, t_pause);
writeIntToEEPROM(msgBankAddr + OFFSET_ADDR_PAUSE, t_pause);
}

void readPauseFromEEPROM() {
t_pause = readIntFromEEPROM(ADDR_PAUSE);
t_pause = readIntFromEEPROM(msgBankAddr + OFFSET_ADDR_PAUSE);
}

void errExit() {
Expand Down
12 changes: 7 additions & 5 deletions morse/morse.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ const int t_PAUSE = 3000;
// Serial transmission rate
const int BAUD_RATE = 9600;

// EEPROM addresses
const int ADDR_SPEED = 0x3F0;
const int ADDR_PAUSE = 0x3F4;

// special value indicating that an int in EEPROM has not been set
const int NOT_SET = -1;

Expand All @@ -78,6 +74,10 @@ const int MESSAGE_SIZE = 240;
// determines location of message banks in EEPROM
const int MSG_BANK_SIZE = 0x100;

// EEPROM addresses (add msgBankAddr)
const int OFFSET_ADDR_SPEED = 0xF0;
const int OFFSET_ADDR_PAUSE = 0xF4;

// commBuffer[] is used to store/receive message via radio
// Format:
// commBuffer[0] : token indicating message type (1 byte)
Expand Down Expand Up @@ -105,9 +105,11 @@ const int CONSOLE_WIDTH = 80;

const int EEPROM_LEN = 0x3F0; // leave room for speed, pause

void showSettings();

void clearMessage();

void initNewArduino();
void prepareDevice();

void setupRadio();

Expand Down
14 changes: 7 additions & 7 deletions morse/morse.ino
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ void setup() {

Serial.begin(BAUD_RATE);

initNewArduino();

// pushbutton
pinMode(PIN_BUTTON_, INPUT_PULLUP);

Expand All @@ -41,7 +39,7 @@ void setup() {
// device ID jumpers
pinMode(PIN_ID1, INPUT_PULLUP);
pinMode(PIN_ID2, INPUT_PULLUP);

pinMode(PIN_XRMODE, INPUT_PULLUP);
transmitMode = digitalRead(PIN_XRMODE);

Expand All @@ -61,11 +59,12 @@ void setup() {
pinMode(PIN_ID2, INPUT_PULLUP);

int msgBankId = 2 * !digitalRead(PIN_ID2) + !digitalRead(PIN_ID1);
msgBankAddr = MSG_BANK_SIZE * msgBankId;

Serial.print(F("Using message bank "));
prepareDevice();

Serial.print(F("Device #"));
Serial.println(msgBankId);

msgBankAddr = MSG_BANK_SIZE * msgBankId;

readSpeedFromEEPROM();
readPauseFromEEPROM();
Expand All @@ -86,7 +85,8 @@ void setup() {
if (testMode) {
testRoutine();
}


showSettings();
if (transmitMode) {
Serial.println(F("Configured as master\n"));
showInstructions();
Expand Down
41 changes: 17 additions & 24 deletions morse/morse_xmit.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/**
* functions related to transmission only
*/


#include <string.h> //needed for memcpy
#include "morse.h"

Expand All @@ -24,28 +22,23 @@ byte line[LINE_SIZE];
int line_len;

void showInstructions() {
Serial.print(F("Dot duration: ")); Serial.print(t_dot); Serial.println(F(" ms"));
Serial.print(F("Pause duration: )")); Serial.print(t_pause); Serial.println(F(" ms"));
Serial.println();
Serial.println(F("Accepting input from serial console"));
Serial.println();
Serial.println(F("In-stream modifiers for text interpretation:"));
Serial.println(F(" _ Morse (default)"));
Serial.println(F(" $ Hexadecimal"));
Serial.println(F(" # Unary"));
Serial.println(F(" % Chess"));
Serial.println();
Serial.println(F("Timing commands:"));
Serial.println(F(" *s<dot>"));
Serial.println(F(" changes the dot duration (speed) to <dot> ms"));
Serial.println(F(" *p<pause>"));
Serial.println(F(" changes the inter-message pause to <pause> ms"));
Serial.println();
Serial.println(F("Manual control:"));
Serial.println(F(" ^0 Turns output off"));
Serial.println(F(" ^1 Turns output on"));
Serial.println(F(" ^ Resumes message output/Syncs message with master"));
Serial.println();
Serial.println(F("In-stream modifiers for text interpretation:"));
Serial.println(F(" _ Morse (default)"));
Serial.println(F(" $ Hexadecimal"));
Serial.println(F(" # Unary"));
Serial.println(F(" % Chess"));
Serial.println();
Serial.println(F("Timing commands:"));
Serial.println(F(" *s<dot>"));
Serial.println(F(" changes the dot duration (speed) to <dot> ms"));
Serial.println(F(" *p<pause>"));
Serial.println(F(" changes the inter-message pause to <pause> ms"));
Serial.println();
Serial.println(F("Manual control:"));
Serial.println(F(" ^0 Turns output off"));
Serial.println(F(" ^1 Turns output on"));
Serial.println(F(" ^ Resumes message output/Syncs message with master"));
Serial.println();
}

/*
Expand Down

0 comments on commit 2d45ca7

Please sign in to comment.