WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
ImageSource.hpp
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <initializer_list>
8#include <span>
9#include <string>
10#include <string_view>
11#include <vector>
12
15#include "wpi/cs/cscore_cpp.hpp"
16
17namespace wpi::cs {
18
19/**
20 * A base class for single image providing sources.
21 */
22class ImageSource : public VideoSource {
23 protected:
24 ImageSource() = default;
25
26 public:
27 /**
28 * Signal sinks that an error has occurred. This should be called instead
29 * of NotifyFrame when an error occurs.
30 *
31 * @param msg Notification message.
32 */
33 void NotifyError(std::string_view msg) {
34 m_status = 0;
36 }
37
38 /**
39 * Set source connection status. Defaults to true.
40 *
41 * @param connected True for connected, false for disconnected
42 */
43 void SetConnected(bool connected) {
44 m_status = 0;
46 }
47
48 /**
49 * Set source description.
50 *
51 * @param description Description
52 */
53 void SetDescription(std::string_view description) {
54 m_status = 0;
56 }
57
58 /**
59 * Create a property.
60 *
61 * @param name Property name
62 * @param kind Property kind
63 * @param minimum Minimum value
64 * @param maximum Maximum value
65 * @param step Step value
66 * @param defaultValue Default value
67 * @param value Current value
68 * @return Property
69 */
71 int minimum, int maximum, int step,
72 int defaultValue, int value) {
73 m_status = 0;
75 m_handle, name, static_cast<CS_PropertyKind>(static_cast<int>(kind)),
76 minimum, maximum, step, defaultValue, value, &m_status)};
77 }
78
79 /**
80 * Create an integer property.
81 *
82 * @param name Property name
83 * @param minimum Minimum value
84 * @param maximum Maximum value
85 * @param step Step value
86 * @param defaultValue Default value
87 * @param value Current value
88 * @return Property
89 */
90 VideoProperty CreateIntegerProperty(std::string_view name, int minimum,
91 int maximum, int step, int defaultValue,
92 int value) {
93 m_status = 0;
96 static_cast<CS_PropertyKind>(
97 static_cast<int>(VideoProperty::Kind::kInteger)),
98 minimum, maximum, step, defaultValue, value, &m_status)};
99 }
100
101 /**
102 * Create a boolean property.
103 *
104 * @param name Property name
105 * @param defaultValue Default value
106 * @param value Current value
107 * @return Property
108 */
109 VideoProperty CreateBooleanProperty(std::string_view name, bool defaultValue,
110 bool value) {
111 m_status = 0;
113 m_handle, name,
114 static_cast<CS_PropertyKind>(
115 static_cast<int>(VideoProperty::Kind::kBoolean)),
116 0, 1, 1, defaultValue ? 1 : 0, value ? 1 : 0, &m_status)};
117 }
118
119 /**
120 * Create a string property.
121 *
122 * @param name Property name
123 * @param value Current value
124 * @return Property
125 */
127 std::string_view value) {
128 m_status = 0;
130 m_handle, name,
131 static_cast<CS_PropertyKind>(
132 static_cast<int>(VideoProperty::Kind::kString)),
133 0, 0, 0, 0, 0, &m_status)};
134 prop.SetString(value);
135 return prop;
136 }
137
138 /**
139 * Configure enum property choices.
140 *
141 * @param property Property
142 * @param choices Choices
143 */
145 std::span<const std::string> choices) {
146 m_status = 0;
147 SetSourceEnumPropertyChoices(m_handle, property.m_handle, choices,
148 &m_status);
149 }
150
151 /**
152 * Configure enum property choices.
153 *
154 * @param property Property
155 * @param choices Choices
156 */
157 template <typename T>
159 std::initializer_list<T> choices) {
160 std::vector<std::string> vec;
161 vec.reserve(choices.size());
162 for (const auto& choice : choices) {
163 vec.emplace_back(choice);
164 }
165 m_status = 0;
166 SetSourceEnumPropertyChoices(m_handle, property.m_handle, vec, &m_status);
167 }
168};
169
170} // namespace wpi::cs
@ name
Definition base.h:690
void SetEnumPropertyChoices(const VideoProperty &property, std::span< const std::string > choices)
Configure enum property choices.
Definition ImageSource.hpp:144
VideoProperty CreateIntegerProperty(std::string_view name, int minimum, int maximum, int step, int defaultValue, int value)
Create an integer property.
Definition ImageSource.hpp:90
VideoProperty CreateStringProperty(std::string_view name, std::string_view value)
Create a string property.
Definition ImageSource.hpp:126
void SetDescription(std::string_view description)
Set source description.
Definition ImageSource.hpp:53
VideoProperty CreateProperty(std::string_view name, VideoProperty::Kind kind, int minimum, int maximum, int step, int defaultValue, int value)
Create a property.
Definition ImageSource.hpp:70
void NotifyError(std::string_view msg)
Signal sinks that an error has occurred.
Definition ImageSource.hpp:33
void SetConnected(bool connected)
Set source connection status.
Definition ImageSource.hpp:43
VideoProperty CreateBooleanProperty(std::string_view name, bool defaultValue, bool value)
Create a boolean property.
Definition ImageSource.hpp:109
void SetEnumPropertyChoices(const VideoProperty &property, std::initializer_list< T > choices)
Configure enum property choices.
Definition ImageSource.hpp:158
A source or sink property.
Definition VideoProperty.hpp:34
CS_Status m_status
Definition VideoSource.hpp:372
VideoSource() noexcept=default
CS_Source m_handle
Video source handle.
Definition VideoSource.hpp:375
CS_PropertyKind
Property kinds.
Definition cscore_c.h:97
void SetSourceConnected(CS_Source source, bool connected, CS_Status *status)
CS_Property CreateSourceProperty(CS_Source source, std::string_view name, CS_PropertyKind kind, int minimum, int maximum, int step, int defaultValue, int value, CS_Status *status)
void SetSourceDescription(CS_Source source, std::string_view description, CS_Status *status)
void SetSourceEnumPropertyChoices(CS_Source source, CS_Property property, std::span< const std::string > choices, CS_Status *status)
void NotifySourceError(CS_Source source, std::string_view msg, CS_Status *status)
Kind
Definition VideoProperty.hpp:41
void SetString(std::string_view value)
Sets the string property value.
Definition VideoProperty.hpp:200
@ kBoolean
Boolean property.
Definition VideoProperty.hpp:45
@ kString
String property.
Definition VideoProperty.hpp:49
@ kInteger
Integer property.
Definition VideoProperty.hpp:47
CameraServer (cscore) namespace.
Definition CvSource.hpp:15