Home Reference Source
import MorseKeyer from 'morse-pro/src/morse-pro-keyer.js'
public class | source

MorseKeyer

Direct Subclass:

MorseIambicKeyer

The Morse keyer tests for input on a timer, plays the appropriate tone and passes the data to a decoder.

Example:

var ditKey = 90;  // Z
var dahKey = 88;  // X
window.onkeyup = function(e) {
    if (e.keyCode === ditKey) { dit = false; }
    if (e.keyCode === dahKey) { dah = false; }
};
window.onkeydown = function(e) {
    var wasMiddle = !dit & !dah;
    if (e.keyCode === ditKey) { dit = true; }
    if (e.keyCode === dahKey) { dah = true; }
    if (wasMiddle & (dit | dah)) { keyer.start(); }
};
var keyCallback = function() {
    return ((dit === true) * 1) + ((dah === true) * 2);
};
var messageCallback = function(d) {
    console.log(d.message);
};
keyer = new MorseKeyer(keyCallback, 20, 20, 550, messageCallback);

Constructor Summary

Public Constructor
public

constructor(keyCallback: function(): number, wpm: number, fwpm: number, frequency: number, messageCallback: function())

Member Summary

Public Members
public

decoder: *

public

ditLen: *

public

fditLen: *

public

fwpm: *

public
public

player: *

public

timer: *

public

wpm: *

Private Members
private

_state: {"playing": *}

Method Summary

Public Methods
public

start()

Call this method when an initial key-press (or equivalent) is detected.

public

stop()

This method can be called externally to stop the keyer but is also used internally when no key-press is detected.

Private Methods
private

_check()

@access: private

private

_ditOrDah(input: *): *

Translate key input into whether to play nothing, dit, or dah

private

_playTone(duration: number)

Play a dit or dah sidetone.

Public Constructors

public constructor(keyCallback: function(): number, wpm: number, fwpm: number, frequency: number, messageCallback: function()) source

Params:

NameTypeAttributeDescription
keyCallback function(): number

A function which should return 0, 1, 2, or 3 from the vitual "paddle" depending if nothing, a dit, a dah or both is detected. This implementation will play dits if both keys are detected.

wpm number
  • optional
  • default: 20

Speed of the keyer.

fwpm number
  • optional
  • default: wpm

Farnsworth speed of the keyer.

frequency number
  • optional
  • default: 550

The frequency in Hz for the sidetone.

messageCallback function()

A function called with {message: string, timings: number[], morse: string} for each decoded part (see MorseDecoder). Its use here will result in a single character being returned each time.

Public Members

public decoder: * source

public ditLen: * source

public fditLen: * source

public fwpm: * source

public keyCallback: * source

public player: * source

public timer: * source

public wpm: * source

Private Members

private _state: {"playing": *} source

Public Methods

public start() source

Call this method when an initial key-press (or equivalent) is detected.

public stop() source

This method can be called externally to stop the keyer but is also used internally when no key-press is detected.

Private Methods

private _check() source

@access: private

private _ditOrDah(input: *): * source

Translate key input into whether to play nothing, dit, or dah

Params:

NameTypeAttributeDescription
input *

Return:

*

undefined, true or false for nothing, dit or dah @access: private

private _playTone(duration: number) source

Play a dit or dah sidetone.

Params:

NameTypeAttributeDescription
duration number

number of milliseconds to play @access: private