ReduxLib C++ 2026.1.2
Loading...
Searching...
No Matches
DigoutSlotState.h
1// Copyright (c) Bagholders of Redux Robotics and other contributors.
2// This is open source and can be modified and shared under the Mozilla Public License v2.0.
3
4#pragma once
5#include <cstdint>
6#include "CanandcolorDetails.h"
7
9
10/**
11 * Decoded digital output state frame.
12 *
13 * Includes current output state, sticky flags, and per-slot condition bitfields.
14 */
16 /** Current digout1 output state. */
18 /** Current digout2 output state. */
20 /** Sticky flag for digout1 state changes. */
22 /** Sticky flag for digout2 state changes. */
24 /** Per-slot condition bitfield for digout1 logic chain. */
25 uint16_t digout1Cond;
26 /** Per-slot condition bitfield for digout2 logic chain. */
27 uint16_t digout2Cond;
28
29 /**
30 * Gets the boolean state of an individual slot condition for digout1.
31 * @param slotIndex slot index [0..15]
32 * @return true if the slot condition is true
33 */
34 bool GetDigout1SlotState(int slotIndex) const {
35 return (digout1Cond >> slotIndex) & 1;
36 }
37
38 /**
39 * Gets the boolean state of an individual slot condition for digout2.
40 * @param slotIndex slot index [0..15]
41 * @return true if the slot condition is true
42 */
43 bool GetDigout2SlotState(int slotIndex) const {
44 return (digout2Cond >> slotIndex) & 1;
45 }
46
47 /**
48 * Decodes a DigoutSlotState from a packed digital output message payload.
49 * @param msg message data (see protocol details)
50 * @return decoded DigoutSlotState
51 */
53 return DigoutSlotState {
55 .digout2State = msg.digout2_state,
56 .digout1Sticky = msg.digout1_sticky,
57 .digout2Sticky = msg.digout2_sticky,
58 .digout1Cond = msg.digout1_cond,
59 .digout2Cond = msg.digout2_cond
60 };
61 }
62};
63
64} // namespace redux::sensors::canandcolor
Definition Canandcolor.h:19
Definition DigoutSlotState.h:15
static constexpr DigoutSlotState FromMsg(details::msg::DigitalOutput msg)
Definition DigoutSlotState.h:52
uint16_t digout1Cond
Definition DigoutSlotState.h:25
bool digout1State
Definition DigoutSlotState.h:17
bool GetDigout2SlotState(int slotIndex) const
Definition DigoutSlotState.h:43
bool digout2State
Definition DigoutSlotState.h:19
bool digout1Sticky
Definition DigoutSlotState.h:21
uint16_t digout2Cond
Definition DigoutSlotState.h:27
bool digout2Sticky
Definition DigoutSlotState.h:23
bool GetDigout1SlotState(int slotIndex) const
Definition DigoutSlotState.h:34
bool digout2_state
Definition CanandcolorDetails.h:1137
bool digout1_state
Definition CanandcolorDetails.h:1134
uint16_t digout1_cond
Definition CanandcolorDetails.h:1146
bool digout2_sticky
Definition CanandcolorDetails.h:1143
bool digout1_sticky
Definition CanandcolorDetails.h:1140
uint16_t digout2_cond
Definition CanandcolorDetails.h:1149