more experiments

This commit is contained in:
Martin Brodbeck 2024-02-12 14:10:04 +01:00
parent 59c348a2e4
commit aa83764bce
4 changed files with 33 additions and 11 deletions

View file

@ -44,9 +44,21 @@ void Keyer::run()
switch (state)
{
case State::Wait:
if (left_paddle_pressed()) {
if (left_paddle_pressed() && right_paddle_pressed())
{
if (m_lastSymbolWas == Symbol::Dit) {
state = State::Dah;
} else if (m_lastSymbolWas == Symbol::Dah) {
state = State::Dit;
}
break;
}
if (left_paddle_pressed())
{
state = State::Dit;
} else if (right_paddle_pressed()) {
}
else if (right_paddle_pressed())
{
state = State::Dah;
}
break;
@ -56,6 +68,7 @@ void Keyer::run()
m_currentlyKeying = true;
m_keying_until = make_timeout_time_us(m_elementDuration);
gpio_put(LED_PIN, 1);
m_lastSymbolWas = Symbol::Dit;
}
else
{
@ -69,11 +82,15 @@ void Keyer::run()
}
break;
case State::Dah:
if(!m_currentlyKeying) {
if (!m_currentlyKeying)
{
m_currentlyKeying = true;
m_keying_until = make_timeout_time_us(m_elementDuration * 3);
gpio_put(LED_PIN, 1);
} else {
m_lastSymbolWas = Symbol::Dah;
}
else
{
if (absolute_time_diff_us(timestamp, m_keying_until) <= 0)
{
m_currentlyKeying = false;
@ -81,7 +98,6 @@ void Keyer::run()
m_previousState = State::Dah;
state = State::InterCharSpace;
}
}
break;
case State::InterCharSpace:
@ -91,7 +107,8 @@ void Keyer::run()
m_previousState = State::InterCharSpace;
}
if(absolute_time_diff_us(timestamp, m_pausing_until) <= 0) {
if (absolute_time_diff_us(timestamp, m_pausing_until) <= 0)
{
state = State::Wait;
}

View file

@ -17,15 +17,20 @@ public:
void run();
private:
Keyer() {};
enum class Symbol
{
Dit,
Dah
};
Keyer(){};
State state{State::Wait};
State m_previousState{State::Wait};
uint8_t m_wpm{18};
uint64_t m_elementDuration{0};
bool m_currentlyKeying {false};
bool m_currentlyKeying{false};
absolute_time_t m_keying_until{0};
absolute_time_t m_pausing_until{0};
Symbol m_lastSymbolWas{Symbol::Dit};
};
#endif

View file

@ -45,7 +45,7 @@ int main()
// printf("Element duration (u_sec): %" PRIu64 "\n", element_duration_us(settings.wpm));
printf("\n");
Keyer keyer(settings.wpm);
Keyer keyer(15);
while (true)
{

View file

@ -16,7 +16,7 @@ struct Settings
{
uint16_t magic_number{MAGIC_NUMBER}; // Bytes: 2
Mode mode{Mode::IAMBIC_B}; // Bytes: 1
uint8_t wpm{20}; // Bytes: 1
uint8_t wpm{18}; // Bytes: 1
uint8_t dummy[FLASH_PAGE_SIZE - 4]{0}; // Sum : 4
};