Skip to content

Commit

Permalink
#73
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Oct 22, 2020
1 parent 5594861 commit 1108b39
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 35 deletions.
38 changes: 6 additions & 32 deletions src/eez/modules/psu/gui/keypad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,11 +681,11 @@ void NumericKeypad::toggleEditUnit() {

////////////////////////////////////////////////////////////////////////////////

float NumericKeypad::getValue() {
double NumericKeypad::getValue() {
const char *p = m_keypadText;

int a = 0;
float b = 0;
double b = 0;
int sign = 1;

if (*p == '-') {
Expand All @@ -708,7 +708,7 @@ float NumericKeypad::getValue() {
}
}

float value = sign * (a + b);
double value = sign * (a + b);

if (isPico()) {
value *= 1E-12f;
Expand All @@ -727,33 +727,6 @@ float NumericKeypad::getValue() {
return value;
}

int NumericKeypad::getNumDecimalDigits() {
int n = 0;
bool afterDot = false;
for (int i = 0; m_keypadText[i]; ++i) {
if (afterDot) {
++n;
} else if (m_keypadText[i] == '.') {
afterDot = true;
}
}
return n;
}

bool NumericKeypad::isValueValid() {
if (m_appContext->getActivePageId() != PAGE_ID_EDIT_MODE_KEYPAD) {
return true;
}

float value = getValue();

if ((value < m_options.min || value > m_options.max) && !(value == 0 && m_options.allowZero)) {
return false;
}

return true;
}

bool NumericKeypad::checkNumSignificantDecimalDigits() {
return true;
}
Expand Down Expand Up @@ -961,13 +934,14 @@ void NumericKeypad::ok() {

return;
} else {
float value = getValue();
double value = getValue();

if (!isNaN(m_options.min) && value < m_options.min && !(value == 0 && m_options.allowZero)) {
psuErrorMessage(0, MakeLessThenMinMessageValue(m_options.min, m_startValue));
} else if (!isNaN(m_options.max) && value > m_options.max) {
psuErrorMessage(0, MakeGreaterThenMaxMessageValue(m_options.max, m_startValue));
} else {
m_okFloatCallback(value);
m_okFloatCallback((float)value);
return;
}

Expand Down
4 changes: 1 addition & 3 deletions src/eez/modules/psu/gui/keypad.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class NumericKeypad : public Keypad {
void (*m_cancelCallback)();

void appendEditUnit(char *text);
float getValue();
double getValue();
char getDotSign();

bool isPico();
Expand All @@ -252,8 +252,6 @@ class NumericKeypad : public Keypad {
Unit getMegaUnit();

void toggleEditUnit();
int getNumDecimalDigits();
bool isValueValid();
bool checkNumSignificantDecimalDigits();
void digit(int d);
void dot();
Expand Down

0 comments on commit 1108b39

Please sign in to comment.