58 lines
No EOL
1.7 KiB
C++
58 lines
No EOL
1.7 KiB
C++
#include "pico/stdlib.h"
|
|
#include "tusb.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "winkeyer.h"
|
|
|
|
void WinKeyer::run(queue_t &queue)
|
|
{
|
|
const uint8_t USB_IF = 0;
|
|
|
|
if (tud_cdc_n_available(USB_IF)) {
|
|
uint8_t buf[64];
|
|
|
|
// printf("AHA!!! %d\n", (int)tud_cdc_n_available(USB_IF));
|
|
uint32_t count = tud_cdc_n_read(USB_IF, buf, sizeof(buf));
|
|
|
|
if (count > 0) {
|
|
switch (buf[0]) {
|
|
case 'a' ... 'z':
|
|
[[fallthrough]];
|
|
case 'A' ... 'Z':
|
|
[[fallthrough]];
|
|
case '0' ... '9':
|
|
[[fallthrough]];
|
|
case ' ':
|
|
[[fallthrough]];
|
|
case '+':
|
|
[[fallthrough]];
|
|
case '=':
|
|
[[fallthrough]];
|
|
case '?':
|
|
[[fallthrough]];
|
|
case ',':
|
|
[[fallthrough]];
|
|
case '.': {
|
|
KeyerQueueData keyerQueueData {KeyerQueueCommand::SendMessage, 0, Mode::IambicB, buf[0]};
|
|
queue_add_blocking(&queue, &keyerQueueData);
|
|
break;
|
|
}
|
|
case 0x00: // ADMIN COMMAND
|
|
switch (buf[1]) {
|
|
case 0x02: // HOST OPEN
|
|
usbSend(USB_IF, 9); // Send WK1 (v9) for now (no WinKeyer PTT control)
|
|
break;
|
|
case 0x04: // ECHO TEST
|
|
usbSend(USB_IF, &buf[2], 1); // Send the received byte back
|
|
break;
|
|
default:
|
|
printf("Unknown admin command: %x\n", buf[1]);
|
|
}
|
|
break;
|
|
default:
|
|
printf("Unknown command: %d.\n", buf[0]);
|
|
}
|
|
}
|
|
}
|
|
} |