commit 11/12/2015
This commit is contained in:
155
instruments.py
155
instruments.py
@@ -2,73 +2,20 @@ __author__ = 'asc'
|
||||
debug = True
|
||||
from random import random
|
||||
import Adafruit_BMP.BMP085 as BMP085
|
||||
import picamera
|
||||
import configparser
|
||||
import time
|
||||
import logging
|
||||
import base64
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class Barometer_Debug ():
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@property
|
||||
def status (self):
|
||||
return (0, "Barometer functioning properly")
|
||||
|
||||
@property
|
||||
def temperature (self):
|
||||
if self.status[0]:
|
||||
return 'error'
|
||||
|
||||
if debug:
|
||||
temp = random()*100
|
||||
else:
|
||||
raise Exception ('Not Debug')
|
||||
return temp
|
||||
|
||||
@property
|
||||
def pressure (self):
|
||||
if (self.status[0]):
|
||||
return 'error'
|
||||
|
||||
if debug:
|
||||
press = random()
|
||||
else:
|
||||
raise Exception ('Not Debug')
|
||||
return press
|
||||
|
||||
@property
|
||||
def altitude (self):
|
||||
if self.status[0]:
|
||||
return 'error'
|
||||
if debug:
|
||||
alt = random()*100000
|
||||
else:
|
||||
raise Exception ('Not Debug')
|
||||
|
||||
return alt
|
||||
|
||||
class Camera_Debug():
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@property
|
||||
def status (self):
|
||||
return (0, "Camera functioning properly")
|
||||
|
||||
def capture (self):
|
||||
#todo capture image
|
||||
return ({"file":open("image2.jpg", 'rb')})
|
||||
|
||||
#camera debug 2 uses actual camera
|
||||
class Camera_Debug2():
|
||||
def __init__(self, low_quality_resolution=(320,240),
|
||||
class Camera:
|
||||
def __init__(self,
|
||||
low_quality_resolution=(320,240),
|
||||
low_quality_compression_pct=5,
|
||||
high_quality_resolution=(2592,1944),
|
||||
high_quality_compression_pct=85,
|
||||
debug = False,
|
||||
**kwargs):
|
||||
logger.debug("Initializing camera")
|
||||
time.sleep(1)
|
||||
@@ -77,11 +24,13 @@ class Camera_Debug2():
|
||||
self.high_quality_resolution = high_quality_resolution
|
||||
self.high_quality_compression_pct = high_quality_compression_pct
|
||||
self.kwargs=kwargs
|
||||
self._cam = picamera.PiCamera(resolution=high_quality_resolution)
|
||||
# if "vflip" in kwargs.keys():
|
||||
for k in kwargs.keys():
|
||||
setattr(self._cam, k, kwargs.get(k))
|
||||
|
||||
self._debug = debug
|
||||
if self._debug == False:
|
||||
import picamera
|
||||
self._cam = picamera.PiCamera(resolution=high_quality_resolution)
|
||||
# if "vflip" in kwargs.keys():
|
||||
for k in kwargs.keys():
|
||||
setattr(self._cam, k, kwargs.get(k))
|
||||
|
||||
logger.debug("Camera intialized")
|
||||
pass
|
||||
@@ -90,39 +39,56 @@ class Camera_Debug2():
|
||||
def status (self):
|
||||
return (0, "Camera functioning properly")
|
||||
|
||||
def capture (self, no_low_quality=False, no_high_quality=False, **kwargs):
|
||||
def capture (self, name, no_low_quality=False, no_high_quality=False, **kwargs):
|
||||
#todo image adjustments
|
||||
img_hi = None
|
||||
img_lo = None
|
||||
if not no_high_quality:
|
||||
logger.debug('Taking high quality photo')
|
||||
self._cam.capture("temp_img_hi.jpg",
|
||||
resize=self.high_quality_resolution,
|
||||
quality=self.high_quality_compression_pct,
|
||||
# **kwargs
|
||||
)
|
||||
img_hi = open("temp_img_hi.jpg", 'rb')
|
||||
with open("temp_img_hi.jpg", 'rb') as f:
|
||||
img_hi = f.read()
|
||||
logger.debug('High quality photo taken')
|
||||
r = {}
|
||||
if not self._debug:
|
||||
if not no_high_quality:
|
||||
logger.debug('Taking high quality photo')
|
||||
self._cam.capture("temp_img_hi.jpg",
|
||||
resize=self.high_quality_resolution,
|
||||
quality=self.high_quality_compression_pct,
|
||||
# **kwargs
|
||||
)
|
||||
with open("temp_img_hi.jpg", 'rb') as f:
|
||||
# img_hi = base64.b64encode(f.read())
|
||||
img_hi = str(base64.b64encode(f.read()),'ascii')
|
||||
r['hi']=("{}_hi.jpg".format(name), img_hi, "image/jpeg")
|
||||
logger.debug('High quality photo taken')
|
||||
|
||||
if not no_low_quality:
|
||||
time.sleep(1)
|
||||
logger.debug('Taking low quality photo (Resolution: {}, JPEG Quality: {}%)'.format(self.low_quality_resolution, self.low_quality_compression_pct))
|
||||
self._cam.capture("temp_img_lo.jpg",
|
||||
resize=self.low_quality_resolution,
|
||||
quality=self.low_quality_compression_pct,
|
||||
# **kwargs
|
||||
)
|
||||
with open("temp_img_lo.jpg", 'rb') as f:
|
||||
img_lo = f.read()
|
||||
logger.debug('Low quality photo taken')
|
||||
if not no_low_quality:
|
||||
time.sleep(1)
|
||||
logger.debug('Taking low quality photo (Resolution: {}, JPEG Quality: {}%)'.format(self.low_quality_resolution, self.low_quality_compression_pct))
|
||||
self._cam.capture("temp_img_lo.jpg",
|
||||
resize=self.low_quality_resolution,
|
||||
quality=self.low_quality_compression_pct,
|
||||
# **kwargs
|
||||
)
|
||||
with open("temp_img_lo.jpg", 'rb') as f:
|
||||
img_lo = str(base64.b64encode(f.read()),'ascii')
|
||||
# img_lo = str(f.read())
|
||||
r['lo']=("{}_lo.jpg".format(name), img_lo, "image/jpeg")
|
||||
logger.debug('Low quality photo taken')
|
||||
else:
|
||||
if not no_high_quality:
|
||||
with open("temp_img_hi.jpg", 'rb') as f:
|
||||
img_hi = str(base64.b64encode(f.read()),'ascii')
|
||||
# img_hi = str(f.read(),'ascii')
|
||||
r['hi']=("{}_hi.jpg".format(name), img_hi, "image/jpeg")
|
||||
logger.info('High quality photo taken')
|
||||
|
||||
return ({"hi":img_hi,
|
||||
"lo":img_lo})
|
||||
if not no_low_quality:
|
||||
with open("temp_img_lo.jpg", 'rb') as f:
|
||||
img_lo = str(base64.b64encode(f.read()),'ascii')
|
||||
# img_lo = str(f.read())
|
||||
r['lo']=("{}_lo.jpg".format(name), img_lo, "image/jpeg")
|
||||
logger.info('Low quality photo taken')
|
||||
|
||||
#barometerdebug2 uses actual barometer
|
||||
class Barometer_Debug2 ():
|
||||
return r
|
||||
|
||||
class Barometer:
|
||||
def __init__(self):
|
||||
logger.debug("Intializing barometer")
|
||||
self.bmp = BMP085.BMP085()
|
||||
@@ -165,14 +131,17 @@ class Barometer_Debug2 ():
|
||||
alt = self.altitude
|
||||
press = self.pressure
|
||||
temp = self.temperature
|
||||
result = {"altitude":alt,
|
||||
"temperature":temp,
|
||||
"pressure":press,
|
||||
result = {"a":alt,
|
||||
"t":temp,
|
||||
"p":press,
|
||||
}
|
||||
logger.debug("Barometer reads {}".format(result))
|
||||
|
||||
return result
|
||||
|
||||
# class Gps:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user