Skip to content

Commit

Permalink
#72
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Jan 23, 2017
1 parent f92d86a commit 278a8cf
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
4 changes: 3 additions & 1 deletion eez_psu_sketch/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,13 @@ void errorMessage(const data::Cursor& cursor, data::Value value, void (*ok_callb
}

alertMessage(errorPageId, value, ok_callback);
sound::playBeep();
}


void errorMessageP(const char *message PROGMEM, void (*ok_callback)()) {
alertMessage(PAGE_ID_ERROR_ALERT, data::Value::ProgmemStr(message), ok_callback);
sound::playBeep();
}

void yesNoDialog(int yesNoPageId, const char *message PROGMEM, void (*yes_callback)(), void (*no_callback)(), void (*cancel_callback)()) {
Expand Down Expand Up @@ -637,7 +639,7 @@ void onEncoder(int counter) {
newValue = min;
}

float max = data::getLimit(g_focusCursor, g_focusDataId).getFloat();
float max = data::getMax(g_focusCursor, g_focusDataId).getFloat();
if (newValue > max) {
newValue = max;
}
Expand Down
12 changes: 6 additions & 6 deletions eez_psu_sketch/gui_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,17 +385,17 @@ void getList(const Cursor &cursor, uint8_t id, const Value **values, int &count)

bool set(const Cursor &cursor, uint8_t id, Value value, int16_t *error) {
if (id == DATA_ID_CHANNEL_U_SET) {
if (value.getFloat() < channel_dispatcher::getUMin(Channel::get(cursor.i)) || value.getFloat() > channel_dispatcher::getUMax(Channel::get(cursor.i))) {
if (!util::between(value.getFloat(), channel_dispatcher::getUMin(Channel::get(cursor.i)), channel_dispatcher::getUMax(Channel::get(cursor.i)), CHANNEL_VALUE_PRECISION)) {
if (error) *error = SCPI_ERROR_DATA_OUT_OF_RANGE;
return false;
}

if (value.getFloat() > channel_dispatcher::getULimit(Channel::get(cursor.i))) {
if (!util::lessOrEqual(value.getFloat(), channel_dispatcher::getULimit(Channel::get(cursor.i)), CHANNEL_VALUE_PRECISION)) {
if (error) *error = SCPI_ERROR_VOLTAGE_LIMIT_EXCEEDED;
return false;
}

if (value.getFloat() * channel_dispatcher::getISet(Channel::get(cursor.i)) > channel_dispatcher::getPowerLimit(Channel::get(cursor.i))) {
if (!util::lessOrEqual(value.getFloat() * channel_dispatcher::getISet(Channel::get(cursor.i)), channel_dispatcher::getPowerLimit(Channel::get(cursor.i)), CHANNEL_VALUE_PRECISION)) {
if (error) *error = SCPI_ERROR_POWER_LIMIT_EXCEEDED;
return false;
}
Expand All @@ -404,17 +404,17 @@ bool set(const Cursor &cursor, uint8_t id, Value value, int16_t *error) {

return true;
} else if (id == DATA_ID_CHANNEL_I_SET) {
if (value.getFloat() < channel_dispatcher::getIMin(Channel::get(cursor.i)) || value.getFloat() > channel_dispatcher::getIMax(Channel::get(cursor.i))) {
if (!util::between(value.getFloat(), channel_dispatcher::getIMin(Channel::get(cursor.i)), channel_dispatcher::getIMax(Channel::get(cursor.i)), CHANNEL_VALUE_PRECISION)) {
if (error) *error = SCPI_ERROR_DATA_OUT_OF_RANGE;
return false;
}

if (value.getFloat() > channel_dispatcher::getILimit(Channel::get(cursor.i))) {
if (!util::lessOrEqual(value.getFloat(), channel_dispatcher::getILimit(Channel::get(cursor.i)), CHANNEL_VALUE_PRECISION)) {
if (error) *error = SCPI_ERROR_CURRENT_LIMIT_EXCEEDED;
return false;
}

if (value.getFloat() * channel_dispatcher::getUSet(Channel::get(cursor.i)) > channel_dispatcher::getPowerLimit(Channel::get(cursor.i))) {
if (!util::lessOrEqual(value.getFloat() * channel_dispatcher::getUSet(Channel::get(cursor.i)), channel_dispatcher::getPowerLimit(Channel::get(cursor.i)), CHANNEL_VALUE_PRECISION)) {
if (error) *error = SCPI_ERROR_POWER_LIMIT_EXCEEDED;
return false;
}
Expand Down
8 changes: 8 additions & 0 deletions eez_psu_sketch/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,18 @@ bool greaterOrEqual(float a, float b, float prec) {
return a > b || equal(a, b, prec);
}

bool lessOrEqual(float a, float b, float prec) {
return a < b || equal(a, b, prec);
}

bool equal(float a, float b, float prec) {
return roundf(a * prec) == roundf(b * prec);
}

bool between(float x, float a, float b, float prec) {
return greaterOrEqual(x, a, prec) && lessOrEqual(x, b, prec);
}

float multiply(float a, float b, float prec) {
return roundPrec(a, prec) * roundPrec(b, prec);
}
Expand Down
3 changes: 3 additions & 0 deletions eez_psu_sketch/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ float ceilPrec(float a, float prec);
float roundPrec(float a, float prec);

bool greaterOrEqual(float a, float b, float prec);
bool lessOrEqual(float a, float b, float prec);
bool equal(float a, float b, float prec);

bool between(float x, float a, float b, float prec);

float multiply(float a, float b, float prec);

bool isNaN(float x);
Expand Down

0 comments on commit 278a8cf

Please sign in to comment.