Compare commits

..

5 Commits

Author SHA1 Message Date
Elizabeth Cray
3926833963 better serial 2025-01-19 16:54:25 -05:00
Elizabeth Cray
f0ea6b2707 fix commands and add encoding 2025-01-19 16:45:29 -05:00
e10e6eddbf End-Of-Session: WIP commands, invert input logic cause pullups 2025-01-19 01:01:31 -05:00
9aa1838a26 Add potentiometer control and debug messages 2025-01-19 00:31:51 -05:00
dbc07c7a0f Fix expected bootloader 2025-01-19 00:31:32 -05:00
5 changed files with 217 additions and 19 deletions

View File

@@ -1,3 +1,16 @@
# Eck Eck # Eck Eck
![EckEckEckEck.gif](https://media-be.chewy.com/wp-content/uploads/2023/05/05165809/cat-chattering-chirping-at-birds.gif) ![EckEckEckEck.gif](https://media-be.chewy.com/wp-content/uploads/2023/05/05165809/cat-chattering-chirping-at-birds.gif)
### Current WIP issue:
command issue:
```
.........................................................SR D
...........SR 1
..............................SR
Processing input: D1
Command: D -
```

View File

@@ -10,5 +10,6 @@
[env:nanoatmega328new] [env:nanoatmega328new]
platform = atmelavr platform = atmelavr
board = nanoatmega328new board = nanoatmega328
framework = arduino framework = arduino
monitor_speed = 115200

37
src/cw.cpp Normal file
View File

@@ -0,0 +1,37 @@
#include <Arduino.h>
#include <ctype.h>
uint8_t convertASCII(char c){
uint8_t result;
if(isalpha(c)){
if(islower(c)){
result = (uint8_t)c - 97;
}else{
result = (uint8_t)c - 65;
}
} else if (isdigit(c)){
result = (uint8_t)c - 22;
} else {
switch (c) {
case '-':
result = 36;
break;
case '.':
result = 36;
break;
case ',':
result = 36;
break;
case '?':
result = 36;
break;
case '/' || '\\':
result = 36;
break;
default:
result = 41;
break;
}
}
return result;
}

55
src/cw.h Normal file
View File

@@ -0,0 +1,55 @@
#ifndef CW_H
#define CW_H
#include <Arduino.h>
#include <ctype.h>
// Morse code representation for each character (A-Z, 0-9)
const char* morseCode[42] = {
".-", // A
"-...", // B
"-.-.", // C
"-..", // D
".", // E
"..-.", // F
"--.", // G
"....", // H
"..", // I
".---", // J
"-.-", // K
".-..", // L
"--", // M
"-.", // N
"---", // O
".--.", // P
"--.-", // Q
".-.", // R
"...", // S
"-", // T
"..-", // U
"...-", // V
".--", // W
"-..-", // X
"-.--", // Y
"--..", // Z
"-----", // 0
".----", // 1
"..---", // 2
"...--", // 3
"....-", // 4
".....", // 5
"-....", // 6
"--...", // 7
"---..", // 8
"----.", // 9
"-...-", // -
".-.-.-", // .
"--..--", // ,
"..--..", // ?
"-..-.", // /
".-.-.", // End Of Message (41)
};
uint8_t convertASCII(char c);
const char* allowedCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-.,?/\\";
#endif // CW_H

View File

@@ -14,56 +14,90 @@
#include <Arduino.h> #include <Arduino.h>
#include <EEPROM.h> #include <EEPROM.h>
#include <ctype.h>
#include "cw.h"
/* TODO: /* TODO:
* - Implement sending strings * - Implement sending strings
* - Add OLED Support * - Add OLED Support
* - Add Potentiometer support
*/ */
uint8_t input_dit = 3, input_dah = 6; boolean debug = true;
uint8_t input_dit = 3, input_dah = 6, input_pot = A6;
uint8_t output = 7; uint8_t output = 7;
uint16_t dit = 200, dah = 500; uint16_t dit = 200, dah = 500;
uint8_t debounce = 50;
uint16_t p_tol = 30, p_min = 50, p_max = 2000, p_buf = 0, p_cache = 0;
String serial_buffer = ""; String serial_buffer = "";
char buf; char buf;
void key_string(String);
void adjust_length(uint16_t);
void set_length(uint16_t, uint16_t); void set_length(uint16_t, uint16_t);
void send(bool); void send(bool);
void process_input(String); void process_input(String);
void log(String);
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
log("Set PinModes\n");
pinMode(input_dit, INPUT_PULLUP); pinMode(input_dit, INPUT_PULLUP);
pinMode(input_dah, INPUT_PULLUP); pinMode(input_dah, INPUT_PULLUP);
pinMode(input_pot, INPUT);
pinMode(output, OUTPUT); pinMode(output, OUTPUT);
digitalWrite(output, HIGH); digitalWrite(output, LOW);
log("Read EEPROM\n");
// dumbass
pinMode(9, OUTPUT);
digitalWrite(9, LOW);
dit = EEPROM.read(20); dit = EEPROM.read(20);
dah = EEPROM.read(21); dah = EEPROM.read(21);
debug = EEPROM.read(22);
p_buf = analogRead(input_pot);
// adjust_length(p_buf);
log("Setup complete\n");
log("Dit length: ");
log(String(dit));
log("\n");
log("Dah length: ");
log(String(dah));
log("\n");
log("Potentiometer: ");
log(String(p_buf));
log("\n");
} }
void loop() { void loop() {
if (!digitalRead(input_dah)){
if (digitalRead(input_dah)){
send(true); send(true);
}else if (digitalRead(input_dit)){ }else if (!digitalRead(input_dit)){
send(false); send(false);
} }
p_cache = analogRead(input_pot);
if (abs(p_cache - p_buf) > p_tol){
p_buf = p_cache;
if (p_cache < p_min){
p_cache = p_min;
} else if (p_cache > p_max){
p_cache = p_max;
}
adjust_length(p_cache);
}
if (Serial.available() > 0) { if (Serial.available() > 0) {
buf = Serial.read(); buf = Serial.read();
if ((uint16_t) buf == 13){ if ((uint16_t) buf == 13){
process_input(serial_buffer); process_input(serial_buffer);
serial_buffer = ""; serial_buffer = "";
} else { } else if ((uint8_t) buf > 27 ){
serial_buffer += buf; serial_buffer += buf;
} }
} }
delay(debounce);
}
void adjust_length(uint16_t adjusted_length){
uint16_t new_dah = map(adjusted_length, 20, 1000, p_min, p_max);
set_length(new_dah/2, new_dah);
} }
void process_input(String input){ void process_input(String input){
@@ -71,12 +105,25 @@ void process_input(String input){
// S<string> send string as CW, unavail chars become " " // S<string> send string as CW, unavail chars become " "
// I<int> set did length (ms) // I<int> set did length (ms)
// A<Int> set dah length (ms) // A<Int> set dah length (ms)
// D<0/1> set debug mode
log("Processing input: ");
log(input);
log("\n");
char command = input[0]; char command = input[0];
input.remove(0); input.remove(0,1);
log("Command: ");
log(String(command));
log(" - ");
log(input);
log("\n");
uint16_t length = 0; uint16_t length = 0;
if (islower(command)){
command = toupper(command);
}
switch(command){ switch(command){
case 'S': case 'S':
// TODO key_string(input);
break; break;
case 'I': case 'I':
length = input.toInt(); length = input.toInt();
@@ -86,22 +133,67 @@ void process_input(String input){
length = input.toInt(); length = input.toInt();
set_length(dit, length); set_length(dit, length);
break; break;
case 'D':
debug = boolean(input.toInt()==1);
log("Debug mode enabled");
EEPROM.write(22, debug);
break;
default: default:
Serial.println('?'); Serial.println('?');
break; break;
} }
} }
void key_string(String input){
// log("Sending string: ");
// log(input);
// log("\n");
uint8_t b = 0;
for (uint8_t i = 0; i < input.length(); i++){
char c = input[i];
if ((uint8_t)c != 32){
b = convertASCII(c);
for(uint8_t y = 0; y < strlen(morseCode[b]); y++){
send(morseCode[b][y] == '.');
delay(dit);
}
if(debug){
Serial.print(' ');
}
delay(dit);
} else {
if (debug){
Serial.println("");
}
delay(dah);
}
}
}
void send(bool b) { void send(bool b) {
digitalWrite(output, LOW); if (debug){
delay(b?dit:dah); Serial.print(b?"+":"=");
}
digitalWrite(output, HIGH); digitalWrite(output, HIGH);
delay(b?dit:dah);
digitalWrite(output, LOW);
} }
void set_length(uint16_t length_dit, uint16_t length_dah) { void set_length(uint16_t length_dit, uint16_t length_dah) {
log("Setting dit length to ");
log(String(length_dit));
log(" and dah length to ");
log(String(length_dah));
log("\n");
dit = length_dit; dit = length_dit;
dah = length_dah; dah = length_dah;
EEPROM.write(20, length_dit); EEPROM.write(20, length_dit);
EEPROM.write(21, length_dah); EEPROM.write(21, length_dah);
return; return;
} }
void log(String content){
if (debug){
Serial.print(content);
}
}