Toggle keying modes
This commit is contained in:
parent
27d300f227
commit
98183b14ec
1 changed files with 40 additions and 0 deletions
|
@ -1,6 +1,8 @@
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
#include "bsp/board.h"
|
#include "bsp/board.h"
|
||||||
#include "hardware/adc.h"
|
#include "hardware/adc.h"
|
||||||
#include "pico/binary_info/code.h"
|
#include "pico/binary_info/code.h"
|
||||||
|
@ -26,6 +28,7 @@ extern constexpr uint BUZZER_PIN = 18;
|
||||||
constexpr uint DISPLAY_DIO_PIN = 20;
|
constexpr uint DISPLAY_DIO_PIN = 20;
|
||||||
constexpr uint DISPLAY_CLK_PIN = 21;
|
constexpr uint DISPLAY_CLK_PIN = 21;
|
||||||
extern constexpr uint ADC_PIN = 26;
|
extern constexpr uint ADC_PIN = 26;
|
||||||
|
constexpr uint BUTTON_KEYER_MODE = 2;
|
||||||
|
|
||||||
queue_t keyerQueue;
|
queue_t keyerQueue;
|
||||||
|
|
||||||
|
@ -47,6 +50,11 @@ void setup()
|
||||||
gpio_set_dir(CW_OUT_PIN, GPIO_OUT);
|
gpio_set_dir(CW_OUT_PIN, GPIO_OUT);
|
||||||
gpio_put(CW_OUT_PIN, 0);
|
gpio_put(CW_OUT_PIN, 0);
|
||||||
|
|
||||||
|
// Setup Button Keyer Mode
|
||||||
|
gpio_init(BUTTON_KEYER_MODE);
|
||||||
|
gpio_set_dir(BUTTON_KEYER_MODE, GPIO_IN);
|
||||||
|
gpio_pull_down(BUTTON_KEYER_MODE);
|
||||||
|
|
||||||
// Setup ADC
|
// Setup ADC
|
||||||
adc_init();
|
adc_init();
|
||||||
gpio_init(ADC_PIN);
|
gpio_init(ADC_PIN);
|
||||||
|
@ -131,7 +139,12 @@ int main()
|
||||||
display.displayIambicMode(settings.mode);
|
display.displayIambicMode(settings.mode);
|
||||||
display.displaySpeed(currentWpm);
|
display.displaySpeed(currentWpm);
|
||||||
|
|
||||||
|
auto timestamp = get_absolute_time();
|
||||||
|
auto ignoreButtonKeyerModeUntil = timestamp;
|
||||||
|
uint count = static_cast<std::underlying_type<Mode>::type>(settings.mode); // TODO: Simplify with C++23
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
timestamp = get_absolute_time();
|
||||||
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
|
||||||
|
@ -143,6 +156,33 @@ int main()
|
||||||
display.displaySpeed(currentWpm);
|
display.displaySpeed(currentWpm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If Button for keying mode is pressed, toggle through the possible values (Iambic A, Iambic B, Straight)
|
||||||
|
if (absolute_time_diff_us(timestamp, ignoreButtonKeyerModeUntil) <= 0 && gpio_get(BUTTON_KEYER_MODE)) {
|
||||||
|
++count;
|
||||||
|
count = count % 3;
|
||||||
|
|
||||||
|
switch (count) {
|
||||||
|
case 0:
|
||||||
|
settings.mode = Mode::IambicA;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
settings.mode = Mode::IambicB;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
settings.mode = Mode::Straight;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
KeyerQueueData keyerQueueData {KeyerQueueCommand::Config, currentWpm, settings.mode, 0};
|
||||||
|
queue_add_blocking(&keyerQueue, &keyerQueueData);
|
||||||
|
|
||||||
|
display.displayIambicMode(settings.mode);
|
||||||
|
|
||||||
|
ignoreButtonKeyerModeUntil = make_timeout_time_us(500'000);
|
||||||
|
}
|
||||||
|
|
||||||
tud_task(); // Internal PICO purposes
|
tud_task(); // Internal PICO purposes
|
||||||
|
|
||||||
winKeyer.run(keyerQueue);
|
winKeyer.run(keyerQueue);
|
||||||
|
|
Loading…
Reference in a new issue