Skip to content

Commit

Permalink
initial setup on pi sept 2020
Browse files Browse the repository at this point in the history
  • Loading branch information
alzo425 committed Sep 9, 2020
1 parent e353e77 commit 90099f1
Show file tree
Hide file tree
Showing 36 changed files with 1,414 additions and 40 deletions.
70 changes: 70 additions & 0 deletions api/LEDcommunication.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
header('Content-Type: application/json');

require_once('../lib/config.php');

function LEDcommunication($Mode)
{

global $config;

exec("killall -9 python3 > logKill.txt 2>&1 &");

$dir="/var/www/html/api";
chdir($dir);
$cmd = "python3 PhotoBoothLEDsV2.py -$Mode > log.txt 2>&1 &";

exec($cmd, $output, $returnValue);

if ($returnValue) {
die(json_encode([
'error' => 'Execution not possible',
'cmd' => $cmd,
'returnValue' => $returnValue,
'output' => $output,
]));
}

}

//übergabe json an frontend error handling
// no mode provided from frontend, error return
if (!isset($_POST['mode'])) {
die(json_encode([
'error' => 'No mode provided'
]));
}
// choos which mode was provided and forward it to executeable function
if ($_POST['mode'] === 'home'){
LEDcommunication('home');
die(json_encode([
'success' => 'home'
]));
} elseif ($_POST['mode'] === 'flashing'){
LEDcommunication('flashing');
die(json_encode([
'success' => 'flashing'
]));
} elseif ($_POST['mode'] === 'gallery'){
LEDcommunication('gallery');
die(json_encode([
'success' => 'gallery'
]));
} elseif ($_POST['mode'] === 'loading'){
LEDcommunication('loading');
die(json_encode([
'success' => 'loading'
]));
} elseif ($_POST['mode'] === 'picture'){
LEDcommunication('picture');
die(json_encode([
'success' => 'picture'
]));
}


// send imagename to frontend
echo json_encode([
'success' => 'mode'
]);

215 changes: 215 additions & 0 deletions api/PhotoBoothLEDsV2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@

### import libraries
import argparse
import time
import random
import board
import adafruit_ws2801

### Example for a Feather M4 driving 25 12mm leds
odata = board.MOSI_1 #MOSI
oclock = board.SCLK_1 #SCLK
numleds = 41 #Number LEDs
bright = 1.0
leds = adafruit_ws2801.WS2801(oclock, odata, numleds, brightness=bright, auto_write=False)
n_leds = len(leds)

######################### HELPERS ################################

# a random color 0 -> 224
def random_color():
rand = [random.randrange(0, 7) * 36, random.randrange(0, 7) * 36, random.randrange(0, 7) * 36]
return rand

def wheel(pos):
# Input a value 0 to 255 to get a color value.
# The colours are a transition r - g - b - back to r.
if pos < 0 or pos > 255:
return 0, 0, 0
if pos < 85:
return int(255 - pos * 3), int(pos * 3), 0
if pos < 170:
pos -= 85
return 0, int(255 - pos * 3), int(pos * 3)
pos -= 170
return int(pos * 3), 0, int(255 - (pos * 3))

######################### Modes ##################################
def random_mode(frequency,repeats):
for idy in range(repeats):
# fill each led with a random color
for idx in range(n_leds):
leds[idx] = random_color()

# show all leds in led string
leds.show()
time.sleep(frequency)

def loading_mode1(color,frequency, repeats): #only vertical lines were moving up and down
# initialize, all LEDs off
leds.fill(0)
leds.show()
time.sleep(0.05)
move=range(8)

for idy in range(repeats):
for idx in move: #move up
ledright=12+idx
leds[ledright] = color
leds[ledright+1] = color
leds[ledright-1] = 0
leds[ledright-2] = 0

ledleft=40-idx
leds[ledleft] = color
leds[ledleft-1] = color
if idx>0:
leds[ledleft+1] = 0
if idx>1:
leds[ledleft+2] = 0

leds.show()
time.sleep(frequency)

for idx in move: #move down
ledright=20-idx
leds[ledright] = color
leds[ledright-1] = color
leds[ledright+1] = 0
leds[ledright+2] = 0

ledleft=32+idx
leds[ledleft] = color
leds[ledleft+1] = color
leds[ledleft-1] = 0
leds[ledleft-2] = 0

leds.show()
time.sleep(frequency)

def loading_mode2(color,frequency,repeats): # loading circle
leds.fill(0)
leds.show()
time.sleep(0.05)
for idy in range(repeats):
for idx in range(n_leds):
leds[idx] = color
leds.show()
time.sleep(frequency)
for idx in range(n_leds):
leds[idx] = 0
leds.show()
time.sleep(frequency)

def flash_mode(frequency, flashes,color):
for i in range(flashes):
leds.fill(color)
leds.show()
time.sleep(frequency)
leds.fill(0)
leds.show()
time.sleep(frequency)
leds.fill(color)
leds.show()
time.sleep(1000)

def rainbow_mode(frequency):
for i in range(256):
i = (i + 1) % 256 # run from 0 to 255
leds.fill(wheel(i))
leds.show()
time.sleep(frequency)

