Skip to content

Commit 0574e50

Browse files
committed
edit mode changed
1 parent 3febf2c commit 0574e50

File tree

12 files changed

+30385
-30724
lines changed

12 files changed

+30385
-30724
lines changed

modular-psu-firmware.eez-project

Lines changed: 362 additions & 677 deletions
Large diffs are not rendered by default.

src/eez/apps/psu/gui/data.cpp

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -881,14 +881,11 @@ void data_channel_u_set(data::DataOperationEnum operation, data::Cursor &cursor,
881881
} else if (operation == data::DATA_OPERATION_GET_UNIT) {
882882
value = UNIT_VOLT;
883883
} else if (operation == data::DATA_OPERATION_SET) {
884-
if (!psu::between(value.getFloat(), channel_dispatcher::getUMin(channel),
885-
channel_dispatcher::getUMax(channel), UNIT_VOLT, iChannel)) {
884+
if (!psu::between(value.getFloat(), channel_dispatcher::getUMin(channel), channel_dispatcher::getUMax(channel), UNIT_VOLT, iChannel)) {
886885
value = MakeScpiErrorValue(SCPI_ERROR_DATA_OUT_OF_RANGE);
887-
} else if (psu::greater(value.getFloat(), channel_dispatcher::getULimit(channel), UNIT_VOLT,
888-
iChannel)) {
886+
} else if (psu::greater(value.getFloat(), channel_dispatcher::getULimit(channel), UNIT_VOLT, iChannel)) {
889887
value = MakeScpiErrorValue(SCPI_ERROR_VOLTAGE_LIMIT_EXCEEDED);
890-
} else if (psu::greater(value.getFloat() * channel_dispatcher::getISetUnbalanced(channel),
891-
channel_dispatcher::getPowerLimit(channel), UNIT_WATT, iChannel)) {
888+
} else if (psu::greater(value.getFloat() * channel_dispatcher::getISetUnbalanced(channel), channel_dispatcher::getPowerLimit(channel), UNIT_WATT, iChannel)) {
892889
value = MakeScpiErrorValue(SCPI_ERROR_POWER_LIMIT_EXCEEDED);
893890
} else {
894891
channel_dispatcher::setVoltage(channel, value.getFloat());
@@ -910,8 +907,7 @@ void data_channel_u_mon(data::DataOperationEnum operation, data::Cursor &cursor,
910907
value = MakeValue(channel_dispatcher::getULimit(channel), UNIT_VOLT, iChannel);
911908
} else if (operation == data::DATA_OPERATION_GET_HISTORY_VALUE) {
912909
int position = value.getInt();
913-
value =
914-
MakeValue(channel_dispatcher::getUMonHistory(channel, position), UNIT_VOLT, iChannel);
910+
value = MakeValue(channel_dispatcher::getUMonHistory(channel, position), UNIT_VOLT, iChannel);
915911
}
916912
}
917913

@@ -938,12 +934,10 @@ void data_channel_u_edit(data::DataOperationEnum operation, data::Cursor &cursor
938934
int iChannel = cursor.i >= 0 ? cursor.i : (g_channel ? (g_channel->index - 1) : 0);
939935
Channel &channel = Channel::get(iChannel);
940936
if (operation == data::DATA_OPERATION_GET) {
941-
bool focused = (g_focusCursor == cursor || channel_dispatcher::isCoupled()) &&
942-
g_focusDataId == DATA_ID_CHANNEL_U_EDIT;
937+
bool focused = (g_focusCursor == cursor || channel_dispatcher::isCoupled()) && g_focusDataId == DATA_ID_CHANNEL_U_EDIT;
943938
if (focused && g_focusEditValue.getType() != VALUE_TYPE_NONE) {
944939
value = g_focusEditValue;
945-
} else if (focused && getActivePageId() == PAGE_ID_EDIT_MODE_KEYPAD &&
946-
edit_mode_keypad::g_keypad->isEditing()) {
940+
} else if (focused && getActivePageId() == PAGE_ID_EDIT_MODE_KEYPAD && edit_mode_keypad::g_keypad->isEditing()) {
947941
data_keypad_text(operation, cursor, value);
948942
} else {
949943
value = MakeValue(channel_dispatcher::getUSet(channel), UNIT_VOLT, iChannel);
@@ -959,14 +953,11 @@ void data_channel_u_edit(data::DataOperationEnum operation, data::Cursor &cursor
959953
} else if (operation == data::DATA_OPERATION_GET_UNIT) {
960954
value = UNIT_VOLT;
961955
} else if (operation == data::DATA_OPERATION_SET) {
962-
if (!psu::between(value.getFloat(), channel_dispatcher::getUMin(channel),
963-
channel_dispatcher::getUMax(channel), UNIT_VOLT, iChannel)) {
956+
if (!psu::between(value.getFloat(), channel_dispatcher::getUMin(channel), channel_dispatcher::getUMax(channel), UNIT_VOLT, iChannel)) {
964957
value = MakeScpiErrorValue(SCPI_ERROR_DATA_OUT_OF_RANGE);
965-
} else if (psu::greater(value.getFloat(), channel_dispatcher::getULimit(channel), UNIT_VOLT,
966-
iChannel)) {
958+
} else if (psu::greater(value.getFloat(), channel_dispatcher::getULimit(channel), UNIT_VOLT, iChannel)) {
967959
value = MakeScpiErrorValue(SCPI_ERROR_VOLTAGE_LIMIT_EXCEEDED);
968-
} else if (psu::greater(value.getFloat() * channel_dispatcher::getISetUnbalanced(channel),
969-
channel_dispatcher::getPowerLimit(channel), UNIT_WATT, iChannel)) {
960+
} else if (psu::greater(value.getFloat() * channel_dispatcher::getISetUnbalanced(channel), channel_dispatcher::getPowerLimit(channel), UNIT_WATT, iChannel)) {
970961
value = MakeScpiErrorValue(SCPI_ERROR_POWER_LIMIT_EXCEEDED);
971962
} else {
972963
channel_dispatcher::setVoltage(channel, value.getFloat());
@@ -1269,25 +1260,7 @@ void data_edit_unit(data::DataOperationEnum operation, data::Cursor &cursor, dat
12691260

12701261
void data_edit_info(data::DataOperationEnum operation, data::Cursor &cursor, data::Value &value) {
12711262
if (operation == data::DATA_OPERATION_GET) {
1272-
int editInfoPartOffset =
1273-
g_focusCursor.i * 6 + (g_focusDataId == DATA_ID_CHANNEL_U_EDIT ? 0 : 1) * 3;
1274-
value = data::Value(0 + editInfoPartOffset, VALUE_TYPE_EDIT_INFO);
1275-
}
1276-
}
1277-
1278-
void data_edit_info1(data::DataOperationEnum operation, data::Cursor &cursor, data::Value &value) {
1279-
if (operation == data::DATA_OPERATION_GET) {
1280-
int editInfoPartOffset =
1281-
g_focusCursor.i * 6 + (g_focusDataId == DATA_ID_CHANNEL_U_EDIT ? 0 : 1) * 3;
1282-
value = data::Value(1 + editInfoPartOffset, VALUE_TYPE_EDIT_INFO);
1283-
}
1284-
}
1285-
1286-
void data_edit_info2(data::DataOperationEnum operation, data::Cursor &cursor, data::Value &value) {
1287-
if (operation == data::DATA_OPERATION_GET) {
1288-
int editInfoPartOffset =
1289-
g_focusCursor.i * 6 + (g_focusDataId == DATA_ID_CHANNEL_U_EDIT ? 0 : 1) * 3;
1290-
value = data::Value(2 + editInfoPartOffset, VALUE_TYPE_EDIT_INFO);
1263+
value = data::Value(edit_mode::getInfoTextPartIndex(g_focusCursor, g_focusDataId), VALUE_TYPE_EDIT_INFO);
12911264
}
12921265
}
12931266

src/eez/apps/psu/gui/edit_mode.cpp

Lines changed: 98 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -75,33 +75,33 @@ void enter(int tabIndex) {
7575
if (getFoundWidgetAtDown().widget->data == DATA_ID_CHANNEL_PROTECTION_OVP_LIMIT) {
7676
changeVoltageLimit(g_channel->index - 1);
7777
return;
78-
}
79-
78+
}
79+
8080
if (getFoundWidgetAtDown().widget->data == DATA_ID_CHANNEL_PROTECTION_OCP_LIMIT) {
8181
changeCurrentLimit(g_channel->index - 1);
8282
return;
8383
}
84-
84+
8585
if (getFoundWidgetAtDown().widget->data == DATA_ID_CHANNEL_PROTECTION_OPP_LIMIT) {
8686
changePowerLimit(g_channel->index - 1);
8787
return;
8888
}
89-
89+
9090
if (getFoundWidgetAtDown().widget->data == DATA_ID_CHANNEL_PROTECTION_OPP_LEVEL) {
9191
changePowerTripLevel(g_channel->index - 1);
9292
return;
9393
}
94-
94+
9595
if (getFoundWidgetAtDown().widget->data == DATA_ID_CHANNEL_PROTECTION_OTP_LEVEL) {
9696
changeTemperatureTripLevel(g_channel->index - 1);
9797
return;
9898
}
99-
99+
100100
if (getFoundWidgetAtDown().widget->data == DATA_ID_CHANNEL_PROTECTION_OPP_DELAY) {
101101
changePowerTripDelay(g_channel->index - 1);
102102
return;
103103
}
104-
104+
105105
if (getFoundWidgetAtDown().widget->data == DATA_ID_CHANNEL_PROTECTION_OTP_DELAY) {
106106
changeTemperatureTripDelay(g_channel->index - 1);
107107
return;
@@ -207,82 +207,107 @@ bool setValue(float value_) {
207207
return true;
208208
}
209209

210-
void getInfoText(int part, char *infoText) {
211-
// channel 0 u part 0
212-
// channel 0 u part 1
213-
// channel 0 u part 2
214-
// channel 0 i part 0
215-
// channel 0 i part 1
216-
// channel 0 i part 2
217-
// channel 1 u part 0
218-
// channel 1 u part 1
219-
// channel 1 u part 2
220-
// channel 1 i part 0
221-
// channel 1 i part 1
222-
// channel 1 i part 2
223-
// ...
224-
225-
int iChannel = part / 6;
226-
227-
part %= 6;
210+
int getInfoTextPartIndex(data::Cursor &cursor, uint16_t dataId) {
211+
int dataIdIndex;
212+
213+
if (dataId == DATA_ID_CHANNEL_U_SET || dataId == DATA_ID_CHANNEL_U_EDIT) {
214+
dataIdIndex = 0;
215+
} else if (dataId == DATA_ID_CHANNEL_I_SET || dataId == DATA_ID_CHANNEL_I_EDIT) {
216+
dataIdIndex = 1;
217+
} else if (dataId == DATA_ID_CHANNEL_PROTECTION_OVP_LIMIT) {
218+
dataIdIndex = 2;
219+
} else if (dataId == DATA_ID_CHANNEL_PROTECTION_OCP_LIMIT) {
220+
dataIdIndex = 3;
221+
} else if (dataId == DATA_ID_CHANNEL_PROTECTION_OPP_LIMIT) {
222+
dataIdIndex = 4;
223+
} else if (dataId == DATA_ID_CHANNEL_PROTECTION_OPP_LEVEL) {
224+
dataIdIndex = 5;
225+
} else if (dataId == DATA_ID_CHANNEL_PROTECTION_OPP_DELAY) {
226+
dataIdIndex = 6;
227+
} else if (dataId == DATA_ID_CHANNEL_PROTECTION_OTP_LEVEL) {
228+
dataIdIndex = 7;
229+
} else if (dataId == DATA_ID_CHANNEL_PROTECTION_OTP_DELAY) {
230+
dataIdIndex = 8;
231+
} else {
232+
dataIdIndex = 9;
233+
}
234+
235+
return g_focusCursor.i * 10 + dataIdIndex;
236+
}
237+
238+
void getInfoText(int partIndex, char *infoText) {
239+
int iChannel = partIndex / 10;
240+
241+
int dataIdIndex = partIndex % 10;
228242

229243
int dataId;
230-
if (part / 3 == 0) {
244+
const char *dataName;
245+
const char *unitName;
246+
int numSignificantDecimalDigits = 2;
247+
if (dataIdIndex == 0) {
231248
dataId = DATA_ID_CHANNEL_U_EDIT;
232-
} else {
249+
dataName = "Voltage";
250+
unitName = "V";
251+
} else if (dataIdIndex == 1) {
233252
dataId = DATA_ID_CHANNEL_I_EDIT;
253+
dataName = "Current";
254+
unitName = "A";
255+
} else if (dataIdIndex == 2) {
256+
dataId = DATA_ID_CHANNEL_PROTECTION_OVP_LIMIT;
257+
dataName = "OVP Limit";
258+
unitName = "V";
259+
} else if (dataIdIndex == 3) {
260+
dataId = DATA_ID_CHANNEL_PROTECTION_OCP_LIMIT;
261+
dataName = "OCP Limit";
262+
unitName = "A";
263+
} else if (dataIdIndex == 4) {
264+
dataId = DATA_ID_CHANNEL_PROTECTION_OPP_LIMIT;
265+
dataName = "OPP Limit";
266+
unitName = "W";
267+
} else if (dataIdIndex == 5) {
268+
dataId = DATA_ID_CHANNEL_PROTECTION_OPP_LEVEL;
269+
dataName = "OPP Level";
270+
unitName = "W";
271+
} else if (dataIdIndex == 6) {
272+
dataId = DATA_ID_CHANNEL_PROTECTION_OPP_DELAY;
273+
dataName = "OPP Delay";
274+
unitName = "s";
275+
numSignificantDecimalDigits = 0;
276+
} else if (dataIdIndex == 7) {
277+
dataId = DATA_ID_CHANNEL_PROTECTION_OTP_LEVEL;
278+
dataName = "OTP Level";
279+
unitName = "oC";
280+
numSignificantDecimalDigits = 0;
281+
} else if (dataIdIndex == 8) {
282+
dataId = DATA_ID_CHANNEL_PROTECTION_OTP_DELAY;
283+
dataName = "OTP Delay";
284+
unitName = "s";
285+
numSignificantDecimalDigits = 0;
286+
} else {
287+
dataId = DATA_ID_NONE;
288+
dataName = "Unknown";
289+
unitName = "";
234290
}
235291

236-
part %= 3;
237-
238-
Channel &channel = Channel::get(iChannel);
239-
if (dataId == DATA_ID_CHANNEL_I_EDIT) {
240-
if (part == 0 || part == 1) {
241-
if (channel_dispatcher::isCoupled() || channel_dispatcher::isTracked()) {
242-
strcpy(infoText, "Set current");
243-
} else {
244-
sprintf(infoText, "Set Ch%d current", channel.index);
245-
}
246-
} else {
247-
*infoText = 0;
248-
}
249-
250-
if (part == 0) {
251-
strcat(infoText, " ");
252-
}
292+
data::Cursor cursor(iChannel);
293+
float minValue = data::getMin(cursor, dataId).getFloat();
294+
float maxValue = (dataId == DATA_ID_CHANNEL_U_EDIT || dataId == DATA_ID_CHANNEL_I_EDIT) ?
295+
data::getLimit(cursor, dataId).getFloat() : data::getMax(cursor, dataId).getFloat();
253296

254-
if (part == 0 || part == 2) {
255-
strcat(infoText, "[");
256-
strcatFloat(infoText, g_minValue.getFloat(), 2);
257-
strcat(infoText, "-");
258-
strcatCurrent(infoText, channel_dispatcher::getILimit(Channel::get(g_focusCursor.i)),
259-
2);
260-
strcat(infoText, "]");
261-
}
297+
if (channel_dispatcher::isCoupled() || channel_dispatcher::isTracked()) {
298+
strcpy(infoText, "Set ");
262299
} else {
263-
if (part == 0 || part == 1) {
264-
if (channel_dispatcher::isCoupled() || channel_dispatcher::isTracked()) {
265-
strcpy(infoText, "Set voltage");
266-
} else {
267-
sprintf(infoText, "Set Ch%d voltage", channel.index);
268-
}
269-
} else {
270-
*infoText = 0;
271-
}
300+
sprintf(infoText, "Set Ch%d ", iChannel + 1);
301+
}
272302

273-
if (part == 0) {
274-
strcat(infoText, " ");
275-
}
303+
strcat(infoText, dataName);
276304

277-
if (part == 0 || part == 2) {
278-
strcat(infoText, "[");
279-
strcatFloat(infoText, g_minValue.getFloat(), 2);
280-
strcat(infoText, "-");
281-
strcatVoltage(infoText, channel_dispatcher::getULimit(Channel::get(g_focusCursor.i)),
282-
2);
283-
strcat(infoText, "]");
284-
}
285-
}
305+
strcat(infoText, " [");
306+
strcatFloat(infoText, minValue, numSignificantDecimalDigits);
307+
strcat(infoText, "-");
308+
strcatFloat(infoText, maxValue, numSignificantDecimalDigits);
309+
strcat(infoText, unitName);
310+
strcat(infoText, "]");
286311
}
287312

288313
} // namespace edit_mode

src/eez/apps/psu/gui/edit_mode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const eez::gui::data::Value &getMax();
3939
Unit getUnit();
4040
bool setValue(float value);
4141

42+
int getInfoTextPartIndex(eez::gui::data::Cursor &cursor, uint16_t dataId);
4243
void getInfoText(int part, char *infoText);
4344

4445
void nonInteractiveSet();

src/eez/apps/psu/gui/edit_mode_keypad.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,15 @@
2020

2121
#if OPTION_DISPLAY
2222

23+
#include <eez/gui/gui.h>
2324
#include <eez/apps/psu/gui/edit_mode.h>
2425
#include <eez/apps/psu/gui/edit_mode_keypad.h>
2526
#include <eez/apps/psu/gui/numeric_keypad.h>
2627

2728
namespace eez {
29+
30+
using namespace gui;
31+
2832
namespace psu {
2933
namespace gui {
3034
namespace edit_mode_keypad {
@@ -35,11 +39,12 @@ NumericKeypad *g_keypad;
3539
////////////////////////////////////////////////////////////////////////////////
3640

3741
void onKeypadOk(float value) {
38-
edit_mode::setValue(value);
42+
if (edit_mode::setValue(value)) {
43+
popPage();
44+
}
3945
}
4046

41-
void enter(Channel &channel, const eez::gui::data::Value &editValue,
42-
const eez::gui::data::Value &minValue, eez::gui::data::Value &maxValue) {
47+
void enter(Channel &channel, const eez::gui::data::Value &editValue, const eez::gui::data::Value &minValue, eez::gui::data::Value &maxValue) {
4348
g_keypad = &g_theKeypad;
4449

4550
NumericKeypadOptions options;

src/eez/apps/psu/gui/numeric_keypad.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,7 @@ void NumericKeypad::ok() {
546546

547547
if (!isNaN(m_options.min) && less(value, m_options.min, m_startValue.getUnit(), m_options.channelIndex)) {
548548
psuErrorMessage(0, MakeLessThenMinMessageValue(m_options.min, m_startValue));
549-
} else if (!isNaN(m_options.max) && greater(value, m_options.max, m_startValue.getUnit(),
550-
m_options.channelIndex)) {
549+
} else if (!isNaN(m_options.max) && greater(value, m_options.max, m_startValue.getUnit(), m_options.channelIndex)) {
551550
psuErrorMessage(0, MakeGreaterThenMaxMessageValue(m_options.max, m_startValue));
552551
} else {
553552
m_okFloatCallback(value);

src/eez/apps/psu/gui/psu.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,8 +612,10 @@ void findNextFocusCursor(const WidgetCursor &widgetCursor) {
612612
void moveToNextFocusCursor() {
613613
g_findNextFocusCursorState = 0;
614614
enumWidgets(findNextFocusCursor);
615-
g_focusCursor = g_nextFocusCursor;
616-
g_focusDataId = g_nextFocusDataId;
615+
if (g_findNextFocusCursorState > 0) {
616+
g_focusCursor = g_nextFocusCursor;
617+
g_focusDataId = g_nextFocusDataId;
618+
}
617619
}
618620

619621
bool onEncoderConfirmation() {

0 commit comments

Comments
 (0)