raspikeyer/src/keyer.h

63 lines
1.2 KiB
C
Raw Normal View History

2024-02-16 21:05:25 +01:00
#pragma once
2024-02-09 12:20:30 +01:00
2024-02-23 09:18:02 +01:00
#include <queue>
2024-02-28 14:29:00 +01:00
//#include <string>
2024-02-23 09:18:02 +01:00
2024-02-13 09:00:39 +01:00
#include "settings.h"
2024-02-16 20:56:03 +01:00
#include "sidetone.h"
2024-02-12 15:57:50 +01:00
2024-02-09 12:20:30 +01:00
class Keyer final
{
2024-02-16 20:56:03 +01:00
public:
2024-02-14 11:05:33 +01:00
Keyer() = delete;
2024-02-13 09:00:39 +01:00
Keyer(uint8_t wpm, Mode mode);
2024-02-09 12:20:30 +01:00
2024-02-14 11:05:33 +01:00
void setMode(Mode mode) { m_mode = mode; }
void setSpeed(uint8_t wpm);
2024-02-28 14:29:00 +01:00
//void sendMessage(std::string msg);
void sendCharacter(const char ch);
2024-02-14 11:05:33 +01:00
2024-02-09 12:20:30 +01:00
void run();
2024-02-14 11:32:09 +01:00
void stop();
2024-02-09 12:20:30 +01:00
2024-02-16 20:56:03 +01:00
private:
enum class State {
2024-02-15 13:59:30 +01:00
Wait,
Dit,
Dah,
2024-02-16 09:46:46 +01:00
DitPause,
DahPause,
2024-02-15 13:59:30 +01:00
Abort,
};
2024-02-16 09:46:46 +01:00
2024-02-23 14:29:36 +01:00
enum class MessageState {
Wait,
Dit,
Dah,
IntraCharSpace,
InterCharSpace,
InterWordSpace,
Abort,
};
2024-02-19 12:10:42 +01:00
uint8_t m_wpm {18};
2024-02-20 15:24:51 +01:00
Mode m_mode {Mode::IambicB};
2024-02-16 09:46:46 +01:00
2024-02-19 12:10:42 +01:00
absolute_time_t m_keying_until {0};
absolute_time_t m_pausing_until {0};
2024-02-16 09:46:46 +01:00
2024-02-18 17:14:47 +01:00
Sidetone m_buzzer;
2024-02-23 09:18:02 +01:00
// Sidetone m_audioOut;
2024-02-16 09:46:46 +01:00
2024-02-23 14:45:42 +01:00
State m_paddleKeyingState {State::Wait};
2024-02-19 12:10:42 +01:00
State m_previousState {State::Wait};
2024-02-23 14:29:36 +01:00
std::queue<char> m_messageQueue;
MessageState m_messageKeyingState {MessageState::Wait};
2024-02-23 23:26:59 +01:00
char m_messageChar{};
2024-02-23 14:29:36 +01:00
2024-02-19 12:10:42 +01:00
uint64_t m_elementDuration {0};
bool m_currentlyKeying {false};
bool m_currentlyPausing {false};
bool m_keyNextIambicB {false};
2024-02-16 21:05:25 +01:00
};