Alpha 01
This commit is contained in:
107
src/main.cpp
Normal file
107
src/main.cpp
Normal file
@@ -0,0 +1,107 @@
|
||||
// Copyright 2025 Elizabeth Cray
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <EEPROM.h>
|
||||
|
||||
/* TODO:
|
||||
* - Implement sending strings
|
||||
* - Add OLED Support
|
||||
* - Add Potentiometer support
|
||||
*/
|
||||
|
||||
uint8_t input_dit = 3, input_dah = 6;
|
||||
uint8_t output = 7;
|
||||
uint16_t dit = 200, dah = 500;
|
||||
String serial_buffer = "";
|
||||
char buf;
|
||||
|
||||
void set_length(uint16_t, uint16_t);
|
||||
void send(bool);
|
||||
void process_input(String);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
pinMode(input_dit, INPUT_PULLUP);
|
||||
pinMode(input_dah, INPUT_PULLUP);
|
||||
pinMode(output, OUTPUT);
|
||||
digitalWrite(output, HIGH);
|
||||
|
||||
// dumbass
|
||||
pinMode(9, OUTPUT);
|
||||
digitalWrite(9, LOW);
|
||||
|
||||
dit = EEPROM.read(20);
|
||||
dah = EEPROM.read(21);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
if (digitalRead(input_dah)){
|
||||
send(true);
|
||||
}else if (digitalRead(input_dit)){
|
||||
send(false);
|
||||
}
|
||||
|
||||
|
||||
if (Serial.available() > 0) {
|
||||
buf = Serial.read();
|
||||
if ((uint16_t) buf == 13){
|
||||
process_input(serial_buffer);
|
||||
serial_buffer = "";
|
||||
} else {
|
||||
serial_buffer += buf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void process_input(String input){
|
||||
// Commands:
|
||||
// S<string> send string as CW, unavail chars become " "
|
||||
// I<int> set did length (ms)
|
||||
// A<Int> set dah length (ms)
|
||||
char command = input[0];
|
||||
input.remove(0);
|
||||
uint16_t length = 0;
|
||||
switch(command){
|
||||
case 'S':
|
||||
// TODO
|
||||
break;
|
||||
case 'I':
|
||||
length = input.toInt();
|
||||
set_length(length, dah);
|
||||
break;
|
||||
case 'A':
|
||||
length = input.toInt();
|
||||
set_length(dit, length);
|
||||
break;
|
||||
default:
|
||||
Serial.println('?');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void send(bool b) {
|
||||
digitalWrite(output, LOW);
|
||||
delay(b?dit:dah);
|
||||
digitalWrite(output, HIGH);
|
||||
}
|
||||
|
||||
void set_length(uint16_t length_dit, uint16_t length_dah) {
|
||||
dit = length_dit;
|
||||
dah = length_dah;
|
||||
EEPROM.write(20, length_dit);
|
||||
EEPROM.write(21, length_dah);
|
||||
return;
|
||||
}
|
Reference in New Issue
Block a user