-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempt to get local keyer modes going
- Loading branch information
Showing
13 changed files
with
789 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CompileFlags: | ||
Add: | ||
- "--include-directory=/opt/arduino/hardware/arduino/avr/cores/arduino" | ||
- "--include-directory=/opt/arduino/hardware/arduino/avr/variants/standard" | ||
- "--include-directory=/opt/arduino/hardware/arduino/avr/libraries/HID/src" | ||
- "--include-directory=/opt/arduino/hardware/tools/avr/avr/include" | ||
- "--include-directory=/opt/arduino/libraries/Keyboard/src" | ||
- "--include-directory=/opt/arduino/libraries/HID/src" | ||
- "--include-directory=/home/dartcatcher/Arduino/libraries/MIDIUSB/src" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"clangd.arguments": [ | ||
"--enable-config" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#include <Arduino.h> | ||
#include <Keyboard.h> | ||
#include <MIDIUSB.h> | ||
#include <cstddef> | ||
#include "keyers.h" | ||
#include "adapter.h" | ||
#include "polybuzzer.h" | ||
|
||
#define MILLISECOND 1 | ||
#define SECOND (1000 * MILLISECOND) | ||
|
||
VailAdapter::VailAdapter(unsigned int PiezoPin) { | ||
this->buzzer = new PolyBuzzer(PiezoPin); | ||
this->txToneFrequency = 440; | ||
} | ||
|
||
// Send a MIDI Key Event | ||
void VailAdapter::midiKey(uint8_t key, bool down) { | ||
midiEventPacket_t event = {down?9:8, down?0x90:0x80, key, 0x7f}; | ||
MidiUSB.sendMIDI(event); | ||
MidiUSB.flush(); | ||
} | ||
|
||
// Send a keyboard key event | ||
void VailAdapter::keyboardKey(uint8_t key, bool down) { | ||
if (down) { | ||
Keyboard.press(key); | ||
} else { | ||
Keyboard.release(key); | ||
} | ||
} | ||
|
||
// Begin transmitting | ||
void VailAdapter::BeginTx() { | ||
this->buzzer->Tone(0, this->txToneFrequency); | ||
if (this->keyboardMode) { | ||
this->keyboardKey(KEY_LEFT_CTRL, true); | ||
} else { | ||
this->midiKey(0, true); | ||
} | ||
} | ||
|
||
// Stop transmitting | ||
void VailAdapter::EndTx() { | ||
this->buzzer->NoTone(0); | ||
if (this->keyboardMode) { | ||
this->keyboardKey(KEY_LEFT_CTRL, false); | ||
} else { | ||
this->midiKey(0, false); | ||
} | ||
} | ||
|
||
// Handle a paddle being pressed. | ||
// | ||
// The caller needs to debounce keys and deal with keys wired in parallel. | ||
void VailAdapter::HandlePaddle(Paddle paddle, bool pressed) { | ||
switch (paddle) { | ||
case PADDLE_STRAIGHT: | ||
if (pressed) { | ||
this->BeginTx(); | ||
} else { | ||
this->EndTx(); | ||
} | ||
return; | ||
case PADDLE_DIT: | ||
if (this->keyer) { | ||
this->keyer->Key(paddle, pressed); | ||
} else if (this->keyboardMode) { | ||
this->keyboardKey(KEY_LEFT_CTRL, pressed); | ||
} else { | ||
this->midiKey(1, pressed); | ||
} | ||
break; | ||
case PADDLE_DAH: | ||
if (this->keyer) { | ||
this->keyer->Key(paddle, pressed); | ||
} else if (this->keyboardMode) { | ||
this->keyboardKey(KEY_RIGHT_CTRL, pressed); | ||
} else { | ||
this->midiKey(2, pressed); | ||
} | ||
break; | ||
} | ||
} | ||
|
||
// Handle a MIDI event. | ||
// | ||
// We act as a MIDI | ||
void VailAdapter::HandleMIDI(midiEventPacket_t event) { | ||
uint16_t msg = (event.byte1 << 8) | (event.byte2 << 0); | ||
switch (event.byte1) { | ||
case 0xB0: // Controller Change | ||
switch (event.byte2) { | ||
case 0: // turn keyboard mode on/off | ||
this->keyboardMode = (event.byte3 > 0x3f); | ||
MidiUSB.sendMIDI(event); // Send it back to acknowledge | ||
break; | ||
case 1: // set dit duration (0-254) *2ms | ||
this->ditDuration = event.byte3 * 2 * MILLISECOND; | ||
break; | ||
} | ||
break; | ||
case 0xC0: // Program Change | ||
this->keyer = GetKeyerByNumber(event.byte2, this); | ||
break; | ||
case 0x80: // Note off | ||
this->buzzer->NoTone(1); | ||
break; | ||
case 0x90: // Note on | ||
this->buzzer->Note(1, event.byte2); | ||
break; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma once | ||
|
||
#include <MIDIUSB.h> | ||
#include "keyers.h" | ||
#include "polybuzzer.h" | ||
|
||
class VailAdapter: public Transmitter { | ||
private: | ||
unsigned int txToneFrequency; | ||
unsigned int ditDuration = 100; | ||
bool keyboardMode = false; | ||
Keyer *keyer = NULL; | ||
PolyBuzzer *buzzer = NULL; | ||
|
||
void midiKey(uint8_t key, bool down); | ||
void keyboardKey(uint8_t key, bool down); | ||
|
||
|
||
public: | ||
VailAdapter(unsigned int PiezoPin); | ||
void HandlePaddle(Paddle key, bool pressed); | ||
void HandleMIDI(midiEventPacket_t event); | ||
void BeginTx(); | ||
void EndTx(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Vail MIDI Protocol | ||
|
||
When it boots, | ||
the Vail adapter sends left and right Control keyboard key up and down events. | ||
It also shows up as a MIDI device. | ||
|
||
The Vail web site sends MIDI control commands to enable MIDI keyer mode, | ||
tells the keyer what sideband pitch to generate, | ||
and can set the keyer mode. | ||
|
||
|
||
## Controller 0 - MIDI Mode | ||
|
||
`b0 00 ff` will enable MIDI mode and disable Keyboard mode | ||
|
||
`b0 00 00` will enable Keyboard mode and disable MIDI mode | ||
|
||
|
||
## Controller 1 - dit length | ||
|
||
`b0 00 xx` will set the dit duration to `xx` times 2 milliseconds | ||
|
||
|
||
## Controller 2 - sidetone note | ||
|
||
`b0 00 xx` will play note `xx` as the sidetone note | ||
|
||
|
||
## Program Change | ||
|
||
`c0 xx` will change the keyer mode to `xx`. | ||
|
||
|
||
### Keyer Modes | ||
|
||
* 0: passthrough (sends C# and D for dit and dah) | ||
* 1: cootie / straight key | ||
* 2: bug | ||
* 3: electric bug | ||
* 4: single dot | ||
* 5: ultimatic | ||
* 6: plain iambic | ||
* 7: iambic a | ||
* 8: iambic b | ||
* 9: keyahead | ||
|
||
Any other mode will set to passthrough. | ||
|
||
|
||
## Notes (key down / key up) | ||
|
||
`90 00 xx` will begin playing note `xx` | ||
`80 00 xx` will end playing note `xx` | ||
|
||
These work just like a regular MIDI synthesizer. |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.