raspikeyer/src/keyer.h

63 lines
No EOL
1.2 KiB
C++

#pragma once
#include <queue>
#include <string>
#include "settings.h"
#include "sidetone.h"
class Keyer final
{
public:
Keyer() = delete;
Keyer(uint8_t wpm, Mode mode);
void setMode(Mode mode) { m_mode = mode; }
void setSpeed(uint8_t wpm);
void sendMessage(std::string msg);
void sendCharacter(char ch);
void run();
void stop();
private:
enum class State {
Wait,
Dit,
Dah,
DitPause,
DahPause,
Abort,
};
enum class MessageState {
Wait,
Dit,
Dah,
IntraCharSpace,
InterCharSpace,
InterWordSpace,
Abort,
};
uint8_t m_wpm {18};
Mode m_mode {Mode::IambicB};
absolute_time_t m_keying_until {0};
absolute_time_t m_pausing_until {0};
Sidetone m_buzzer;
// Sidetone m_audioOut;
State m_paddleKeyingState {State::Wait};
State m_previousState {State::Wait};
std::queue<char> m_messageQueue;
MessageState m_messageKeyingState {MessageState::Wait};
char m_messageChar{};
uint64_t m_elementDuration {0};
bool m_currentlyKeying {false};
bool m_currentlyPausing {false};
bool m_keyNextIambicB {false};
};