diff --git a/scripts/main.py b/scripts/main.py index aa1fb14..c42f66f 100644 --- a/scripts/main.py +++ b/scripts/main.py @@ -53,6 +53,9 @@ import planktoscope.segmenter # Import the planktonscope LED module import planktoscope.light +# Import the planktonscope uuidName module +import planktoscope.uuidName + # global variable that keeps the wheels spinning run = True @@ -75,18 +78,17 @@ if __name__ == "__main__": # check if gpu_mem configuration is at least 256Meg, otherwise the camera will not run properly with open("/boot/config.txt", "r") as config_file: for i, line in enumerate(config_file): - if line.startswith("gpu_mem"): - if int(line.split("=")[1].strip()) < 256: - logger.error( - "The GPU memory size is less than 256, this will prevent the camera from running properly" - ) - logger.error( - "Please edit the file /boot/config.txt to change the gpu_mem value to at least 256" - ) - logger.error( - "or use raspi-config to change the memory split, in menu 7 Advanced Options, A3 Memory Split" - ) - sys.exit(1) + if line.startswith("gpu_mem") and int(line.split("=")[1].strip()) < 256: + logger.error( + "The GPU memory size is less than 256, this will prevent the camera from running properly" + ) + logger.error( + "Please edit the file /boot/config.txt to change the gpu_mem value to at least 256" + ) + logger.error( + "or use raspi-config to change the memory split, in menu 7 Advanced Options, A3 Memory Split" + ) + sys.exit(1) # Let's make sure the used base path exists img_path = "/home/pi/PlanktonScope/img" @@ -101,8 +103,7 @@ if __name__ == "__main__": # create the path! os.makedirs(export_path) - with open("/sys/firmware/devicetree/base/serial-number", "r") as config_file: - logger.info(f"This PlanktoScope unique ID is {config_file.readline()}") + logger.info(f"This PlanktoScope unique ID is {planktoscope.uuidName.getSerial()}") # Prepare the event for a gracefull shutdown shutdown_event = multiprocessing.Event() diff --git a/scripts/planktoscope/imager.py b/scripts/planktoscope/imager.py index c692c85..c1dd630 100644 --- a/scripts/planktoscope/imager.py +++ b/scripts/planktoscope/imager.py @@ -280,7 +280,6 @@ class ImagerProcess(multiprocessing.Process): logger.error("We can't update the configuration while we are imaging.") # Publish the status "Interrupted" to via MQTT to Node-RED self.imager_client.client.publish("status/imager", '{"status":"Busy"}') - pass elif action == "settings": if self.__imager.state.name is "stop": @@ -327,7 +326,6 @@ class ImagerProcess(multiprocessing.Process): ) # Publish the status "Interrupted" to via MQTT to Node-RED self.imager_client.client.publish("status/imager", '{"status":"Busy"}') - pass elif action != "": logger.warning( @@ -429,7 +427,6 @@ class ImagerProcess(multiprocessing.Process): self.__imager.change(planktoscope.imager_state_machine.Stop) # Set the LEDs as Green planktoscope.light.setRGB(0, 255, 255) - return else: # We have not reached the final stage, let's keep imaging # Set the LEDs as Blue @@ -459,12 +456,11 @@ class ImagerProcess(multiprocessing.Process): # Change state towards Waiting for pump self.__imager.change(planktoscope.imager_state_machine.Waiting) - return - - elif self.__imager.state.name is "waiting": return - elif self.__imager.state.name is "stop": + elif ( + self.__imager.state.name is "waiting" or self.__imager.state.name is "stop" + ): return ################################################################################ diff --git a/scripts/planktoscope/light.py b/scripts/planktoscope/light.py index fe18db1..d4852e0 100644 --- a/scripts/planktoscope/light.py +++ b/scripts/planktoscope/light.py @@ -84,7 +84,7 @@ def light(state): if state == "on": RPi.GPIO.output(21, RPi.GPIO.HIGH) - if state == "off": + elif state == "off": RPi.GPIO.output(21, RPi.GPIO.LOW) diff --git a/scripts/planktoscope/segmenter.py b/scripts/planktoscope/segmenter.py index d3f0607..736dede 100644 --- a/scripts/planktoscope/segmenter.py +++ b/scripts/planktoscope/segmenter.py @@ -341,7 +341,6 @@ class SegmenterProcess(multiprocessing.Process): self.segmenter_client.client.publish( "status/segmenter", '{"status":"Busy"}' ) - pass elif action != "": logger.warning( diff --git a/scripts/planktoscope/stepper.py b/scripts/planktoscope/stepper.py index 7297741..841cc13 100644 --- a/scripts/planktoscope/stepper.py +++ b/scripts/planktoscope/stepper.py @@ -188,7 +188,7 @@ class StepperProcess(multiprocessing.Process): logger.info( "The hardware configuration file doesn't exists, using defaults" ) - configuration = dict() + configuration = {} reverse = False @@ -371,7 +371,7 @@ class StepperProcess(multiprocessing.Process): ) # Validation of inputs - if direction != "UP" and direction != "DOWN": + if direction not in ["UP", "DOWN"]: logger.error("The direction command is not recognised") logger.error("It should be either UP or DOWN") return @@ -431,7 +431,7 @@ class StepperProcess(multiprocessing.Process): logger.info(f"The pump will move {direction} for {volume}mL at {speed}mL/min") # Validation of inputs - if direction != "FORWARD" and direction != "BACKWARD": + if direction not in ["FORWARD", "BACKWARD"]: logger.error("The direction command is not recognised") logger.error("It should be either FORWARD or BACKWARD") return