Skip to content

Commit

Permalink
inhibit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Nov 15, 2019
1 parent 2e092e8 commit e8e010a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
2 changes: 0 additions & 2 deletions src/eez/modules/psu/gui/page_sys_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -742,8 +742,6 @@ void SysSettingsIOPinsPage::set() {
}

popPage();

io_pins::refresh();
}
}

Expand Down
28 changes: 15 additions & 13 deletions src/eez/modules/psu/io_pins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ static uint32_t g_toutputPulseStartTickCount;

static bool g_pinState[NUM_IO_PINS] = { false, false, false, false };

static bool g_isInhibitedByUser;

#if defined EEZ_PLATFORM_STM32

int ioPinRead(int pin) {
Expand Down Expand Up @@ -156,18 +158,20 @@ void init() {

void tick(uint32_t tickCount) {
// execute input pins function
unsigned inhibited = 0;
unsigned inhibited = g_isInhibitedByUser;

const persist_conf::IOPin &inputPin1 = persist_conf::devConf.ioPins[0];
if (inputPin1.function == io_pins::FUNCTION_INHIBIT) {
int value = ioPinRead(EXT_TRIG1);
inhibited = (value && inputPin1.polarity == io_pins::POLARITY_POSITIVE) || (!value && inputPin1.polarity == io_pins::POLARITY_NEGATIVE) ? 1 : 0;
}
if (!inhibited) {
const persist_conf::IOPin &inputPin1 = persist_conf::devConf.ioPins[0];
if (inputPin1.function == io_pins::FUNCTION_INHIBIT) {
int value = ioPinRead(EXT_TRIG1);
inhibited = (value && inputPin1.polarity == io_pins::POLARITY_POSITIVE) || (!value && inputPin1.polarity == io_pins::POLARITY_NEGATIVE) ? 1 : 0;
}

const persist_conf::IOPin &inputPin2 = persist_conf::devConf.ioPins[1];
if (inputPin2.function == io_pins::FUNCTION_INHIBIT) {
int value = ioPinRead(EXT_TRIG2);
inhibited = (value && inputPin2.polarity == io_pins::POLARITY_POSITIVE) || (!value && inputPin2.polarity == io_pins::POLARITY_NEGATIVE) ? 1 : 0;
const persist_conf::IOPin &inputPin2 = persist_conf::devConf.ioPins[1];
if (inputPin2.function == io_pins::FUNCTION_INHIBIT) {
int value = ioPinRead(EXT_TRIG2);
inhibited = (value && inputPin2.polarity == io_pins::POLARITY_POSITIVE) || (!value && inputPin2.polarity == io_pins::POLARITY_NEGATIVE) ? 1 : 0;
}
}

if (inhibited != g_lastState.inhibited) {
Expand Down Expand Up @@ -262,8 +266,6 @@ void refresh() {
}
}

static bool g_isInhibitedByUser;

bool getIsInhibitedByUser() {
return g_isInhibitedByUser;
}
Expand All @@ -273,7 +275,7 @@ void setIsInhibitedByUser(bool isInhibitedByUser) {
}

bool isInhibited() {
return g_isInhibitedByUser || g_lastState.inhibited ? true : false;
return g_lastState.inhibited;
}

void setPinState(int pin, bool state) {
Expand Down
3 changes: 3 additions & 0 deletions src/eez/modules/psu/persist_conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ using namespace eez::mcu::display;
#include <eez/modules/psu/datetime.h>
#include <eez/modules/psu/trigger.h>
#include <eez/modules/psu/ontime.h>
#include <eez/modules/psu/io_pins.h>

#include <eez/gui/widgets/yt_graph.h>

Expand Down Expand Up @@ -1206,10 +1207,12 @@ void setDstRule(uint8_t dstRule) {

void setIoPinPolarity(int pin, unsigned polarity) {
g_devConf.ioPins[pin].polarity = polarity;
io_pins::refresh();
}

void setIoPinFunction(int pin, unsigned function) {
g_devConf.ioPins[pin].function = function;
io_pins::refresh();
}

void setSelectedThemeIndex(uint8_t selectedThemeIndex) {
Expand Down
4 changes: 0 additions & 4 deletions src/eez/modules/psu/scpi/syst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1427,8 +1427,6 @@ scpi_result_t scpi_cmd_systemDigitalPinFunction(scpi_t *context) {

persist_conf::setIoPinFunction(pin, function);

io_pins::refresh();

return SCPI_RES_OK;
}

Expand Down Expand Up @@ -1470,8 +1468,6 @@ scpi_result_t scpi_cmd_systemDigitalPinPolarity(scpi_t *context) {

persist_conf::setIoPinPolarity(pin, polarity);

io_pins::refresh();

return SCPI_RES_OK;
}

Expand Down

0 comments on commit e8e010a

Please sign in to comment.