Skip to content

Commit

Permalink
Move voltage validation from main to witty pi file
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleshot committed Apr 13, 2024
1 parent 1e167b3 commit a505d37
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ wget -O - https://raw.githubusercontent.com/Eagleshot/GlacierCam/main/updateScri
## Software
- [ ] Automatically set camera to reboot when power is on again
- [ ] Add log level settings
- [ ] Improved settings validation
- [X] Improved settings validation
- [x] Code review by Philip
- [x] Improve the format of saved data -> e.g. use .yaml instead of a csv file so additional data can easily be added or different data versions can be used in future software
- [ ] Enable watchdog
Expand Down
15 changes: 5 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,13 @@ def get_cpu_serial():
###########################
# Set voltage thresholds
###########################

try:
# If settings low voltage threshold exists
if 2.0 <= settings.get("low_voltage_threshold") <= 25.0 or settings.get("low_voltage_threshold") == 0:
if settings.get("low_voltage_threshold"):
wittyPi.set_low_voltage_threshold(settings.get("low_voltage_threshold"))

# If settings recovery voltage threshold exists
if 2.0 <= settings.get("recovery_voltage_threshold") <= 25.0 or settings.get("recovery_voltage_threshold") == 0:
if settings.get("recovery_voltage_threshold"):
# Recovery voltage threshold must be equal or greater than low voltage threshold
if settings.get("recovery_voltage_threshold") < settings.get("low_voltage_threshold"):
settings.set("recovery_voltage_threshold", settings.get("low_voltage_threshold"))
Expand Down Expand Up @@ -340,17 +339,13 @@ def get_cpu_serial():
logging.warning("Could not append new measurements to log: %s", str(e))

###########################
# Upload diagnostics data
# Upload extended diagnostics data
###########################
try:
# fileserver.append_file("diagnostics.csv", "", FILE_PATH)

# Upload WittyPi diagnostics
if settings.get("uploadWittyPiDiagnostics") and CONNECTED_TO_SERVER:

fileserver.append_file("wittyPi.log", f"{FILE_PATH}wittypi/") # Witty Pi log
fileserver.append_file("schedule.log", f"{FILE_PATH}wittypi/") # Witty Pi schedule

fileserver.append_file("wittyPi.log", f"{FILE_PATH}wittypi/")
fileserver.append_file("schedule.log", f"{FILE_PATH}wittypi/")
except Exception as e:
logging.warning("Could not upload diagnostics data: %s", str(e))

Expand Down
30 changes: 20 additions & 10 deletions witty_pi_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,17 @@ def get_recovery_voltage_threshold(self) -> float:
def set_low_voltage_threshold(self, voltage: float) -> float:
'''Sets the low voltage threshold from the Witty Pi 4'''
try:
if voltage != self.get_low_voltage_threshold():
low_voltage_threshold = self.run_command(f"set_low_voltage_threshold {int(voltage*10)}")
logging.info("Set low voltage threshold to: %s V", voltage)
return low_voltage_threshold
if 2.0 <= voltage <= 25.0 or voltage == 0:
if voltage != self.get_low_voltage_threshold():
low_voltage_threshold = self.run_command(f"set_low_voltage_threshold {int(voltage*10)}")
logging.info("Set low voltage threshold to: %s V", voltage)
return low_voltage_threshold

logging.info("Low voltage threshold already set to: %s V", voltage)

else:
logging.error("Voltage must be between 2.0 and 25.0 V (or 0 to disable).")

logging.info("Low voltage threshold already set to: %s V", voltage)
return voltage

except Exception as e:
Expand All @@ -134,12 +139,17 @@ def set_low_voltage_threshold(self, voltage: float) -> float:
def set_recovery_voltage_threshold(self, voltage: float) -> float:
'''Sets the recovery voltage threshold from the Witty Pi 4'''
try:
if voltage != self.get_recovery_voltage_threshold():
recovery_voltage_threshold = self.run_command(f"set_recovery_voltage_threshold {int(voltage*10)}")
logging.info("Set recovery voltage threshold to: %s V", voltage)
return recovery_voltage_threshold
if 2.0 <= voltage <= 25.0 or voltage == 0:
if voltage != self.get_recovery_voltage_threshold():
recovery_voltage_threshold = self.run_command(f"set_recovery_voltage_threshold {int(voltage*10)}")
logging.info("Set recovery voltage threshold to: %s V", voltage)
return recovery_voltage_threshold

logging.info("Recovery voltage threshold already set to: %s V", voltage)

logging.info("Recovery voltage threshold already set to: %s V", voltage)
else:
logging.error("Voltage must be between 2.0 and 25.0 V (or 0 to disable).")

return voltage

except Exception as e:
Expand Down

0 comments on commit a505d37

Please sign in to comment.