2016-06-19 17:10:52 +00:00
|
|
|
//
|
|
|
|
// Typer.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 19/06/2016.
|
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef Typer_hpp
|
|
|
|
#define Typer_hpp
|
|
|
|
|
|
|
|
#include <memory>
|
2016-11-05 18:47:09 +00:00
|
|
|
#include "KeyboardMachine.hpp"
|
2017-07-28 01:53:45 +00:00
|
|
|
#include "../ClockReceiver/ClockReceiver.hpp"
|
2016-06-19 17:10:52 +00:00
|
|
|
|
|
|
|
namespace Utility {
|
|
|
|
|
|
|
|
class Typer {
|
|
|
|
public:
|
2016-11-05 18:47:09 +00:00
|
|
|
class Delegate: public KeyboardMachine::Machine {
|
2016-06-19 17:10:52 +00:00
|
|
|
public:
|
2016-11-05 18:47:09 +00:00
|
|
|
virtual bool typer_set_next_character(Typer *typer, char character, int phase);
|
2016-11-05 19:28:03 +00:00
|
|
|
virtual void typer_reset(Typer *typer) = 0;
|
2016-11-05 18:47:09 +00:00
|
|
|
|
|
|
|
virtual uint16_t *sequence_for_character(Typer *typer, char character);
|
|
|
|
|
2017-07-22 01:18:51 +00:00
|
|
|
typedef uint16_t KeySequence[16];
|
|
|
|
uint16_t *table_lookup_sequence_for_character(KeySequence *sequences, size_t length, char character);
|
|
|
|
|
2016-11-05 18:47:09 +00:00
|
|
|
const uint16_t EndSequence = 0xffff;
|
2017-07-22 01:18:51 +00:00
|
|
|
const uint16_t NotMapped = 0xfffe;
|
2016-06-19 17:10:52 +00:00
|
|
|
};
|
|
|
|
|
2017-07-28 01:53:45 +00:00
|
|
|
Typer(const char *string, HalfCycles delay, HalfCycles frequency, Delegate *delegate);
|
2016-06-19 17:10:52 +00:00
|
|
|
~Typer();
|
2017-07-28 02:05:29 +00:00
|
|
|
void run_for(const HalfCycles duration);
|
2016-08-06 18:33:24 +00:00
|
|
|
bool type_next_character();
|
2016-06-19 17:10:52 +00:00
|
|
|
|
2016-11-05 18:47:09 +00:00
|
|
|
const char BeginString = 0x02; // i.e. ASCII start of text
|
|
|
|
const char EndString = 0x03; // i.e. ASCII end of text
|
|
|
|
|
2016-06-19 17:10:52 +00:00
|
|
|
private:
|
2016-12-03 15:55:50 +00:00
|
|
|
char *string_;
|
2017-07-28 01:53:45 +00:00
|
|
|
HalfCycles frequency_;
|
|
|
|
HalfCycles counter_;
|
2016-12-03 15:55:50 +00:00
|
|
|
int phase_;
|
|
|
|
Delegate *delegate_;
|
|
|
|
size_t string_pointer_;
|
2016-06-19 17:10:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class TypeRecipient: public Typer::Delegate {
|
|
|
|
public:
|
2017-03-26 18:34:47 +00:00
|
|
|
void set_typer_for_string(const char *string) {
|
2016-12-03 15:55:50 +00:00
|
|
|
typer_.reset(new Typer(string, get_typer_delay(), get_typer_frequency(), this));
|
2016-06-19 17:10:52 +00:00
|
|
|
}
|
|
|
|
|
2017-03-26 18:34:47 +00:00
|
|
|
void typer_reset(Typer *typer) {
|
2016-11-05 19:28:03 +00:00
|
|
|
clear_all_keys();
|
2016-11-05 18:47:09 +00:00
|
|
|
}
|
|
|
|
|
2016-06-19 17:10:52 +00:00
|
|
|
protected:
|
2017-07-28 01:53:45 +00:00
|
|
|
virtual HalfCycles get_typer_delay() { return HalfCycles(0); }
|
|
|
|
virtual HalfCycles get_typer_frequency() { return HalfCycles(0); }
|
2016-12-03 15:55:50 +00:00
|
|
|
std::unique_ptr<Typer> typer_;
|
2016-06-19 17:10:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* Typer_hpp */
|