ngscopeclient 0.1-dev+51fbda87c
LoadDialog.h
Go to the documentation of this file.
1/***********************************************************************************************************************
2* *
3* ngscopeclient *
4* *
5* Copyright (c) 2012-2024 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 LoadDialog_h
36#define LoadDialog_h
37
38#include "Dialog.h"
39#include "Session.h"
40
41#include <future>
42
49{
50public:
51 bool m_loadEnabled;
52
53 int m_voltageRangeIndex;
54 std::vector<std::string> m_voltageRangeNames;
55
56 int m_currentRangeIndex;
57 std::vector<std::string> m_currentRangeNames;
58
59 Load::LoadMode m_mode;
60
61 float m_committedSetPoint;
62 std::string m_setPoint;
63
65 : m_loadEnabled(false)
66 , m_voltageRangeIndex(0)
67 , m_currentRangeIndex(0)
69 , m_committedSetPoint(0)
70 , m_chan(0)
71 , m_load(nullptr)
72 {}
73
74 LoadChannelUIState(std::shared_ptr<SCPILoad> load, size_t chan)
75 : m_loadEnabled(load->GetLoadActive(chan))
76 , m_mode(load->GetLoadMode(chan))
77 , m_chan(chan)
78 , m_load(load)
79 {
80 //Voltage ranges
81 Unit volts(Unit::UNIT_VOLTS);
82 auto vranges = load->GetLoadVoltageRanges(chan);
83 for(auto v : vranges)
84 m_voltageRangeNames.push_back(volts.PrettyPrint(v));
85 m_voltageRangeIndex = load->GetLoadVoltageRange(chan);
86
87 //Current ranges
88 Unit amps(Unit::UNIT_AMPS);
89 auto iranges = load->GetLoadCurrentRanges(chan);
90 for(auto i : iranges)
91 m_currentRangeNames.push_back(amps.PrettyPrint(i));
92 m_currentRangeIndex = load->GetLoadCurrentRange(chan);
93
95 }
96
101 {
102 //can happen if we're a placeholder prior to completion of async init
103 if(m_load == nullptr)
104 return;
105
106 m_committedSetPoint = m_load->GetLoadSetPoint(m_chan);
107
108 //Mode
109 Unit volts(Unit::UNIT_VOLTS);
110 Unit amps(Unit::UNIT_AMPS);
111 Unit watts(Unit::UNIT_WATTS);
112 Unit ohms(Unit::UNIT_OHMS);
113 switch(m_mode)
114 {
116 m_setPoint = amps.PrettyPrint(m_committedSetPoint);
117 break;
118
120 m_setPoint = volts.PrettyPrint(m_committedSetPoint);
121 break;
122
124 m_setPoint = watts.PrettyPrint(m_committedSetPoint);
125 break;
126
128 m_setPoint = ohms.PrettyPrint(m_committedSetPoint);
129 break;
130
131 default:
132 break;
133 }
134 }
135
136protected:
137 size_t m_chan;
138 std::shared_ptr<Load> m_load;
139};
140
141
142class LoadDialog : public Dialog
143{
144public:
145 LoadDialog(std::shared_ptr<SCPILoad> load, std::shared_ptr<LoadState> state, Session* session);
146 virtual ~LoadDialog();
147
148 virtual bool DoRender();
149
150 std::shared_ptr<SCPILoad> GetLoad()
151 { return m_load; }
152
153 void RefreshFromHardware();
154
155protected:
156 void ChannelSettings(size_t channel);
157
160
162 double m_tstart;
163
165 std::shared_ptr<SCPILoad> m_load;
166
168 std::shared_ptr<LoadState> m_state;
169
171 std::vector<std::string> m_channelNames;
172
173 //Future channel state during loading
174 std::vector<std::future<LoadChannelUIState> > m_futureUIState;
175
177 std::vector<LoadChannelUIState> m_channelUIState;
178};
179
180
181
182#endif
Declaration of Dialog.
Declaration of Session.
Generic dialog box or other popup window.
Definition: Dialog.h:44
UI state for a single load channel.
Definition: LoadDialog.h:49
void RefreshSetPoint()
Pulls the set point from hardware.
Definition: LoadDialog.h:100
Definition: LoadDialog.h:143
std::shared_ptr< SCPILoad > m_load
The load we're controlling.
Definition: LoadDialog.h:165
void ChannelSettings(size_t channel)
Run settings for a single channel of the load.
Definition: LoadDialog.cpp:162
double m_tstart
Timestamp of when we opened the dialog.
Definition: LoadDialog.h:162
Session * m_session
Session handle so we can remove the load when closed.
Definition: LoadDialog.h:159
std::shared_ptr< LoadState > m_state
Current channel stats, live updated.
Definition: LoadDialog.h:168
std::vector< std::string > m_channelNames
Set of channel names.
Definition: LoadDialog.h:171
std::vector< LoadChannelUIState > m_channelUIState
Channel state for the UI.
Definition: LoadDialog.h:177
LoadMode
Operating modes for the load.
Definition: Load.h:62
@ MODE_CONSTANT_VOLTAGE
Draw as much current as needed for the input voltage to drop to the specified level.
Definition: Load.h:67
@ MODE_CONSTANT_CURRENT
Draw a constant current regardless of supplied voltage.
Definition: Load.h:64
@ MODE_CONSTANT_POWER
Draw a constant power regardless of supplied voltage.
Definition: Load.h:73
@ MODE_CONSTANT_RESISTANCE
Emulate a fixed resistance.
Definition: Load.h:70
A Session stores all of the instrument configuration and other state the user has open.
Definition: Session.h:95
A unit of measurement, plus conversion to pretty-printed output.
Definition: Unit.h:57
std::string PrettyPrint(double value, int sigfigs=-1, bool useDisplayLocale=true) const
Prints a value with SI scaling factors.
Definition: Unit.cpp:587