PicoLC Arduino Library
Arduino library for PicoLC hardware
Toggle main menu visibility
Loading...
Searching...
No Matches
PicoLCTimer.h
1
#pragma once
2
3
#include <Arduino.h>
4
5
#include "PicoLCTypes.h"
6
7
class
PicoLC
;
8
9
/**
10
* @brief IEC-style timer using the shared PicoLC scan timebase.
11
*
12
* PicoLCTimer supports standard TON, TOF, and TP behavior. Timer state is
13
* evaluated using the timestamp captured at the start of the most recent
14
* PicoLC::update().
15
*
16
* A timer should normally be serviced once per PicoLC scan.
17
*/
18
class
PicoLCTimer
{
19
private
:
20
PicoLC
& _plc;
21
TimerMode _mode;
22
uint32_t _preset = 0;
23
uint32_t _started = 0;
24
bool
_running =
false
;
25
bool
_lastInput =
false
;
26
27
public
:
28
/**
29
* @brief Constructs a timer.
30
*
31
* @param plc PicoLC instance that provides the shared scan timebase.
32
* @param mode Standard timer operating mode.
33
* @param preset Initial timer preset in milliseconds.
34
*/
35
PicoLCTimer
(
PicoLC
& plc, TimerMode mode, uint32_t preset);
36
37
/**
38
* @brief Sets the timer preset.
39
*
40
* Changing the preset does not alter the accumulated timer value. The new
41
* preset is used by the next read(), write(), or update() call and may
42
* immediately change the timer output or running state.
43
*
44
* @param ms Timer preset in milliseconds.
45
*/
46
void
presetMillis
(uint32_t ms);
47
48
/**
49
* @brief Returns the configured timer preset.
50
*
51
* @return Timer preset in milliseconds.
52
*/
53
uint32_t
presetMillis
()
const
;
54
55
/**
56
* @brief Applies a timer input and returns the resulting output state.
57
*
58
* This is equivalent to calling write(input) followed by read().
59
*
60
* @param input Current logical timer input.
61
* @return Timer Q state.
62
*/
63
bool
update
(
bool
input);
64
65
/**
66
* @brief Returns the timer output state.
67
*
68
* The returned value represents the timer Q state evaluated against the
69
* timestamp captured at the start of the most recent PicoLC::update().
70
* The call may complete a time-dependent state transition that does not
71
* require a new input value.
72
*
73
* @return Current timer Q state.
74
*/
75
bool
read
();
76
77
/**
78
* @brief Applies the current logical input to the timer.
79
*
80
* The input is processed according to the configured standard TON, TOF,
81
* or TP behavior. This method should normally be called once per PicoLC
82
* scan.
83
*
84
* @param input Current logical timer input.
85
*/
86
void
write
(
bool
input);
87
88
/**
89
* @brief Reports whether the timer is currently accumulating time.
90
*
91
* This is independent of the current input and output states.
92
*
93
* @return true while the timer is accumulating elapsed time.
94
*/
95
bool
running
()
const
;
96
97
/**
98
* @brief Returns the accumulated timer value.
99
*
100
* @return Elapsed timer value in milliseconds.
101
*/
102
uint32_t
elapsed
()
const
;
103
104
/**
105
* @brief Returns the time remaining before the preset is reached.
106
*
107
* @return Remaining timer value in milliseconds.
108
*/
109
uint32_t
remaining
()
const
;
110
111
/**
112
* @brief Stops and clears the current timer operation.
113
*
114
* After reset(), a subsequent read() returns the same output state as a
115
* timer of the configured mode that has never been started.
116
*/
117
void
reset
();
118
};
PicoLC
Main interface to PicoLC hardware and shared runtime services.
Definition
PicoLCClass.h:25
PicoLCTimer::PicoLCTimer
PicoLCTimer(PicoLC &plc, TimerMode mode, uint32_t preset)
Constructs a timer.
Definition
PicoLCTimer.cpp:5
PicoLCTimer::read
bool read()
Returns the timer output state.
Definition
PicoLCTimer.cpp:19
PicoLCTimer::presetMillis
uint32_t presetMillis() const
Returns the configured timer preset.
Definition
PicoLCTimer.cpp:15
PicoLCTimer::update
bool update(bool input)
Applies a timer input and returns the resulting output state.
Definition
PicoLCTimer.cpp:91
PicoLCTimer::reset
void reset()
Stops and clears the current timer operation.
Definition
PicoLCTimer.cpp:118
PicoLCTimer::running
bool running() const
Reports whether the timer is currently accumulating time.
Definition
PicoLCTimer.cpp:96
PicoLCTimer::remaining
uint32_t remaining() const
Returns the time remaining before the preset is reached.
Definition
PicoLCTimer.cpp:107
PicoLCTimer::write
void write(bool input)
Applies the current logical input to the timer.
Definition
PicoLCTimer.cpp:49
PicoLCTimer::elapsed
uint32_t elapsed() const
Returns the accumulated timer value.
Definition
PicoLCTimer.cpp:100
src
PicoLCTimer.h
Generated by
1.17.0