Skip to content

Commit

Permalink
Add interlock state to GUI gray out buttons and to CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
trappitsch committed Jan 11, 2024
1 parent bd78923 commit 64656e9
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 14 deletions.
6 changes: 3 additions & 3 deletions controller/src/main/python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ def read_all(self):
ch.set_status_from_read(read)

# software lockout
self.software_lockout()
self.lockouts()

def save(self, ask_fname: bool = False):
"""Save the current configuration to default json file.
Expand Down Expand Up @@ -572,12 +572,12 @@ def set_all_channels(self, state: bool):
):
ch.set_status_custom(False)

def software_lockout(self):
def lockouts(self):
"""Activate/deactivate buttons depending on software lockout state."""
if self.dummy:
status = False
else:
status = self.comm.software_lockout
status = self.comm.interlock_state or self.comm.software_lockout

buttons_to_toggle = [self.all_on_button] # non-widget buttons to toggle

Expand Down
5 changes: 5 additions & 0 deletions controller_cli/controller_cli/device_comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ def identify(self):
return "DigIOBox Dummy"
return self.query("*IDN?")

@property
def interlock_state(self) -> bool:
"""Read if software lockout is on."""
return bool(int(self.query("INTERLOCKState?")))

@property
def num_channels(self) -> int:
"""Get / Set number of available channels.
Expand Down
11 changes: 10 additions & 1 deletion controller_cli/tests/test_device_comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,20 @@ def test_all_off():
dev.all_off()


@pytest.mark.parametrize("state", [0, 1])
def test_interlock_state(state):
"""Read state of the interlock."""
with expected_communication(
command=["INTERLOCKState?"], response=[f"{state}"]
) as dev:
assert dev.interlock_state == bool(state)


@pytest.mark.parametrize("state", [0, 1])
def test_software_lockout(state):
"""Read state of software lockout."""
with expected_communication(command=["SWLockout?"], response=[f"{state}"]) as dev:
assert dev.software_lockout == bool(state)
assert dev.lockouts == bool(state)


# CHANNEL PROPERTIES #
Expand Down
26 changes: 19 additions & 7 deletions firmware/DigOutBox_fw_v020/DigOutBox_fw_v020.ino
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ void setup() {
DigIOBox.RegisterCommand(F("DOut#"), &SetDigIO);
DigIOBox.RegisterCommand(F("ALLDOut?"), &GetAllDigIO);
DigIOBox.RegisterCommand(F("ALLOFF"), &AllOff);
DigIOBox.RegisterCommand(F("SWLockout?"), &GetSoftwareLockoutState);
DigIOBox.RegisterCommand(F("INTERLOCKState?"), &GetInterlockState); // returns 1 if interlocked
DigIOBox.RegisterCommand(F("SWLockout?"), &GetSoftwareLockoutState); // returns 1 if software is locked

// Output and LED setups
for (int it = 0; it < numOfChannels; it++) {
Expand All @@ -57,7 +58,7 @@ void setup() {
AllOff();

// Interlock setup
if (EnableInterlock) {
if (EnableInterlock == true) {
pinMode(InterlockPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(InterlockPin), interlock, CHANGE);
// check interlock status and activate / deactivate remote
Expand Down Expand Up @@ -104,12 +105,12 @@ void software_lockout() {
// Lock the software out with the remote
if (not SoftwareLockoutToggle) {
SoftwareLockoutToggle = true;
if (debug) {
if (debug == true) {
Serial.println("Software lockout activated.");
}
}
else {
if (debug) {
if (debug == true) {
Serial.print("Software lockout counter: ");
Serial.println(SoftwareLockoutCounter);
}
Expand All @@ -122,15 +123,15 @@ void software_lockout() {
else {
// click was not in time
if (millis() - SoftwareLockoutClock > SoftwareLockoutDoubleClickTime) {
if (debug) {
if (debug == true) {
Serial.println("Assuming this is the first click.");
}
SoftwareLockoutCounter = 1;
SoftwareLockoutClock = millis();
}
// second click -> deactivate SoftwareLockout
else {
if (debug) {
if (debug == true) {
Serial.println("Deactivating software lockout.");
}
SoftwareLockoutCounter = 0;
Expand Down Expand Up @@ -239,7 +240,7 @@ void ListenForRemote() {
}
}

if (debug) {
if (debug == true) {
Serial.print("Valid RF Remote code received: ");
Serial.print(received_value);
Serial.print(" / Channel associated: ");
Expand Down Expand Up @@ -288,6 +289,17 @@ void GetSoftwareLockoutState(SCPI_C commands, SCPI_P parameters, Stream& interfa

}

void GetInterlockState(SCPI_C commands, SCPI_P parameters, Stream& interface) {
// Get the state of the SoftwareLockoutToggle. return 0 if off, 1 if on.
if (IsInterlocked) {
interface.println(1);
}
else {
interface.println(0);
}

}

void SetChannel(int ch, int state) {
// only set a channel if not interlocked
if (IsInterlocked == false) {
Expand Down
2 changes: 1 addition & 1 deletion firmware/DigOutBox_fw_v020/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const int rf_delay = 500;
const int InterlockPin = 3;

// Turn interlock mode on (true) or off (false)
const bool EnableInterlock = true;
const bool EnableInterlock = false;

// Software lockout time window (in ms) for double click (second click has to come after `rf_delay`!)
const unsigned long SoftwareLockoutDoubleClickTime = 3000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const int rf_delay = 500;
const int InterlockPin = 3;

// Turn interlock mode on (true) or off (false)
const bool EnableInterlock = true;
const bool EnableInterlock = false;

// Software lockout time window (in ms) for double click (second click has to come after `rf_delay`!)
const unsigned long SoftwareLockoutDoubleClickTime = 3000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const int rf_delay = 500;
const int InterlockPin = 3;

// Turn interlock mode on (true) or off (false)
const bool EnableInterlock = true;
const bool EnableInterlock = false;

// Software lockout time window (in ms) for double click (second click has to come after `rf_delay`!)
const unsigned long SoftwareLockoutDoubleClickTime = 3000;
Expand Down

0 comments on commit 64656e9

Please sign in to comment.