[WIP] Send messages via USB

This commit is contained in:
Martin Brodbeck 2024-02-26 15:20:28 +01:00
parent 4163c9d70f
commit 701bf8f6b4
2 changed files with 40 additions and 20 deletions

View file

@ -93,6 +93,7 @@ void core1_main()
data.cmd = KeyerQueueCommand::Run;
break;
case KeyerQueueCommand::SendMessage:
printf("Sending: %s\n", data.message.c_str());
keyer.sendMessage(data.message);
data.cmd = KeyerQueueCommand::Run;
break;
@ -126,25 +127,42 @@ void cdc_task()
if (tud_cdc_n_available(USB_IF)) {
uint8_t buf[64];
// printf("AHA!!! %d\n", (int)tud_cdc_n_available(USB_IF));
//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':
printf("TODO: Send it!\n");
[[fallthrough]];
case ' ':
[[fallthrough]];
case '+':
[[fallthrough]];
case '=':
[[fallthrough]];
case '?':
[[fallthrough]];
case ',':
[[fallthrough]];
case '.':
{
printf("TODO: Send it: %c\n", buf[0]);
std::string msg(1, buf[0]);
KeyerQueueData keyerQueueData {KeyerQueueCommand::SendMessage, 0, Mode::IambicB, msg};
queue_add_blocking(&keyerQueue, &keyerQueueData);
break;
}
case 0x00: // ADMIN COMMAND
switch (buf[1]) {
case 0x02: // Host open
case 0x02: // HOST OPEN
usbSend(USB_IF, 9); // Send WK1 (v9) for now (no WinKeyer PTT control)
break;
case 0x04: // Echo test
printf("Echo test: %x\n", buf[2]);
printf("buf address: %p\n", &buf[2]);
usbSend(USB_IF, &buf[2], 1);
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]);
@ -209,9 +227,6 @@ int main()
static bool used = false;
while (true) {
tud_task();
cdc_task();
currentWpm = calcWPM(potiRead(), settings.wpmPotiMin, settings.wpmPotiMax);
// If WPM in settings is set to 0 -> take speed from poti
@ -228,6 +243,9 @@ int main()
// pse k"}; queue_add_blocking(&keyerQueue, &keyerQueueData);
used = true;
}
tud_task();
cdc_task();
}
return 0;