Updated all log strings to new format
This commit is contained in:
parent
36e837d374
commit
9f5252194a
35 changed files with 121 additions and 715 deletions
|
|
@ -113,10 +113,10 @@ class BaseCamera(metaclass=ABCMeta):
|
|||
|
||||
def close(self):
|
||||
"""Close the BaseCamera and all attached StreamObjects."""
|
||||
logging.info("Closing {}".format(self))
|
||||
logging.info("Closing {}", (self))
|
||||
# Stop worker thread
|
||||
self.stop_worker()
|
||||
logging.info("Closed {}".format(self))
|
||||
logging.info("Closed {}", (self))
|
||||
|
||||
# START AND STOP WORKER THREAD
|
||||
|
||||
|
|
|
|||
|
|
@ -156,10 +156,10 @@ class PiCameraStreamer(BaseCamera):
|
|||
for key in PiCameraStreamer.picamera_settings_keys:
|
||||
try:
|
||||
value = getattr(self.camera, key)
|
||||
logging.debug("Reading PiCamera().{}: {}".format(key, value))
|
||||
logging.debug("Reading PiCamera().{}: {}", key, value)
|
||||
conf_dict["picamera"][key] = value
|
||||
except AttributeError:
|
||||
logging.debug("Unable to read PiCamera attribute {}".format(key))
|
||||
logging.debug("Unable to read PiCamera attribute {}", (key))
|
||||
|
||||
# Include a serialised lens shading table
|
||||
if (
|
||||
|
|
@ -243,26 +243,22 @@ class PiCameraStreamer(BaseCamera):
|
|||
# Set exposure mode
|
||||
if "exposure_mode" in settings_dict:
|
||||
logging.debug(
|
||||
"Applying exposure_mode: {}".format(settings_dict["exposure_mode"])
|
||||
"Applying exposure_mode: {}", (settings_dict["exposure_mode"])
|
||||
)
|
||||
self.camera.exposure_mode = settings_dict["exposure_mode"]
|
||||
|
||||
# Apply gains and let them settle
|
||||
if "analog_gain" in settings_dict:
|
||||
logging.debug(
|
||||
"Applying analog_gain: {}".format(settings_dict["analog_gain"])
|
||||
)
|
||||
logging.debug("Applying analog_gain: {}", (settings_dict["analog_gain"]))
|
||||
set_analog_gain(self.camera, float(settings_dict["analog_gain"]))
|
||||
if "digital_gain" in settings_dict:
|
||||
logging.debug(
|
||||
"Applying digital_gain: {}".format(settings_dict["digital_gain"])
|
||||
)
|
||||
logging.debug("Applying digital_gain: {}", (settings_dict["digital_gain"]))
|
||||
set_digital_gain(self.camera, float(settings_dict["digital_gain"]))
|
||||
|
||||
# Apply shutter speed
|
||||
if "shutter_speed" in settings_dict:
|
||||
logging.debug(
|
||||
"Applying shutter_speed: {}".format(settings_dict["shutter_speed"])
|
||||
"Applying shutter_speed: {}", (settings_dict["shutter_speed"])
|
||||
)
|
||||
self.camera.shutter_speed = int(settings_dict["shutter_speed"])
|
||||
|
||||
|
|
@ -272,17 +268,17 @@ class PiCameraStreamer(BaseCamera):
|
|||
if "awb_gains" in settings_dict:
|
||||
logging.debug("Applying awb_mode: off")
|
||||
self.camera.awb_mode = "off"
|
||||
logging.debug("Applying awb_gains: {}".format(settings_dict["awb_gains"]))
|
||||
logging.debug("Applying awb_gains: {}", (settings_dict["awb_gains"]))
|
||||
self.camera.awb_gains = settings_dict["awb_gains"]
|
||||
elif "awb_mode" in settings_dict:
|
||||
logging.debug("Applying awb_mode: {}".format(settings_dict["awb_mode"]))
|
||||
logging.debug("Applying awb_mode: {}", (settings_dict["awb_mode"]))
|
||||
self.camera.awb_mode = settings_dict["awb_mode"]
|
||||
|
||||
# Handle some properties that can be quickly applied
|
||||
batched_keys = ["framerate", "saturation"]
|
||||
for key in batched_keys:
|
||||
if (key in settings_dict) and hasattr(self.camera, key):
|
||||
logging.debug("Applying {}: {}".format(key, settings_dict[key]))
|
||||
logging.debug("Applying {}: {}", key, settings_dict[key])
|
||||
setattr(self.camera, key, settings_dict[key])
|
||||
|
||||
# Final optional pause to settle
|
||||
|
|
@ -307,7 +303,7 @@ class PiCameraStreamer(BaseCamera):
|
|||
for i in range(2):
|
||||
if np.abs(centre[i] - 0.5) + size / 2 > 0.5:
|
||||
centre[i] = 0.5 + (1.0 - size) / 2 * np.sign(centre[i] - 0.5)
|
||||
logging.info("setting zoom, centre {}, size {}".format(centre, size))
|
||||
logging.info("setting zoom, centre {}, size {}", centre, size)
|
||||
new_fov = (centre[0] - size / 2, centre[1] - size / 2, size, size)
|
||||
self.camera.zoom = new_fov
|
||||
|
||||
|
|
@ -329,13 +325,12 @@ class PiCameraStreamer(BaseCamera):
|
|||
self.preview_active = True
|
||||
except picamerax.exc.PiCameraMMALError as e:
|
||||
logging.error(
|
||||
"Suppressed a MMALError in start_preview. Exception: {}".format(e)
|
||||
"Suppressed a MMALError in start_preview. Exception: {}", (e)
|
||||
)
|
||||
except picamerax.exc.PiCameraValueError as e:
|
||||
logging.error(
|
||||
"Suppressed a ValueError exception in start_preview. Exception: {}".format(
|
||||
e
|
||||
)
|
||||
"Suppressed a ValueError exception in start_preview. Exception: {}",
|
||||
(e),
|
||||
)
|
||||
|
||||
def stop_preview(self):
|
||||
|
|
@ -364,7 +359,7 @@ class PiCameraStreamer(BaseCamera):
|
|||
if not self.record_active:
|
||||
|
||||
# Start the camera video recording on port 2
|
||||
logging.info("Recording to {}".format(output))
|
||||
logging.info("Recording to {}", (output))
|
||||
|
||||
self.camera.start_recording(
|
||||
output,
|
||||
|
|
@ -406,19 +401,19 @@ class PiCameraStreamer(BaseCamera):
|
|||
"""
|
||||
for k in kwargs.keys():
|
||||
logging.warning(
|
||||
"Warning, kwarg %s is invalid for stop_stream_recording.", k
|
||||
"Warning, kwarg {} is invalid for stop_stream_recording.", k
|
||||
)
|
||||
with self.lock:
|
||||
# Stop the camera video recording on port 1
|
||||
try:
|
||||
self.camera.stop_recording(splitter_port=splitter_port)
|
||||
except picamerax.exc.PiCameraNotRecording:
|
||||
logging.info("Not recording on splitter_port {}".format(splitter_port))
|
||||
logging.info("Not recording on splitter_port {}", (splitter_port))
|
||||
else:
|
||||
logging.info(
|
||||
"Stopped MJPEG stream on port {1}. Switching to {0}.".format(
|
||||
self.image_resolution, splitter_port
|
||||
)
|
||||
"Stopped MJPEG stream on port {}. Switching to {}.",
|
||||
splitter_port,
|
||||
self.image_resolution,
|
||||
)
|
||||
|
||||
# Increase the resolution for taking an image
|
||||
|
|
@ -436,7 +431,7 @@ class PiCameraStreamer(BaseCamera):
|
|||
"""
|
||||
for k in kwargs.keys():
|
||||
logging.warning(
|
||||
"Warning, kwarg %s is invalid for stop_stream_recording.", k
|
||||
"Warning, kwarg {} is invalid for stop_stream_recording.", k
|
||||
)
|
||||
with self.lock(timeout=None):
|
||||
# Reduce the resolution for video streaming
|
||||
|
|
@ -470,9 +465,9 @@ class PiCameraStreamer(BaseCamera):
|
|||
)
|
||||
else:
|
||||
logging.debug(
|
||||
"Started MJPEG stream at {} on port {}".format(
|
||||
self.stream_resolution, splitter_port
|
||||
)
|
||||
"Started MJPEG stream at {} on port {}",
|
||||
self.stream_resolution,
|
||||
splitter_port,
|
||||
)
|
||||
|
||||
def capture(
|
||||
|
|
@ -501,7 +496,7 @@ class PiCameraStreamer(BaseCamera):
|
|||
output_object (str/BytesIO): Target object.
|
||||
"""
|
||||
with self.lock:
|
||||
logging.info("Capturing to {}".format(output))
|
||||
logging.info("Capturing to {}", (output))
|
||||
|
||||
# Set resolution and stop stream recording if necessary
|
||||
if not use_video_port:
|
||||
|
|
@ -537,7 +532,7 @@ class PiCameraStreamer(BaseCamera):
|
|||
logging.debug("Creating PiRGBArray")
|
||||
with picamerax.array.PiRGBArray(self.camera) as output:
|
||||
|
||||
logging.info("Capturing to {}".format(output))
|
||||
logging.info("Capturing to {}", (output))
|
||||
|
||||
self.camera.capture(output, format="rgb", use_video_port=True)
|
||||
|
||||
|
|
|
|||
|
|
@ -55,26 +55,17 @@ if __name__ == "__main__":
|
|||
# fix the shutter speed
|
||||
cam.shutter_speed = cam.exposure_speed
|
||||
|
||||
logging.info(
|
||||
"Current a/d gains: {}, {}".format(cam.analog_gain, cam.digital_gain)
|
||||
)
|
||||
logging.info("Current a/d gains: {}, {}", cam.analog_gain, cam.digital_gain)
|
||||
|
||||
logging.info("Attempting to set analogue gain to 1")
|
||||
set_analog_gain(cam, 1)
|
||||
logging.info("Attempting to set digital gain to 1")
|
||||
set_digital_gain(cam, 1)
|
||||
# The old code is left in here in case it is a useful example...
|
||||
# ret = mmal.mmal_port_parameter_set_rational(cam._camera.control._port,
|
||||
# MMAL_PARAMETER_DIGITAL_GAIN,
|
||||
# to_rational(1))
|
||||
# print("Return code: {}".format(ret))
|
||||
|
||||
try:
|
||||
while True:
|
||||
logging.info(
|
||||
"Current a/d gains: {}, {}".format(
|
||||
cam.analog_gain, cam.digital_gain
|
||||
)
|
||||
"Current a/d gains: {}, {}", cam.analog_gain, cam.digital_gain
|
||||
)
|
||||
time.sleep(1)
|
||||
except KeyboardInterrupt:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue