holiday-lights/morse.h

42 lines
837 B
C
Raw Permalink Normal View History

2020-11-28 20:23:35 -07:00
#pragma once
#include <stdint.h>
#define MORSE_DIT 1
#define MORSE_DAH 3
#define MORSE_PAUSE_LETTER 3
#define MORSE_PAUSE_WORD 6
#define MORSE_PAUSE_TRANSMISSION 50
2020-11-28 20:23:35 -07:00
class MorseEncoder {
public:
MorseEncoder();
MorseEncoder(const char *s);
/** SetText resets state with new text.
*/
void SetText(const char *s);
2020-12-05 10:43:22 -07:00
/** Tick tells the encoder that a dit has elapsed.
*
* Returns true if there's data left to transmit.
* If it returns false, you need to feed it more data.
*
* You should call this every time your dit duration ends.
*/
bool Tick();
/** Quiet stops transmitting for this many ticks.
*/
void Quiet(int ticks);
/** Transmitting is true if you should be transmitting right now.
*/
bool Transmitting;
2020-11-28 20:23:35 -07:00
private:
const char *p;
uint8_t bit;
2020-11-28 20:23:35 -07:00
int ticksLeft;
};