ScStwTimer class

The ScStwTimer class is used for advanced time measurement.

It does not work on its own though. It is recommended to use it in combination with the ScStwRace class.

When using standalone:

ScStwTimer timer;
// start the timer
timer.start();
// stop the timer
timer.stop();

The timer will now go into ScStw::WAITING state. That indicates that the timer has stopped and the final result has to be assigned by an external handler.

// assign result 'won'
timer.setResult(ScStwTimer::WON);

The timer is now in ScStwTimer::WON state.

// reset the timer
timer.reset();

The timer is not in ScStwTimer::IDLE state again.

Public types

enum TimerState { IDLE, STARTING, RUNNING, WAITING, WON, LOST, FAILING, WILDCARD, FAILED, CANCELLED, INCIDENT, DISABLED }
The TimerState enum contains all state the timer can be in.
enum ReadyState { IsReady = 0, NotInIdleState, IsDisabled, ExtensionIsNotConnected, ExtensionBatteryIsCritical, ClimberIsNotReady }
The ReadyStatus enum contains all possible reasons for a timer not to be ready (>0) and the case that it is ready (0)

Constructors, destructors, conversion operators

ScStwTimer(QString letter, QObject* parent = nullptr) explicit
ScStwTimer constructor.

Signals

void stateChanged(TimerState state)
Emitted when the state of the timer changed.
void reactionTimeChanged()
Emitted when the reaction time changed.
void wantsToBeDisabledChanged(ScStwTimer* timer, bool wantsToBeDisabled)
Emitted when the timer wants its state to be changed by the external handler.
void readyStateChanged(ReadyState readyState)
Emitted when the ready state of the timer changes.

Public slots

auto start() -> bool
Function to start the timer.
auto start(double timeOfStart) -> bool virtual
Function to start the timer at a given point in time (present or future)
auto cancel() -> bool
Function to cancel the timer.
auto stop() -> bool
Function to stop the timer.
auto stop(double timeOfStop) -> bool
Function to stop the timer at a given point in time (past or future)
auto setResult(TimerState) -> bool
Function to assing the result of the race to the timer.
auto reset() -> bool virtual
Function to reset the timer.
auto getState() -> TimerState
Function to get the current state of the timer.
auto getCurrentTime() -> double
Function to get the current time of the timer.
auto getReactionTime() -> double
Function to get the reaction time of the climber.
auto getText() -> QString
Function to get the text, a timer display is supposed to show.
auto getLetter() -> QString
Function to get the letter of the timer.
void setDisabled(bool disabled)
Function to set if the timer is supposed to be disabled.
auto getWantsToBeDisabled() -> bool
Function to check if the timer currently wants to be disabled.
auto getReadyState() -> ScStwTimer::ReadyState virtual
Function to get the current ready status of a timer.

Protected slots

void handleClimberStart(double timeOfStart)
slot to call when the climber has started
void setState(TimerState newState)
Function to change the state of the timer.
void setWantsToBeDisabled(bool wantsToBeDisabled)
Function to set whether the timer currently wants to be disabled.
void technicalIncident()
Function to set the timer into INCIDENT state immidieately.
auto wildcard() -> bool
Function to set the timer into WILDCARD state.

Protected variables

TimerState state
The current state of the timer.
double startTime
The time the timer was started at.
double stopTime
The time the timer was stopped at.
double reactionTime
the reaction time of the climber
QString letter
The letter (eg. "A" or "B") of the Timer (only one char)
bool wantsToBeDisabled
Defines if the timer currently wants to be disabled or not.

Enum documentation

enum ScStwTimer::TimerState

The TimerState enum contains all state the timer can be in.

Enumerators
IDLE

Timer is waiting to be started

STARTING

Timer is starting and will react with a false start if the climber starts

RUNNING

Timer is running

WAITING

Timer was stopped and is waiting to be set to either WON or LOST

WON

Timer has won

LOST

Timer has lost

FAILING

Timer encountered a false start and is waiting to be set to either FAILED or WILDCARD

WILDCARD

The opponent has done a false start

FAILED

A false start occured

CANCELLED

Timer was cancelled

INCIDENT

There was a technical incident (most likely a disconnected extension)

DISABLED

Timer is disabled

enum ScStwTimer::ReadyState

The ReadyStatus enum contains all possible reasons for a timer not to be ready (>0) and the case that it is ready (0)

Enumerators
IsReady

Timer is ready for start

NotInIdleState

Timer is not in IDLE state

IsDisabled

Timer is disabled

ExtensionIsNotConnected

Not all extension of the timer are conneted

ExtensionBatteryIsCritical

The battery level of one or more extension is critical or unknown

ClimberIsNotReady

The startpad of the timer is not triggered

Function documentation

