Sending chars via WKdemo
This commit is contained in:
parent
701bf8f6b4
commit
df85ca4267
4 changed files with 27 additions and 31 deletions
|
@ -50,7 +50,6 @@ void Keyer::setSpeed(uint8_t wpm)
|
||||||
|
|
||||||
void Keyer::sendMessage(std::string msg)
|
void Keyer::sendMessage(std::string msg)
|
||||||
{
|
{
|
||||||
printf("Queue size: %d\n", m_messageQueue.size());
|
|
||||||
std::string morse = messageToMorse(msg);
|
std::string morse = messageToMorse(msg);
|
||||||
|
|
||||||
for (char c : morse) {
|
for (char c : morse) {
|
||||||
|
@ -58,23 +57,31 @@ void Keyer::sendMessage(std::string msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Keyer::sendCharacter(char ch)
|
||||||
|
{
|
||||||
|
std::string morse = charToMorse(ch);
|
||||||
|
|
||||||
|
for (char c : morse) {
|
||||||
|
m_messageQueue.push(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Keyer::run()
|
void Keyer::run()
|
||||||
{
|
{
|
||||||
auto timestamp = get_absolute_time();
|
auto timestamp = get_absolute_time();
|
||||||
|
|
||||||
// If there is some message to send …
|
// If there is some message to send …
|
||||||
//if (!m_messageQueue.empty() || m_messageKeyingState != MessageState::Wait) {
|
if (!m_messageQueue.empty() || m_messageKeyingState != MessageState::Wait) {
|
||||||
if (!m_messageQueue.empty()) {
|
|
||||||
// Stop all paddle keying, if necessary
|
// Stop all paddle keying, if necessary
|
||||||
if (m_paddleKeyingState != State::Wait) {
|
if (m_paddleKeyingState != State::Wait) {
|
||||||
//gpio_put(LED_PIN, 0);
|
gpio_put(LED_PIN, 0);
|
||||||
//gpio_put(CW_OUT_PIN, 0);
|
gpio_put(CW_OUT_PIN, 0);
|
||||||
//m_buzzer.off();
|
m_buzzer.off();
|
||||||
//m_keyNextIambicB = false;
|
m_keyNextIambicB = false;
|
||||||
//m_currentlyPausing = false;
|
m_currentlyPausing = false;
|
||||||
//m_currentlyKeying = false;
|
m_currentlyKeying = false;
|
||||||
//m_previousState = State::Abort;
|
m_previousState = State::Abort;
|
||||||
//m_paddleKeyingState = State::Wait;
|
m_paddleKeyingState = State::Wait;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (m_messageKeyingState) {
|
switch (m_messageKeyingState) {
|
||||||
|
@ -167,7 +174,7 @@ void Keyer::run()
|
||||||
break;
|
break;
|
||||||
case MessageState::InterWordSpace:
|
case MessageState::InterWordSpace:
|
||||||
if (!m_currentlyPausing) {
|
if (!m_currentlyPausing) {
|
||||||
m_pausing_until = make_timeout_time_us(m_elementDuration * 7);
|
m_pausing_until = make_timeout_time_us(m_elementDuration * (7-3)); // 7-3, because we aleady have the InterCharSpace of 3
|
||||||
m_currentlyPausing = true;
|
m_currentlyPausing = true;
|
||||||
}
|
}
|
||||||
if (left_paddle_pressed() || right_paddle_pressed()) {
|
if (left_paddle_pressed() || right_paddle_pressed()) {
|
||||||
|
|
|
@ -15,6 +15,7 @@ class Keyer final
|
||||||
void setMode(Mode mode) { m_mode = mode; }
|
void setMode(Mode mode) { m_mode = mode; }
|
||||||
void setSpeed(uint8_t wpm);
|
void setSpeed(uint8_t wpm);
|
||||||
void sendMessage(std::string msg);
|
void sendMessage(std::string msg);
|
||||||
|
void sendCharacter(char ch);
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
void stop();
|
void stop();
|
||||||
|
|
|
@ -78,7 +78,7 @@ std::string messageToMorse(std::string &msg)
|
||||||
|
|
||||||
// Append word space if last char was not a blank
|
// Append word space if last char was not a blank
|
||||||
if (msg.back() != ' ') {
|
if (msg.back() != ' ') {
|
||||||
//morseString.push_back('w');
|
morseString.push_back('w');
|
||||||
}
|
}
|
||||||
|
|
||||||
return morseString;
|
return morseString;
|
||||||
|
@ -102,7 +102,7 @@ std::string charToMorse(char ch) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//morseString.push_back('c');
|
morseString.push_back('c');
|
||||||
|
|
||||||
return morseString;
|
return morseString;
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ struct KeyerQueueData {
|
||||||
KeyerQueueCommand cmd;
|
KeyerQueueCommand cmd;
|
||||||
uint8_t wpm;
|
uint8_t wpm;
|
||||||
Mode mode;
|
Mode mode;
|
||||||
std::string message;
|
char message;
|
||||||
};
|
};
|
||||||
|
|
||||||
queue_t keyerQueue;
|
queue_t keyerQueue;
|
||||||
|
@ -93,8 +93,7 @@ void core1_main()
|
||||||
data.cmd = KeyerQueueCommand::Run;
|
data.cmd = KeyerQueueCommand::Run;
|
||||||
break;
|
break;
|
||||||
case KeyerQueueCommand::SendMessage:
|
case KeyerQueueCommand::SendMessage:
|
||||||
printf("Sending: %s\n", data.message.c_str());
|
keyer.sendCharacter(data.message);
|
||||||
keyer.sendMessage(data.message);
|
|
||||||
data.cmd = KeyerQueueCommand::Run;
|
data.cmd = KeyerQueueCommand::Run;
|
||||||
break;
|
break;
|
||||||
case KeyerQueueCommand::Wait:
|
case KeyerQueueCommand::Wait:
|
||||||
|
@ -150,9 +149,7 @@ void cdc_task()
|
||||||
[[fallthrough]];
|
[[fallthrough]];
|
||||||
case '.':
|
case '.':
|
||||||
{
|
{
|
||||||
printf("TODO: Send it: %c\n", buf[0]);
|
KeyerQueueData keyerQueueData {KeyerQueueCommand::SendMessage, 0, Mode::IambicB, buf[0]};
|
||||||
std::string msg(1, buf[0]);
|
|
||||||
KeyerQueueData keyerQueueData {KeyerQueueCommand::SendMessage, 0, Mode::IambicB, msg};
|
|
||||||
queue_add_blocking(&keyerQueue, &keyerQueueData);
|
queue_add_blocking(&keyerQueue, &keyerQueueData);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -221,29 +218,20 @@ int main()
|
||||||
}
|
}
|
||||||
lastWpm = currentWpm;
|
lastWpm = currentWpm;
|
||||||
|
|
||||||
KeyerQueueData keyerQueueData {KeyerQueueCommand::Run, currentWpm, settings.mode, ""};
|
KeyerQueueData keyerQueueData {KeyerQueueCommand::Run, currentWpm, settings.mode, 0};
|
||||||
queue_add_blocking(&keyerQueue, &keyerQueueData);
|
queue_add_blocking(&keyerQueue, &keyerQueueData);
|
||||||
|
|
||||||
static bool used = false;
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
currentWpm = calcWPM(potiRead(), settings.wpmPotiMin, settings.wpmPotiMax);
|
currentWpm = calcWPM(potiRead(), settings.wpmPotiMin, settings.wpmPotiMax);
|
||||||
|
|
||||||
// If WPM in settings is set to 0 -> take speed from poti
|
// If WPM in settings is set to 0 -> take speed from poti
|
||||||
if (settings.wpm == 0 && (currentWpm != lastWpm)) {
|
if (settings.wpm == 0 && (currentWpm != lastWpm)) {
|
||||||
KeyerQueueData keyerQueueData {KeyerQueueCommand::Config, currentWpm, settings.mode, ""};
|
KeyerQueueData keyerQueueData {KeyerQueueCommand::Config, currentWpm, settings.mode, 0};
|
||||||
queue_add_blocking(&keyerQueue, &keyerQueueData);
|
queue_add_blocking(&keyerQueue, &keyerQueueData);
|
||||||
printf("WPM has changed to: %d\n", currentWpm);
|
printf("WPM has changed to: %d\n", currentWpm);
|
||||||
lastWpm = currentWpm;
|
lastWpm = currentWpm;
|
||||||
}
|
}
|
||||||
|
|
||||||
// busy_wait_ms(5000);
|
|
||||||
if (!used) {
|
|
||||||
// KeyerQueueData keyerQueueData {KeyerQueueCommand::SendMessage, 0, settings.mode, "cq cq de dg2smb dg2smb
|
|
||||||
// pse k"}; queue_add_blocking(&keyerQueue, &keyerQueueData);
|
|
||||||
used = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
tud_task();
|
tud_task();
|
||||||
cdc_task();
|
cdc_task();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue