raspikeyer/src/keyer.cpp

59 lines
1 KiB
C++
Raw Normal View History

2024-02-10 23:51:55 +01:00
#include <stdio.h>
#include "pico/stdlib.h"
2024-02-09 12:20:30 +01:00
#include "keyer.h"
2024-02-10 23:51:55 +01:00
extern const uint LEFT_PADDLE_PIN;
bool left_paddle_pressed()
{
2024-02-11 15:45:12 +01:00
if (!gpio_get(LEFT_PADDLE_PIN))
2024-02-10 23:51:55 +01:00
{
return true;
}
return false;
}
2024-02-09 12:20:30 +01:00
void Keyer::run()
{
switch (state)
{
2024-02-10 23:51:55 +01:00
case State::Wait:
if (left_paddle_pressed())
2024-02-11 16:26:55 +01:00
state = State::Dit;
2024-02-10 23:51:55 +01:00
break;
2024-02-11 16:26:55 +01:00
case State::Dit:
2024-02-10 23:51:55 +01:00
printf(".");
2024-02-11 15:45:12 +01:00
if (left_paddle_pressed())
state = State::InterCharSpace;
else
state = State::Wait;
break;
2024-02-11 16:26:55 +01:00
case State::Dah:
printf("-");
++numElements;
if (numElements == 3)
{
numElements = 0;
if (left_paddle_pressed())
state = State::InterCharSpace;
else
state = State::Wait;
}
break;
2024-02-11 15:45:12 +01:00
case State::InterCharSpace:
printf("(.)");
if (left_paddle_pressed())
2024-02-11 16:26:55 +01:00
state = State::Dit;
2024-02-11 15:45:12 +01:00
else
state = State::Wait;
2024-02-09 12:20:30 +01:00
break;
default:
break;
}
}