ScStwTimer::ScStwTimer(QString letter, QObject* parent = nullptr) explicit

ScStwTimer constructor.

Parameters
letter the letter of the timer (only first char will be used!)
parent the parent object

void ScStwTimer::wantsToBeDisabledChanged(ScStwTimer* timer, bool wantsToBeDisabled) signal

Emitted when the timer wants its state to be changed by the external handler.

Parameters
timer the timer object
wantsToBeDisabled

void ScStwTimer::readyStateChanged(ReadyState readyState) signal

Emitted when the ready state of the timer changes.

Parameters
readyState the new ReadyState

bool ScStwTimer::start() public slot

Function to start the timer.

Returns false if the timer was not in the required state and therefore not started, true otherwise

To do this, the timer has to be in ScStwTimer::STARTING state!

bool ScStwTimer::start(double timeOfStart) virtual public slot

Function to start the timer at a given point in time (present or future)

Parameters
timeOfStart the point in time (msecs since epoch) when the timer is supposted to be started
Returns false if the timer was not in the required state and therefore not started, true otherwise

To do this, the timer has to be in ScStwTimer::STARTING state!

bool ScStwTimer::cancel() public slot

Function to cancel the timer.

Returns false if the timer was not in the required state and therefore not cancelled, true otherwise

To do this, the timer has to be in ScStwTimer::IDLE, ScStwTimer::STARTING or ScStwTimer::RUNNING state!

bool ScStwTimer::stop() public slot

Function to stop the timer.

Returns false if the timer was not in the required state and therefore not stopped, true otherwise

To do this, the timer has to be in ScStwTimer::RUNNING state!

bool ScStwTimer::stop(double timeOfStop) public slot

Function to stop the timer at a given point in time (past or future)

Parameters
timeOfStop the point in time (msecs since epoch) when the timer is supposted to be stopped
Returns false if the timer was not in the required state and therefore not stopped, true otherwise

To do this, the timer has to be in ScStwTimer::RUNNING state!

bool ScStwTimer::setResult(TimerState) public slot

Function to assing the result of the race to the timer.

Returns false if the timer was not in the required state and the result therefore not set, true otherwise

To do this, the timer has to be in ScStwTimer::WAITING state!

bool ScStwTimer::reset() virtual public slot

Function to reset the timer.

Returns false if the timer was not in the required state and therefore not reset, true otherwise

To do this, the timer has to be in ScStwTimer::WON or ScSTw::LOST state!

TimerState ScStwTimer::getState() public slot

Function to get the current state of the timer.

Returns current state of the timer

double ScStwTimer::getCurrentTime() public slot

Function to get the current time of the timer.

Returns The current / final time of the timer or -1 if it is not in the required state

To do this, the timer has to be in ScStwTimer::RUNNING, ScStwTimer::WAITING, ScStwTimer::WON or ScSTw::LOST state!

double ScStwTimer::getReactionTime() public slot

Function to get the reaction time of the climber.

Returns The climbers reaction time

QString ScStwTimer::getText() public slot

Function to get the text, a timer display is supposed to show.

Returns The text to show

QString ScStwTimer::getLetter() public slot

Function to get the letter of the timer.

Returns The letter of the timer or ""

void ScStwTimer::setDisabled(bool disabled) public slot

Function to set if the timer is supposed to be disabled.

Parameters
disabled if the timer is supposed to be diabled

!!! CAUTION use this function with care, it immidiately changes the state of the timer !!! It is recommended to only use this function to change the timers state after the ScStwTimer::requestTimerEnableChange() signal was called, during the race, the timer is used in, is in IDLE state.

bool ScStwTimer::getWantsToBeDisabled() public slot

Function to check if the timer currently wants to be disabled.

Returns true or false

ScStwTimer::ReadyState ScStwTimer::getReadyState() virtual public slot

Function to get the current ready status of a timer.

Returns The current ready status

void ScStwTimer::handleClimberStart(double timeOfStart) protected slot

slot to call when the climber has started

Parameters
timeOfStart time (msecs since epoch) when the climber started

void ScStwTimer::setState(TimerState newState) protected slot

Function to change the state of the timer.

Parameters
newState The new state

Doing this will emit the ScStwTimer::stateChanged() signal (only if the new state differs from the current one)

void ScStwTimer::setWantsToBeDisabled(bool wantsToBeDisabled) protected slot

Function to set whether the timer currently wants to be disabled.

Parameters
wantsToBeDisabled true or false

void ScStwTimer::technicalIncident() protected slot

Function to set the timer into INCIDENT state immidieately.

The current state of the timer will be ignored! It can only get out of this state by calling ScStwTimer::reset

bool ScStwTimer::wildcard() protected slot

Function to set the timer into WILDCARD state.

Returns false if not in STARTING state

Only works when the timer is in STARTING state.