FakeGPIO, FakePicamera zum Simulieren auf Entwickler-Maschine

This commit is contained in:
Patrick Haßel 2018-08-15 12:36:42 +02:00
parent 50a3d6f29f
commit 5a460f7b54
5 changed files with 67 additions and 4 deletions

27
FakeGPIO/__init__.py Normal file
View File

@ -0,0 +1,27 @@
BOARD = 1
HIGH = 1
LOW = 0
OUT = 1
IN = 0
FALLING = 0
RISING = 1
def setmode(x):
pass
def setwarnings(x):
pass
def setup(gpio, mode, initial=None):
pass
def output(gpio, state):
pass
def add_event_detect(gpio, edge, callback, bouncetime=None):
pass

BIN
FakeGPIO/__init__.pyc Normal file

Binary file not shown.

28
FakePicamera/__init__.py Normal file
View File

@ -0,0 +1,28 @@
from PIL import Image
class Overlay(object):
def __init__(self):
self.alpha = 0
class PiCamera(object):
def __init__(self):
self.resolution = None
def start_preview(self, *args, **kwargs):
pass
def add_overlay(self, *args, **kwargs):
return Overlay()
def remove_overlay(self, *args, **kwargs):
pass
def capture(self, filename, format, *args, **kwargs):
print("FAKE: capture(%s, %s)" % (filename, format))
img = Image.new("RGB", self.resolution, (255, 255, 255))
img.save(filename, format)
def close(self, *args, **kwargs):
pass

BIN
FakePicamera/__init__.pyc Normal file

Binary file not shown.

View File

@ -1,6 +1,7 @@
#!/usr/bin/python
import datetime
import imp
import inspect
import os
import sys
@ -8,13 +9,20 @@ from math import floor
from shutil import copyfile
from time import sleep
import RPi.GPIO as GPIO
import picamera
import pygame
from PIL import Image
# ~ import server
try:
imp.find_module('RPi')
import RPi.GPIO as GPIO
except ImportError:
import FakeGPIO as GPIO
try:
imp.find_module('picamera')
import picamera
except ImportError:
import FakePicamera as picamera
__all__ = ["monotonic_time"]
@ -222,7 +230,7 @@ def waitForBegin():
def countdown(camera, pad, img):
sleep(PIC_INTERVAL)
o = camera.add_overlay(pad.tostring(), size=img.size)
o = camera.add_overlay(pad.tobytes(), size=img.size)
o.alpha = OVERLAY_ALPHA
o.layer = 3
sleep(TEXT_INTERVAL)