ngscopeclient v0.2.2
Loading...
Searching...
No Matches
FunctionGeneratorState.h
Go to the documentation of this file.
1/***********************************************************************************************************************
2* *
3* ngscopeclient *
4* *
5* Copyright (c) 2012-2026 Andrew D. Zonenberg and contributors *
6* All rights reserved. *
7* *
8* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
9* following conditions are met: *
10* *
11* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
12* following disclaimer. *
13* *
14* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
15* following disclaimer in the documentation and/or other materials provided with the distribution. *
16* *
17* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
18* derived from this software without specific prior written permission. *
19* *
20* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
21* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
22* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
24* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
26* POSSIBILITY OF SUCH DAMAGE. *
27* *
28***********************************************************************************************************************/
29
35#ifndef FunctionGeneratorState_h
36#define FunctionGeneratorState_h
37
42{
43public:
44
45 FunctionGeneratorState(std::shared_ptr<FunctionGenerator> generator)
46 {
47 size_t n = generator->GetChannelCount();
48 m_channelNumber = n;
49 m_channelActive = std::make_unique<bool[] >(n);
50 m_channelAmplitude = std::make_unique<std::atomic<float>[] >(n);
51 m_channelOffset= std::make_unique<std::atomic<float>[] >(n);
52 m_channelFrequency = std::make_unique<std::atomic<float>[] >(n);
53 m_channelDutyCycle = std::make_unique<std::atomic<float>[] >(n);
54 m_channelRiseTime = std::make_unique<std::atomic<float>[] >(n);
55 m_channelFallTime = std::make_unique<std::atomic<float>[] >(n);
56 m_channelShape = std::make_unique<std::atomic<FunctionGenerator::WaveShape>[] >(n);
57 m_channelOutputImpedance = std::make_unique<std::atomic<FunctionGenerator::OutputImpedance>[] >(n);
58 m_channelShapes = std::make_unique<std::vector<FunctionGenerator::WaveShape>[] >(n);
59 m_channelShapeIndexes = std::make_unique<std::map<FunctionGenerator::WaveShape,int>[] >(n);
60 m_channelShapeNames = std::make_unique<std::vector<std::string>[] >(n);
61
62 m_needsUpdate = std::make_unique<std::atomic<bool>[] >(n);
63
64 m_strOffset = std::make_unique<std::string[]>(n);
65 m_committedOffset = std::make_unique<float[]>(n);
66 m_strAmplitude = std::make_unique<std::string[]>(n);
67 m_committedAmplitude = std::make_unique<float[]>(n);
68 m_strFrequency = std::make_unique<std::string[]>(n);
69 m_committedFrequency = std::make_unique<float[]>(n);
70 m_strDutyCycle = std::make_unique<std::string[]>(n);
71 m_committedDutyCycle = std::make_unique<float[]>(n);
72 m_strRiseTime = std::make_unique<std::string[]>(n);
73 m_committedRiseTime = std::make_unique<float[]>(n);
74 m_strFallTime = std::make_unique<std::string[]>(n);
75 m_committedFallTime = std::make_unique<float[]>(n);
76
77 Unit volts(Unit::UNIT_VOLTS);
78
79 for(size_t i=0; i<n; i++)
80 {
81 m_channelActive[i] = false;
82 m_channelAmplitude[i] = 0;
83 m_channelOffset[i] = 0;
84 m_channelFrequency[i] = 0;
85 m_channelDutyCycle[i] = 0;
86 m_channelRiseTime[i] = 0;
87 m_channelFallTime[i] = 0;
88 m_channelShape[i] = FunctionGenerator::WaveShape::SHAPE_SINE;
90 // Init shape list and names
91 m_channelShapes[i] = generator->GetAvailableWaveformShapes(i);
92 for(size_t j=0; j<m_channelShapes[i].size(); j++)
93 {
94 m_channelShapeNames[i].push_back(generator->GetNameOfShape(m_channelShapes[i][j]));
95 m_channelShapeIndexes[i][m_channelShapes[i][j]] = j;
96 }
97 m_needsUpdate[i] = true;
98
99 m_committedAmplitude[i] = FLT_MIN;
100 m_committedOffset[i] = FLT_MIN;
101 m_committedFrequency[i] = FLT_MIN;
102 m_committedDutyCycle[i] = FLT_MIN;
103 m_committedRiseTime[i] = FLT_MIN;
104 m_committedFallTime[i] = FLT_MIN;
105 }
106 }
107
108 void FlushConfigCache()
109 {
110 for(size_t i = 0 ; i < m_channelNumber.load() ; i++)
111 m_needsUpdate[i] = true;
112 }
113
114 std::unique_ptr<bool[]> m_channelActive;
115 std::unique_ptr<std::atomic<float>[]> m_channelAmplitude;
116 std::unique_ptr<std::atomic<float>[]> m_channelOffset;
117 std::unique_ptr<std::atomic<float>[]> m_channelFrequency;
118 std::unique_ptr<std::atomic<float>[]> m_channelDutyCycle;
119 std::unique_ptr<std::atomic<float>[]> m_channelRiseTime;
120 std::unique_ptr<std::atomic<float>[]> m_channelFallTime;
121 std::unique_ptr<std::atomic<FunctionGenerator::WaveShape>[]> m_channelShape;
122 std::unique_ptr<std::atomic<FunctionGenerator::OutputImpedance>[]> m_channelOutputImpedance;
123 std::unique_ptr<std::vector<FunctionGenerator::WaveShape>[]> m_channelShapes;
124 std::unique_ptr<std::map<FunctionGenerator::WaveShape,int>[]> m_channelShapeIndexes;
125 std::unique_ptr<std::vector<std::string>[]> m_channelShapeNames;
126
127 std::unique_ptr<std::atomic<bool>[]> m_needsUpdate;
128
129 std::atomic<size_t> m_channelNumber;
130
131 //UI state for dialogs etc
132 std::unique_ptr<float[]> m_committedOffset;
133 std::unique_ptr<std::string[]> m_strOffset;
134
135 std::unique_ptr<float[]> m_committedAmplitude;
136 std::unique_ptr<std::string[]> m_strAmplitude;
137
138 std::unique_ptr<float[]> m_committedFrequency;
139 std::unique_ptr<std::string[]> m_strFrequency;
140
141 std::unique_ptr<float[]> m_committedDutyCycle;
142 std::unique_ptr<std::string[]> m_strDutyCycle;
143
144 std::unique_ptr<float[]> m_committedRiseTime;
145 std::unique_ptr<std::string[]> m_strRiseTime;
146
147 std::unique_ptr<float[]> m_committedFallTime;
148 std::unique_ptr<std::string[]> m_strFallTime;
149};
150
151#endif
Definition AcceleratorBuffer.h:204
Current status of a Function Generator.
Definition FunctionGeneratorState.h:42
@ IMPEDANCE_HIGH_Z
Channel expects to drive a high-impedance load.
Definition FunctionGenerator.h:261
A unit of measurement, plus conversion to pretty-printed output.
Definition Unit.h:59