diff --git a/backend/app/handlers/SocketHandler.py b/backend/app/handlers/SocketHandler.py index 3b2dea23d..80aaf08c0 100644 --- a/backend/app/handlers/SocketHandler.py +++ b/backend/app/handlers/SocketHandler.py @@ -25,14 +25,18 @@ class ChameleonWebSocket(tornado.websocket.WebSocketHandler): self.init_cameras_settings() def init_cameras_settings(self): + if os.path.exists(self.cams_path): + for curr_dir in os.listdir(self.cams_path): + pipelines = {} + for file in os.listdir(os.path.join(self.cams_path, curr_dir)): + with open(os.path.join(self.cams_path, curr_dir, file)) as pipeline: + pipelines[os.path.splitext(file)[0]] = json.load(pipeline) - for curr_dir in os.listdir(self.cams_path): - pipelines = {} - for file in os.listdir(os.path.join(self.cams_path, curr_dir)): - with open(os.path.join(self.cams_path, curr_dir, file)) as pipeline: - pipelines[os.path.splitext(file)[0]] = json.load(pipeline) - - self.cams[curr_dir] = pipelines + self.cams[curr_dir] = pipelines + else: + self.create_new_cam("cam1") + self.settings["curr_camera"] = "cam1" + self.settings["curr_pipeline"] = "pipeline1" def init_actions(self): self.actions["camera"] = self.change_curr_camera @@ -124,7 +128,12 @@ class ChameleonWebSocket(tornado.websocket.WebSocketHandler): def save_cameras(self): for cam in self.cams: for pipeline in self.cams[cam]: - with open(os.path.join(self.cams_path, cam, pipeline + '.json'), 'w') as pipeline_file: + path = os.path.join(self.cams_path, cam) + + if not os.path.exists(path): + os.makedirs(path) + + with open(os.path.join(path, pipeline + '.json'), 'w+') as pipeline_file: json.dump(self.cams[cam][pipeline], pipeline_file) def save_settings(self): diff --git a/backend/settings/cams/cam1/pipeline1.json b/backend/settings/cams/cam1/pipeline1.json index 89f5e7a95..70c73a717 100644 --- a/backend/settings/cams/cam1/pipeline1.json +++ b/backend/settings/cams/cam1/pipeline1.json @@ -1 +1 @@ -{"exposure": 32, "brightness": 36, "hue": [10, 45], "orientation": "Normal", "camera": "3", "resolution": "Normal"} \ No newline at end of file +{"exposure": 50, "brightness": 50} \ No newline at end of file diff --git a/backend/settings/cams/cam1/pipeline2.json b/backend/settings/cams/cam1/pipeline2.json deleted file mode 100644 index 42df9d775..000000000 --- a/backend/settings/cams/cam1/pipeline2.json +++ /dev/null @@ -1 +0,0 @@ -{"exposure": 23, "brightness": 12} \ No newline at end of file diff --git a/backend/settings/cams/cam1/pipeline5.json b/backend/settings/cams/cam1/pipeline5.json deleted file mode 100644 index 70c73a717..000000000 --- a/backend/settings/cams/cam1/pipeline5.json +++ /dev/null @@ -1 +0,0 @@ -{"exposure": 50, "brightness": 50} \ No newline at end of file diff --git a/backend/settings/cams/cam2/pipeline1.json b/backend/settings/cams/cam2/pipeline1.json deleted file mode 100644 index c9ea90ea2..000000000 --- a/backend/settings/cams/cam2/pipeline1.json +++ /dev/null @@ -1 +0,0 @@ -{"exposure": 0, "brightness": 100} \ No newline at end of file diff --git a/backend/settings/cams/cam2/pipeline2.json b/backend/settings/cams/cam2/pipeline2.json deleted file mode 100644 index e4059c97c..000000000 --- a/backend/settings/cams/cam2/pipeline2.json +++ /dev/null @@ -1 +0,0 @@ -{"exposure": 2, "brightness": 3} \ No newline at end of file