Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added basic camera handling #3

Open
wants to merge 5 commits into
base: V5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion scratchgpio_handler5dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import re
import sgh_GPIOController
import sgh_PiGlow
import sgh_RasPiCamera
import sgh_PiMatrix
import sgh_Stepper
import logging
Expand Down Expand Up @@ -1259,6 +1260,7 @@ def run(self):
sghGC.pinUpdate(motorList[listLoop][2],0)



elif (("piglow" in ADDON) and (piglow != None)):
#do PiGlow stuff but make sure PiGlow physically detected

Expand Down Expand Up @@ -1780,6 +1782,10 @@ def run(self):
if self.bFind('ultra2'):
print 'start pinging on', str(7)
sghGC.pinUse[7] = sghGC.PULTRA

elif ("raspicamera" in ADDON):
if self.bFindValue('photo'):
RasPiCamera.take_photo()

elif (("piglow" in ADDON) and (piglow != None)): # Pimoroni PiGlow
#print "processing piglow variables"
Expand Down Expand Up @@ -2456,7 +2462,12 @@ def cleanup_threads(threads):
#PiMatrix.start()
#time.sleep(5)


RasPiCamera = None
try:
RasPiCamera = sgh_RasPiCamera.RasPiCamera()
print RasPiCamera
except:
print "No Camera Detected"

if __name__ == '__main__':
SCRIPTPATH = os.path.split(os.path.realpath(__file__))[0]
Expand Down
57 changes: 57 additions & 0 deletions sgh_RasPiCamera.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python
# sgh_RasPiCamera - control the raspberry pi camera via scratch
#Copyright (C) 2014 by Matt Venn

#This program is free software; you can redistribute it and/or
#modify it under the terms of the GNU General Public License
#as published by the Free Software Foundation; either version 2
#of the License, or (at your option) any later version.

#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.

#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Version = '0.0.1' # 13Apr14


import os,glob

class RasPiCamera:

def __init__(self):
print "pi camera init"
self.num = 0
self.dir = (os.path.expanduser("~") + "/photos/")
try:
os.mkdir(self.dir)
except OSError:
#already exists
pass

photos = glob.glob(self.dir + '*.jpg')
if len(photos):
latest_photo = sorted(photos)[-1]
latest_photo = latest_photo.replace(self.dir,'')
latest_photo = latest_photo.replace('.jpg','')
latest_photo_num = int(latest_photo)
self.num = latest_photo_num + 1

print("starting at %d" % self.num)


def take_photo(self):
photo_file = self.dir + str(self.num) + '.jpg'
os.system("raspistill -n -t 1 -o " + photo_file)
print "photo taken: " + photo_file
self.num += 1

#### end RasPiCamera ###############################################################