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"
|
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);
|
|
|
|
|
|
|
|
const uint16_t EndSequence = 0xffff;
|
2016-06-19 17:10:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Typer(const char *string, int delay, int frequency, Delegate *delegate);
|
|
|
|
~Typer();
|
|
|
|
void update(int 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_;
|
|
|
|
int frequency_;
|
|
|
|
int counter_;
|
|
|
|
int phase_;
|
|
|
|
Delegate *delegate_;
|
|
|
|
size_t string_pointer_;
|
2016-06-19 17:10:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class TypeRecipient: public Typer::Delegate {
|
|
|
|
public:
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-11-05 18:47:09 +00:00
|
|
|
void typer_reset(Typer *typer)
|
|
|
|
{
|
2016-11-05 19:28:03 +00:00
|
|
|
clear_all_keys();
|
2016-12-03 15:55:50 +00:00
|
|
|
typer_.reset();
|
2016-11-05 18:47:09 +00:00
|
|
|
}
|
|
|
|
|
2016-06-19 17:10:52 +00:00
|
|
|
protected:
|
2016-11-04 02:14:40 +00:00
|
|
|
virtual int get_typer_delay() { return 0; }
|
|
|
|
virtual int get_typer_frequency() { return 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 */
|