37 static constexpr std::chrono::microseconds
halfPeriod(
const double freq)
39 using namespace std::chrono_literals;
40 return std::chrono::duration_cast<std::chrono::microseconds>(1s / (2 * freq));
46 explicit Clock(QGraphicsItem *parent =
nullptr);
51 bool isOn(
const int port = 0)
const override;
56 double delay()
const override;
63 void setOn()
override;
79 void resetClock(std::chrono::steady_clock::time_point globalTime);
81 void updateClock(std::chrono::steady_clock::time_point globalTime);
104 std::chrono::steady_clock::time_point m_startTime;
static constexpr double kDefaultFrequency
void save(QDataStream &stream, SerializationOptions options) const override
bool isOn(const int port=0) const override
Returns true if the clock output is currently logic-high.
void load(QDataStream &stream, SerializationContext &context) override
double delay() const override
void resetClock(std::chrono::steady_clock::time_point globalTime)
Resets the clock phase reference to globalTime.
void setOn() override
Drives all output ports logic-high.
void setOff() override
Drives all output ports logic-low.
void setFrequency(const double freq) override
Sets the clock output frequency to freq Hz.
QList< std::pair< int, QString > > appearanceStates() const override
void updateClock(std::chrono::steady_clock::time_point globalTime)
Advances the clock state based on elapsed time since globalTime.
double frequency() const override
Returns the clock frequency in Hz.
QString genericProperties() override
Returns a summary string of the clock's current frequency and delay settings.
Clock(QGraphicsItem *parent=nullptr)
Constructs the element with optional parent.
static constexpr std::chrono::microseconds halfPeriod(const double freq)
void setDelay(const double delay) override
Bundles all per-deserialization state so that load() overrides receive it through one explicit parame...
Options passed to GraphicElement::save() (and friends); the save-side counterpart of SerializationCon...