def rainbowCycle_mode(frequency,repeats=1):
for idy in range(repeats):
for j in range(256): # one cycle of all 256 colors in the wheel
for i in range(numleds):
leds[i] =wheel(((i * 256 // numleds) + j) % 256)
leds.show()
time.sleep(frequency)

def brightness_change( frequency, color, step):
if step > 0:
dr=color[0]/step
dg=color[1]/step
db=color[2]/step
# else
#error out
r = 0
g = 0
b = 0
for i in range(step):
time.sleep(frequency)
r = int(i*dr)
g = int(i*dg)
b = int(i*db)
leds.fill([r,g,b])
leds.show()
r0 =color[0]
g0 =color[1]
b0 =color[2]
leds.fill(color)
for i in range(step+1):
r = int(r0-i*dr)
g = int(g0-i*dg)
b = int(b0-i*db)
leds.fill([r,g,b])
leds.show()
time.sleep(frequency)



######################### MAIN LOOP ##############################
# Main program logic follows:
if __name__ == '__main__':
# Process arguments
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--clear', action='store_true', help='clear the display on exit')
parser.add_argument('-home', action='store_true', help='home mode activated for led stripe')
parser.add_argument('-loading', action='store_true', help='home mode activated for led stripe')
parser.add_argument('-flashing', action='store_true', help='home mode activated for led stripe')
parser.add_argument('-gallery', action='store_true', help='home mode activated for led stripe')
parser.add_argument('-picture', action='store_true', help='home mode activated for led stripe')

args = parser.parse_args()

print ('Press Ctrl-C to quit.')
if not args.clear:
print('Use "-c" argument to clear LEDs on exit')

try:
while True:


if args.home:
#Rainbow Mode
rainbow_mode(0.05)
#Rainbow Cycle
rainbowCycle_mode(0.02,5)


if args.gallery:
#Brightnes change
brightness_change(0.1,random_color(),50)

if args.loading:
#loading mode 2
loading_mode2(random_color(),0.05,1)

if args.flashing:
#Flash mode
flash_mode(0.5,5,random_color())

if args.picture:
brightness_change(0.1,[255,255,255],10)

#loading mode 1
#loading_mode1(random_color(),0.1,2)
# Random Mode
#random_mode(0.25,5)


except KeyboardInterrupt:
if args.clear:
leds.fill(0)

7 changes: 6 additions & 1 deletion api/applyEffects.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
$collageSrcImagePaths[] = $collageBasename . '-' . $i . '.jpg';
}

if (!createCollage($collageSrcImagePaths, $filename_tmp, $config['take_frame'], $config['take_frame_path'])) {
if (!createCollage($collageSrcImagePaths, $filename_tmp, $config['take_frame'], $config['collage_Frame_2x2'], $config['collage_layout'], $config['collage_background'])) {
die(json_encode([
'error' => 'Could not create collage'
]));
Expand Down Expand Up @@ -94,6 +94,11 @@
$chromaCopyResource = resizeImage($imageResource, 1500, 1000);
imagejpeg($chromaCopyResource, $filename_keying, $config['jpeg_quality_chroma']);
imagedestroy($chromaCopyResource);
// AZ insert chroma keying effect apply here

// echo "<script type="text/javascript" src="resources/js/chromakeying.js">setBackgroundImage(<InsertBackground>)</script>"
//'<img src="'$filename_keying'" class="backgroundPreview" onclick="setBackgroundImage(<InsertBackground>)">';

}

// image scale, create thumbnail
Expand Down
2 changes: 2 additions & 0 deletions api/log.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Der Befehl "python3" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.
2 changes: 2 additions & 0 deletions api/logKill.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Der Befehl "killall" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.
17 changes: 17 additions & 0 deletions api/print.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
)
);

// writeToDB($filename); // AZ Database

die(json_encode([
'status' => 'ok',
'msg' => $printimage || '',
Expand Down Expand Up @@ -194,3 +196,18 @@ function ResizeCropImage($max_width, $max_height, $source_file, $dst_dir, $quali
imagedestroy($src_img);
}
}
/*
function writeToDB($filename){ // AZ Database
# POST TO DB
$postRequest = array(
'api_key' => 'PostPhotoData',
'sensor' => 'print',
'printName' => $filename
);
$cURLConnection = curl_init('http://photokaestchen/api/post-esp-data.php'); // AZ To be changed
curl_setopt($cURLConnection, CURLOPT_POSTFIELDS, $postRequest);
curl_setopt($cURLConnection, CURLOPT_RETURNTRANSFER, true);
$apiResponse = curl_exec($cURLConnection);
curl_close($cURLConnection);
} */

26 changes: 24 additions & 2 deletions api/takePic.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ function takePicture($filename)
$filename = $basename . '-' . $number . '.jpg';

takePicture($filename);

/*
if ($number == 3) { // AZ Database
writeToDB($file);
}*/

die(json_encode([
'success' => 'collage',
'file' => $file,
Expand All @@ -103,9 +107,27 @@ function takePicture($filename)
'error' => 'Invalid photo style provided',
]));
}

//writeToDB($file);

// send imagename to frontend
echo json_encode([
'success' => 'image',
'file' => $file,
]);

/*
function writeToDB($file) // AZ Database
{
# POST TO DB
$postRequest = array(
'api_key' => 'PostPhotoData',
'sensor' => 'photo',
'photoName' => $file
);
$cURLConnection = curl_init('http://photokaestchen/api/post-esp-data.php');
curl_setopt($cURLConnection, CURLOPT_POSTFIELDS, $postRequest);
curl_setopt($cURLConnection, CURLOPT_RETURNTRANSFER, true);
$apiResponse = curl_exec($cURLConnection);
curl_close($cURLConnection);
}*/

Loading

0 comments on commit 90099f1

Please sign in to comment.