Skip to content

Commit

Permalink
Merge branch 'reduce-salt-calls'
Browse files Browse the repository at this point in the history
  • Loading branch information
CameronRP committed Oct 16, 2024
2 parents e343cb9 + 0e7e1dc commit 073d848
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions _release/tc2-hat-attiny.service
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
[Unit]
Description=Cacophony Project ATtiny controller
After=multi-user.target
ConditionPathExists=/etc/salt/minion_id

[Service]
Type=simple
Expand Down
11 changes: 6 additions & 5 deletions cmd/tc2-hat-attiny/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,6 @@ func runMain() error {
onReason = fmt.Sprintf("Staying on because camera has been requested to stay on for %s", durToStr(waitDuration))
}

if waitDuration < saltCommandWaitDuration && shouldStayOnForSalt() {
waitDuration = saltCommandWaitDuration
onReason = "Staying on because salt command is running"
}

// Check if the RP2040 wants the RPi to stay on
if waitDuration <= time.Duration(0) {
val, err := attiny.readRegister(rp2040PiPowerCtrlReg)
Expand All @@ -176,6 +171,12 @@ func runMain() error {
}
}

// Checking if a salt command is running should only be done if needed
if waitDuration < time.Duration(0) && shouldStayOnForSalt() {
waitDuration = saltCommandWaitDuration
onReason = "Staying on because salt command is running"
}

if waitDuration <= time.Duration(0) {
stayOnLock.Lock()
for process, maxTime := range stayOnForProcess {
Expand Down

0 comments on commit 073d848

Please sign in to comment.