Skip to content

Commit

Permalink
Make preset configurable
Browse files Browse the repository at this point in the history
Instead of hard-coding the preset, this patch allows users to specify
the active and inactive profiles in the configuration.

This fixes #18
  • Loading branch information
lkiesow committed Feb 9, 2024
1 parent 6a37868 commit c8f7d5f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
6 changes: 5 additions & 1 deletion camera-control.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ calendar:
#
# The format of this configuration is:
# <capture-agent-name>:
# - url: http://url.to.first.camera.interface
# - url: http://url.to.camera.interface
# type: `panasonic` or `sony`
# user: username to access the API (optional)
# password: password to access the API (optional)
# preset_active: Camera preset to move to when recording (default: 1)
# preset_inactive: Camera preset to move to when not recording (default: 10)
camera:
15-217-1:
- url: http://camera-panasonic-15-217.virtuos.uni-osnabrueck.de
Expand All @@ -32,6 +34,8 @@ camera:
15-217-2:
- url: http://camera-2-panasonic-15-217.virtuos.uni-osnabrueck.de
type: panasonic
preset_active: 1
preset_inactive: 10
15-217-3:
- url: http://camera-sony-15-217.virtuos.uni-osnabrueck.de
type: sony
Expand Down
27 changes: 16 additions & 11 deletions occameracontrol/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,30 @@ class Camera:
type = None
url = None
user = None
preset_active = 1
preset_inactive = 10

def __init__(self,
agent: Agent,
url: str,
type: str,
user: str | None = None,
password: str | None = None):
password: str | None = None,
preset_active: int = 1,
preset_inactive: int = 10):
self.agent = agent
self.url = url.rstrip('/')
self.type = CameraType[type]
self.user = user
self.password = password
self.preset_active = preset_active
self.preset_inactive = preset_inactive

def __str__(self):
return f"'{self.agent.agent_id}' @ '{self.url}' " \
f"(type: '{self.type.value}', position: {self.position})"

def setPreset(self, preset):
def move_to_preset(self, preset):
if self.type == CameraType.panasonic:
params = {'cmd': f'#R{preset - 1:02}', 'res': 1}
url = f'{self.url}/cgi-bin/aw_ptz'
Expand Down Expand Up @@ -91,15 +97,14 @@ def update_position(self):
logger.info('[%s] No planned events', agent_id)

if event.active():
# TODO: Preset numbers should not be hard-coded
if self.position != 1:
if self.position != self.preset_active:
logger.info('[%s] Event `%s` started', agent_id, event.title)
logger.info('[%s] Moving to preset 1', agent_id)
# Move to recording preset
self.setPreset(1)
logger.info('[%s] Moving to preset %s', agent_id,
self.preset_active)
self.move_to_preset(self.preset_active)

else: # No active event
if self.position != 10:
# Return to netral preset
logger.info('[%s] Returning to preset 10', agent_id)
self.setPreset(10)
if self.position != self.preset_inactive:
logger.info('[%s] Returning to preset %s', agent_id,
self.preset_inactive)
self.move_to_preset(self.preset_inactive)

0 comments on commit c8f7d5f

Please sign in to comment.