PicoLC Arduino Library
Arduino library for PicoLC hardware
Loading...
Searching...
No Matches
PicoLCClass.h
1#pragma once
2
3#include <Arduino.h>
4
5#include "PicoLCTypes.h"
6
7#include "PicoLCInput.h"
8#include "PicoLCOutput.h"
9#include "PicoLCLED.h"
10#include "PicoLCButton.h"
11#include "PicoLCPair.h"
12#include "PicoLCSerial.h"
13#include "PicoLCStorage.h"
14
15/**
16 * @brief Main interface to PicoLC hardware and shared runtime services.
17 *
18 * PicoLC owns the board inputs, outputs, output pairs, indicators, buttons,
19 * serial interface, and storage objects. It also provides the shared scan
20 * timestamp used throughout the API.
21 *
22 * Call begin() once during setup(), configure the required hardware objects,
23 * then call update() once at the beginning of each loop() iteration.
24 */
25class PicoLC {
26private:
27 uint32_t _currentMillis = 0;
28 uint32_t _cycles = 0;
29
30 PicoLC(const PicoLC&) = delete;
31 PicoLC& operator=(const PicoLC&) = delete;
32
33public:
34 /**
35 * @brief Constructs the PicoLC interface and its child hardware objects.
36 *
37 * Hardware initialization is deferred until begin() is called.
38 */
39 PicoLC();
40
41 /** Hardware outputs Y0 through Y3. */
42 PicoLCOutput Y0, Y1, Y2, Y3;
43
44 /** Hardware inputs X0 through X3. */
45 PicoLCInput X0, X1, X2, X3;
46
47 /** Paired-output controllers for Y0/Y1 and Y2/Y3. */
49
50 /** Board indicator LEDs. */
51 PicoLCLED StatusLED, CommLED, FaultLED;
52
53 /** Board-defined control buttons. */
54 PicoLCButton RunStopButton, UserButton, BootButton;
55
56 /** RS-485 serial interface. */
58
59 /** User-accessible nonvolatile storage. */
61
62 /**
63 * @brief Initializes PicoLC hardware and child objects.
64 *
65 * Call this once from setup() before configuring or using PicoLC inputs,
66 * outputs, LEDs, buttons, serial, storage, or output pairs.
67 *
68 * Physical outputs remain disabled until enableOutputs() is called.
69 */
70 void begin();
71
72 /**
73 * @brief Advances PicoLC by one application scan.
74 *
75 * update() captures the shared millisecond timestamp, increments the scan
76 * counter, samples and filters logical inputs and buttons, and advances
77 * timed LED and output behavior.
78 *
79 * Call this once at the beginning of each loop() iteration. Logical output
80 * commands issued after the call are applied during a subsequent update().
81 */
82 void update();
83
84 /**
85 * @brief Returns the timestamp captured for the current scan.
86 *
87 * The value changes only when update() is called and is shared by timed
88 * API components such as timers, input filters, pulses, and blink patterns.
89 *
90 * @return Current scan timestamp in milliseconds.
91 */
92 uint32_t currentMillis() const;
93
94 /**
95 * @brief Returns the number of completed update cycles.
96 *
97 * Cycle zero represents initialization. The first call to update()
98 * advances the counter to one.
99 *
100 * @return Current PicoLC scan count.
101 */
102 uint32_t cycles() const;
103
104 /**
105 * @brief Enables physical output-driver operation.
106 *
107 * Logical output states and indicator LEDs continue to operate regardless
108 * of this setting. Enabling outputs permits the configured logical output
109 * states to reach the physical output terminals.
110 */
111 void enableOutputs();
112
113 /**
114 * @brief Disables all physical output-driver channels.
115 *
116 * Logical output states are preserved, and the output indicator LEDs
117 * continue to show the states that would otherwise be applied to the
118 * hardware outputs.
119 */
120 void disableOutputs();
121
122 /**
123 * @brief Reports whether physical outputs are globally enabled.
124 *
125 * @return true when logical output states are permitted to drive the
126 * physical output terminals.
127 */
128 bool outputsEnabled() const;
129
130 /**
131 * @brief Reports the current output-driver fault indication.
132 *
133 * @return true when the hardware output driver reports a fault.
134 */
135 bool outputFault() const;
136
137 /**
138 * @brief Resets the hardware output driver.
139 *
140 * This operation resets the driver hardware without changing the logical
141 * output configuration or commanded states.
142 */
143 void resetOutputDriver();
144
145 /**
146 * @brief Measures the PicoLC supply voltage.
147 *
148 * The value is sampled directly from the board VIN sense circuit when this
149 * method is called and is independent of update().
150 *
151 * @return Measured supply voltage in volts.
152 */
153 float supplyVoltage() const;
154};
Represents one filtered, logical PicoLC button.
float supplyVoltage() const
Measures the PicoLC supply voltage.
Definition PicoLC.cpp:199
PicoLCOutput Y0
Hardware outputs Y0 through Y3.
Definition PicoLCClass.h:42
uint32_t cycles() const
Returns the number of completed update cycles.
Definition PicoLC.cpp:175
PicoLCStorage Storage
User-accessible nonvolatile storage.
Definition PicoLCClass.h:60
void resetOutputDriver()
Resets the hardware output driver.
Definition PicoLC.cpp:195
PicoLCInput X0
Hardware inputs X0 through X3.
Definition PicoLCClass.h:45
void update()
Advances PicoLC by one application scan.
Definition PicoLC.cpp:121
bool outputFault() const
Reports the current output-driver fault indication.
Definition PicoLC.cpp:191
PicoLCSerial Serial
RS-485 serial interface.
Definition PicoLCClass.h:57
void disableOutputs()
Disables all physical output-driver channels.
Definition PicoLC.cpp:183
PicoLCButton RunStopButton
Board-defined control buttons.
Definition PicoLCClass.h:54
uint32_t currentMillis() const
Returns the timestamp captured for the current scan.
Definition PicoLC.cpp:171
PicoLCLED StatusLED
Board indicator LEDs.
Definition PicoLCClass.h:51
void enableOutputs()
Enables physical output-driver operation.
Definition PicoLC.cpp:179
PicoLC()
Constructs the PicoLC interface and its child hardware objects.
Definition PicoLC.cpp:77
bool outputsEnabled() const
Reports whether physical outputs are globally enabled.
Definition PicoLC.cpp:187
void begin()
Initializes PicoLC hardware and child objects.
Definition PicoLC.cpp:85
PicoLCPair P0
Paired-output controllers for Y0/Y1 and Y2/Y3.
Definition PicoLCClass.h:48
Represents one filtered, logical PicoLC input.
Definition PicoLCInput.h:18
Represents one configurable PicoLC status LED.
Definition PicoLCLED.h:18
Represents one configurable PicoLC hardware output.
Provides Arduino Stream-compatible access to the PicoLC RS-485 port.