first attempt to add generic raspimjpeg worker
This commit is contained in:
parent
a28c9168ed
commit
30bb211324
8 changed files with 51 additions and 21 deletions
48
phytopi/camera/camera.py
Normal file
48
phytopi/camera/camera.py
Normal file
|
@ -0,0 +1,48 @@
|
|||
import io
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import signal
|
||||
|
||||
from phytopi import db, models, app
|
||||
|
||||
class CameraWorker(object):
|
||||
def __init__(self, pidfile='/tmp/raspimjpeg.pid', executable='/usr/local/bin/raspimjpeg', fifo='/dev/shm/mjpeg/mjpeg_fifo', app=None):
|
||||
self.pidfile = pidfile
|
||||
self.executable = executable
|
||||
self.fifo = fifo
|
||||
self.proc = None
|
||||
self.pid = None
|
||||
self.app = app
|
||||
|
||||
def start(self):
|
||||
# create FIFO if not existent
|
||||
if not os.path.isfile(self.fifo):
|
||||
os.mkfifo(self.fifo)
|
||||
|
||||
# check if process is already running
|
||||
if os.path.isfile(self.pidfile):
|
||||
with open(self.pidfile) as fh:
|
||||
self.pid = int(fh.read())
|
||||
|
||||
# if not, spawn new process and create pid file
|
||||
self.proc = subprocess.Popen(self.executable, stdout=subprocess.PIPE)
|
||||
self.pid = self.proc.pid
|
||||
with open(self.pidfile) as fh:
|
||||
fh.write(self.pid)
|
||||
|
||||
def stop(self):
|
||||
# if process was spawned by this instance, killing is easy
|
||||
if self.proc:
|
||||
self.proc.kill()
|
||||
else:
|
||||
# otherwise send SIGTERM to pid
|
||||
os.kill(self.pid, signal.SIGTERM)
|
||||
os.unlink(self.fifo)
|
||||
|
||||
def send_cmd(self, cmd):
|
||||
with open(self.fifo, 'w') as fh:
|
||||
fh.write(cmd)
|
||||
|
||||
def read_output(self):
|
||||
return self.proc.stdout.readlines()
|
Binary file not shown.
|
@ -1,6 +1,6 @@
|
|||
from flask import render_template, Response, flash, jsonify, request, stream_with_context, send_file
|
||||
|
||||
from phytopi.camera.camera_pi import Camera
|
||||
from phytopi.camera.camera import CameraWorker
|
||||
from phytopi.forms import CameraSettingsForm
|
||||
|
||||
from phytopi import app
|
||||
|
@ -10,7 +10,8 @@ from phytopi.models import Dataset
|
|||
from io import BytesIO
|
||||
import zipstream
|
||||
|
||||
camera = Camera(app=app)
|
||||
camera = CameraWorker(app=app)
|
||||
camera.start()
|
||||
# camera = app.camera
|
||||
save_frames = False
|
||||
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
alembic>=1.0.1
|
||||
Click>=7.0
|
||||
Flask>=1.0.2
|
||||
Flask-Migrate>=2.3.0
|
||||
Flask-SQLAlchemy>=2.3.2
|
||||
Flask-WTF>=0.14.2
|
||||
itsdangerous>=1.1.0
|
||||
Jinja2>=2.10
|
||||
Mako>=1.0.7
|
||||
MarkupSafe>=1.0
|
||||
picamera>=1.13
|
||||
Pillow>=5.3.0
|
||||
python-dateutil>=2.7.5
|
||||
python-editor>=1.0.3
|
||||
six>=1.11.0
|
||||
SQLAlchemy>=1.2.12
|
||||
Werkzeug>=0.14.1
|
||||
WTForms>=2.2.1
|
||||
zipstream>=1.1.4
|
Loading…
Add table
Reference in a new issue