more experiments
This commit is contained in:
parent
59c348a2e4
commit
aa83764bce
4 changed files with 33 additions and 11 deletions
|
@ -44,9 +44,21 @@ void Keyer::run()
|
||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
case State::Wait:
|
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;
|
state = State::Dit;
|
||||||
} else if (right_paddle_pressed()) {
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (left_paddle_pressed())
|
||||||
|
{
|
||||||
|
state = State::Dit;
|
||||||
|
}
|
||||||
|
else if (right_paddle_pressed())
|
||||||
|
{
|
||||||
state = State::Dah;
|
state = State::Dah;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -56,6 +68,7 @@ void Keyer::run()
|
||||||
m_currentlyKeying = true;
|
m_currentlyKeying = true;
|
||||||
m_keying_until = make_timeout_time_us(m_elementDuration);
|
m_keying_until = make_timeout_time_us(m_elementDuration);
|
||||||
gpio_put(LED_PIN, 1);
|
gpio_put(LED_PIN, 1);
|
||||||
|
m_lastSymbolWas = Symbol::Dit;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -69,11 +82,15 @@ void Keyer::run()
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case State::Dah:
|
case State::Dah:
|
||||||
if(!m_currentlyKeying) {
|
if (!m_currentlyKeying)
|
||||||
|
{
|
||||||
m_currentlyKeying = true;
|
m_currentlyKeying = true;
|
||||||
m_keying_until = make_timeout_time_us(m_elementDuration * 3);
|
m_keying_until = make_timeout_time_us(m_elementDuration * 3);
|
||||||
gpio_put(LED_PIN, 1);
|
gpio_put(LED_PIN, 1);
|
||||||
} else {
|
m_lastSymbolWas = Symbol::Dah;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if (absolute_time_diff_us(timestamp, m_keying_until) <= 0)
|
if (absolute_time_diff_us(timestamp, m_keying_until) <= 0)
|
||||||
{
|
{
|
||||||
m_currentlyKeying = false;
|
m_currentlyKeying = false;
|
||||||
|
@ -81,7 +98,6 @@ void Keyer::run()
|
||||||
m_previousState = State::Dah;
|
m_previousState = State::Dah;
|
||||||
state = State::InterCharSpace;
|
state = State::InterCharSpace;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case State::InterCharSpace:
|
case State::InterCharSpace:
|
||||||
|
@ -91,7 +107,8 @@ void Keyer::run()
|
||||||
m_previousState = State::InterCharSpace;
|
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;
|
state = State::Wait;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,11 @@ public:
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
enum class Symbol
|
||||||
|
{
|
||||||
|
Dit,
|
||||||
|
Dah
|
||||||
|
};
|
||||||
Keyer(){};
|
Keyer(){};
|
||||||
State state{State::Wait};
|
State state{State::Wait};
|
||||||
State m_previousState{State::Wait};
|
State m_previousState{State::Wait};
|
||||||
|
@ -25,7 +30,7 @@ private:
|
||||||
bool m_currentlyKeying{false};
|
bool m_currentlyKeying{false};
|
||||||
absolute_time_t m_keying_until{0};
|
absolute_time_t m_keying_until{0};
|
||||||
absolute_time_t m_pausing_until{0};
|
absolute_time_t m_pausing_until{0};
|
||||||
|
Symbol m_lastSymbolWas{Symbol::Dit};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -45,7 +45,7 @@ int main()
|
||||||
// printf("Element duration (u_sec): %" PRIu64 "\n", element_duration_us(settings.wpm));
|
// printf("Element duration (u_sec): %" PRIu64 "\n", element_duration_us(settings.wpm));
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
Keyer keyer(settings.wpm);
|
Keyer keyer(15);
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,7 +16,7 @@ struct Settings
|
||||||
{
|
{
|
||||||
uint16_t magic_number{MAGIC_NUMBER}; // Bytes: 2
|
uint16_t magic_number{MAGIC_NUMBER}; // Bytes: 2
|
||||||
Mode mode{Mode::IAMBIC_B}; // Bytes: 1
|
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
|
uint8_t dummy[FLASH_PAGE_SIZE - 4]{0}; // Sum : 4
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue