Compare commits
20 Commits
f9da3a45f0
...
master
Author | SHA1 | Date | |
---|---|---|---|
b9f0c632d1 | |||
74d7354593 | |||
c996650414 | |||
653257b787 | |||
15e79e67df | |||
a58f11ac0e | |||
56d4b8c371 | |||
3d14ba3dd6 | |||
1dd5117e1f | |||
e784983f99 | |||
b60b02e223 | |||
1bcb39820c | |||
573f300fea | |||
0f9dc7a886 | |||
a48c3ab596 | |||
df590dbf19 | |||
7ce521fb89 | |||
5d0764988f | |||
c9c0dd14b5 | |||
581fcd8c85 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
audio
|
||||
videos
|
||||
images
|
||||
images
|
||||
__pycache__
|
70
controller/main.py
Normal file
70
controller/main.py
Normal file
@@ -0,0 +1,70 @@
|
||||
from gpiozero import LED, Button
|
||||
from time import sleep
|
||||
import paho.mqtt.client as mqtt
|
||||
|
||||
red = LED(19)
|
||||
blue = LED(26)
|
||||
green = LED(13)
|
||||
button = Button(5)
|
||||
|
||||
def main ():
|
||||
idle = False
|
||||
while True:
|
||||
if not idle:
|
||||
send_idle()
|
||||
idle = True
|
||||
sleep(5)
|
||||
red.on()
|
||||
send_stop()
|
||||
if buttonWait():
|
||||
red.off()
|
||||
idle = False
|
||||
playaudio()
|
||||
displaytext()
|
||||
sleep(5)
|
||||
playaudio()
|
||||
displaytext()
|
||||
green.on()
|
||||
printquestion()
|
||||
sleep(1)
|
||||
green.off()
|
||||
red.off()
|
||||
|
||||
def buttonWait():
|
||||
for i in range(500):
|
||||
if button.value:
|
||||
print("Button pressed")
|
||||
return True
|
||||
sleep(0.01)
|
||||
return False
|
||||
|
||||
def send_idle():
|
||||
print("Idle")
|
||||
client = mqtt.Client()
|
||||
client.connect("localhost", 1883, 60)
|
||||
client.publish("slave", "idle")
|
||||
|
||||
def playaudio():
|
||||
print("Play audio")
|
||||
client = mqtt.Client()
|
||||
client.connect("localhost", 1883, 60)
|
||||
client.publish("slave", "audio")
|
||||
|
||||
|
||||
def playvideo():
|
||||
pass
|
||||
|
||||
def displaytext():
|
||||
print("Display text")
|
||||
|
||||
def printquestion():
|
||||
print("Question")
|
||||
client = mqtt.Client()
|
||||
client.connect("localhost", 1883, 60)
|
||||
client.publish("print", "question")
|
||||
|
||||
def send_stop():
|
||||
pass
|
||||
|
||||
|
||||
main()
|
BIN
controller/press.png
Normal file
BIN
controller/press.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 30 KiB |
BIN
printer/SilkRemington-Regular.otf
Normal file
BIN
printer/SilkRemington-Regular.otf
Normal file
Binary file not shown.
55
printer/actions.txt
Normal file
55
printer/actions.txt
Normal file
@@ -0,0 +1,55 @@
|
||||
ask a stranger for a dance
|
||||
ask a stranger what their biggest fear is
|
||||
smell a stranger’s hair
|
||||
show off your impression of a duck
|
||||
spank a consenting individual
|
||||
kiss a consenting individual
|
||||
reveal a secret
|
||||
tell a creative story
|
||||
compliment someone on their smile
|
||||
hold Tanos hands
|
||||
request a 20 second eye gaze
|
||||
serve a drink for someone from another faction
|
||||
ask a stranger for a dance
|
||||
ask a stranger what their biggest fear is
|
||||
smell a stranger’s hair
|
||||
spank a consenting individual
|
||||
kiss a consenting individualas
|
||||
reveal a secret
|
||||
do a handstand across the dance floor
|
||||
tell a creative story
|
||||
compliment someone on their smile
|
||||
request a 20 second eye gaze
|
||||
change character
|
||||
find an animal to stroke
|
||||
make an instrument out of something odd
|
||||
tell a stranger that you love them
|
||||
tell a stranger that you love yourself
|
||||
start a game of leapfrog
|
||||
hold someones hand
|
||||
bow to someone respectable
|
||||
embrace yo-ur spirit animal
|
||||
give someone a foot massage
|
||||
learn to code
|
||||
warn someone of a grave danger
|
||||
ask a question with no answer
|
||||
be a fairy
|
||||
find the snail
|
||||
press any key to continue
|
||||
swap an object with a stranger
|
||||
go for an adventure
|
||||
find sally the snail
|
||||
find something furry and appreciate it
|
||||
introduce two strangers to each other
|
||||
nominate a stranger to be your friends
|
||||
wingman someone that could use your help
|
||||
give someone a shoulder rub
|
||||
make it a party
|
||||
serve someone a drink from another faction
|
||||
run on the spot for 1 minute
|
||||
find the pharoah
|
||||
hug a consenting stranger
|
||||
hug 3 consenting people in a row
|
||||
strut around
|
||||
consetually give someone a hug
|
||||
tell someone they are the most beautiful person you have ever seen
|
29
printer/adverbs.txt
Normal file
29
printer/adverbs.txt
Normal file
@@ -0,0 +1,29 @@
|
||||
graciously
|
||||
heroically
|
||||
confidently
|
||||
ferociously
|
||||
happily
|
||||
emotionally
|
||||
spritely
|
||||
majestically
|
||||
boldly
|
||||
brightly
|
||||
cheerfully
|
||||
eagerly
|
||||
elegantly
|
||||
gleefully
|
||||
innocently
|
||||
politely
|
||||
powerfully
|
||||
victoriously
|
||||
boastfully
|
||||
occasionally
|
||||
casually
|
||||
mysteriously
|
||||
seriously
|
||||
dramatically
|
||||
flamboyantly
|
||||
sexually
|
||||
flirtatiously
|
||||
awkwardly
|
||||
saintly
|
BIN
printer/image.jpg
Normal file
BIN
printer/image.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 171 KiB |
BIN
printer/image2.jpg
Normal file
BIN
printer/image2.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 257 KiB |
7
printer/locations.txt
Normal file
7
printer/locations.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
on the steps
|
||||
outdoors
|
||||
in the boiler room
|
||||
by the DJ
|
||||
in a dark area
|
||||
in the auditorium
|
||||
by a window
|
28
printer/press.py
Normal file
28
printer/press.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import StarTSPImage
|
||||
from PIL import Image, ImageDraw, ImageFont, ImageOps
|
||||
import textwrap
|
||||
import random
|
||||
|
||||
im = Image.new('RGB', (500, 1600), color = 'white')
|
||||
# f = ImageFont.load_default()
|
||||
f = ImageFont.truetype("printer/SilkRemington-Regular.otf", 100)
|
||||
txt=Image.new('L', (1600,500))
|
||||
d = ImageDraw.Draw(txt)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
d.text((50, 50), "(When flashing)", font=f, fill=255)
|
||||
w=txt.rotate(-90, expand=1)
|
||||
|
||||
im.paste( ImageOps.colorize(w, (0,0,0), (0,0,0)), (-100, 60), w)
|
||||
|
||||
im.show()
|
||||
# im.save("image_tmp.jpg")
|
||||
|
||||
raster = StarTSPImage.imageToRaster(im, cut=True)
|
||||
printer = open('/dev/usb/lp0', "wb")
|
||||
printer.write(raster)
|
@@ -1,5 +1,7 @@
|
||||
import StarTSPImage
|
||||
from PIL import Image, ImageDraw
|
||||
from PIL import Image, ImageDraw, ImageFont, ImageOps
|
||||
import textwrap
|
||||
import random
|
||||
|
||||
|
||||
|
||||
@@ -15,27 +17,68 @@ def on_connect(client, userdata, flags, rc):
|
||||
|
||||
# The callback for when a PUBLISH message is received from the server.
|
||||
def on_message(client, userdata, msg):
|
||||
print(msg.topic+" "+str(msg.payload))
|
||||
image = Image.new('RGB', (2000, 2000), color='White')
|
||||
draw = ImageDraw.Draw(image)
|
||||
draw.ellipse((0, 0, 500, 500), fill='Black')
|
||||
draw.ellipse((10, 10, 490, 490), fill='White')
|
||||
image.show()
|
||||
image.save("image.jpg")
|
||||
print("Print")
|
||||
with open("printer/locations.txt") as locations:
|
||||
lines = locations.read().splitlines()
|
||||
location = random.choice(lines)
|
||||
|
||||
# raster = StarTSPImage.imageToRaster(image, cut=True)
|
||||
with open("printer/actions.txt") as actions:
|
||||
lines = actions.read().splitlines()
|
||||
action = random.choice(lines)
|
||||
|
||||
with open("printer/adverbs.txt") as adverb:
|
||||
lines = adverb.read().splitlines()
|
||||
adverb = random.choice(lines)
|
||||
|
||||
if random.randint(0,1):
|
||||
im=Image.open("printer/image.jpg")
|
||||
else:
|
||||
im=Image.open("printer/image2.jpg")
|
||||
|
||||
# f = ImageFont.load_default()
|
||||
f = ImageFont.truetype("printer/SilkRemington-Regular.otf", 40)
|
||||
txt=Image.new('L', (1000,230))
|
||||
d = ImageDraw.Draw(txt)
|
||||
|
||||
text = "While {}, {}, {}".format(location, action, adverb)
|
||||
text_short = "By the DJ, offer a stranger a drink"
|
||||
text_long = "In the outdoor area, ask someone would you rather be known for always being honest or always being kind"
|
||||
|
||||
lines = textwrap.wrap(text, width=23)
|
||||
|
||||
if random.randint(0,1) == 0:
|
||||
im=Image.open("printer/image.jpg")
|
||||
else:
|
||||
im=Image.open("printer/image2.jpg")
|
||||
|
||||
y = 0
|
||||
n = 0
|
||||
for line in lines:
|
||||
n += 1
|
||||
width, height = f.getsize(line)
|
||||
d.text(((1000-width)/2, y), line, font=f, fill=255)
|
||||
y += height
|
||||
w=txt.rotate(-90, expand=1)
|
||||
print(n)
|
||||
im.paste( ImageOps.colorize(w, (0,0,0), (0,0,0)), ( (n-5)*20 + 127, 5), w)
|
||||
|
||||
# im.show()
|
||||
# im.save("image_tmp.jpg")
|
||||
|
||||
raster = StarTSPImage.imageToRaster(im, cut=True)
|
||||
|
||||
printer = open('/dev/usb/lp0', "wb")
|
||||
printer.write(raster)
|
||||
|
||||
# printer = open('/dev/usb/lp0', "wb")
|
||||
# printer.write(raster)
|
||||
|
||||
client = mqtt.Client()
|
||||
client.on_connect = on_connect
|
||||
client.on_message = on_message
|
||||
|
||||
client.connect("10.1.1.162", 1883, 60)
|
||||
client.connect("192.168.240.231", 1883, 60)
|
||||
|
||||
# Blocking call that processes network traffic, dispatches callbacks and
|
||||
# handles reconnecting.
|
||||
# Other loop*() functions are available that give a threaded interface and a
|
||||
# manual interface.
|
||||
client.loop_forever()
|
||||
client.loop_forever()
|
||||
|
57
printer/test.py
Normal file
57
printer/test.py
Normal file
@@ -0,0 +1,57 @@
|
||||
import StarTSPImage
|
||||
from PIL import Image, ImageDraw, ImageFont, ImageOps
|
||||
import textwrap
|
||||
import random
|
||||
|
||||
print("Print")
|
||||
with open("printer/locations.txt") as locations:
|
||||
lines = locations.read().splitlines()
|
||||
location = random.choice(lines)
|
||||
|
||||
with open("printer/actions.txt") as actions:
|
||||
lines = actions.read().splitlines()
|
||||
action = random.choice(lines)
|
||||
|
||||
with open("printer/adverbs.txt") as adverb:
|
||||
lines = adverb.read().splitlines()
|
||||
adverb = random.choice(lines)
|
||||
|
||||
if random.randint(0,1):
|
||||
im=Image.open("printer/image.jpg")
|
||||
else:
|
||||
im=Image.open("printer/image2.jpg")
|
||||
|
||||
# f = ImageFont.load_default()
|
||||
f = ImageFont.truetype("printer/SilkRemington-Regular.otf", 40)
|
||||
txt=Image.new('L', (1000,230))
|
||||
d = ImageDraw.Draw(txt)
|
||||
|
||||
text = "While {}, {}, {}".format(location, action, adverb)
|
||||
text_short = "By the DJ, offer a stranger a drink"
|
||||
text_long = "In the outdoor area, ask someone would you rather be known for always being honest or always being kind"
|
||||
|
||||
lines = textwrap.wrap(text, width=23)
|
||||
|
||||
if random.randint(0,1) == 0:
|
||||
im=Image.open("printer/image.jpg")
|
||||
else:
|
||||
im=Image.open("printer/image2.jpg")
|
||||
|
||||
y = 0
|
||||
n = 0
|
||||
for line in lines:
|
||||
n += 1
|
||||
width, height = f.getsize(line)
|
||||
d.text(((1000-width)/2, y), line, font=f, fill=255)
|
||||
y += height
|
||||
w=txt.rotate(-90, expand=1)
|
||||
print(n)
|
||||
im.paste( ImageOps.colorize(w, (0,0,0), (0,0,0)), ( (n-5)*20 + 127, 5), w)
|
||||
|
||||
# im.show()
|
||||
# im.save("image_tmp.jpg")
|
||||
|
||||
raster = StarTSPImage.imageToRaster(im, cut=True)
|
||||
|
||||
printer = open('/dev/usb/lp0', "wb")
|
||||
printer.write(raster)
|
22
slave/image.py
Normal file
22
slave/image.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import cv2
|
||||
import numpy as np
|
||||
from time import sleep
|
||||
|
||||
class Image:
|
||||
def __init__(self, x, y):
|
||||
self.x = x
|
||||
self.y = y
|
||||
|
||||
def show(self, path):
|
||||
image = cv2.imread(path)
|
||||
cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN)
|
||||
cv2.moveWindow("window", self.x, self.y)
|
||||
cv2.setWindowProperty("window",cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
|
||||
cv2.imshow("window", image)
|
||||
|
||||
def blank(self):
|
||||
blank_image = np.zeros(shape=[512, 512, 3], dtype=np.uint8)
|
||||
cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN)
|
||||
cv2.moveWindow("window", self.x, self.y)
|
||||
cv2.setWindowProperty("window",cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
|
||||
cv2.imshow("window", blank_image)
|
@@ -6,55 +6,65 @@ from random import randint
|
||||
from time import sleep
|
||||
import paho.mqtt.client as mqtt
|
||||
from video import Video
|
||||
import multiprocessing
|
||||
import sys
|
||||
from random import randint
|
||||
|
||||
import cv2
|
||||
from image import Image
|
||||
import multiprocessing
|
||||
|
||||
class App:
|
||||
def __init__(self, client, x, y):
|
||||
self.client = client
|
||||
def __init__(self, x, y):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.video = Video(x, y)
|
||||
self.image = Image(x, y)
|
||||
self.videos = [join("slave/videos", f) for f in listdir("slave/videos") if isfile(join("slave/videos", f))]
|
||||
self.images = [join("slave/images", f) for f in listdir("slave/images") if isfile(join("slave/images", f))]
|
||||
self.lastvideo = -1
|
||||
self.lastimage = -1
|
||||
print(self.videos)
|
||||
print(self.videos[randint(0, len(self.videos))])
|
||||
|
||||
def on_connect(self, client, userdata, flags, rc):
|
||||
print("Connected with result code "+str(rc))
|
||||
self.client.subscribe("slave")
|
||||
|
||||
|
||||
def on_message(self, client, userdata, msg):
|
||||
print(msg.topic+" "+str(msg.payload))
|
||||
if msg.payload == b'idle':
|
||||
print("Idle")
|
||||
self.x = multiprocessing.Process(target = self.idle)
|
||||
self.x.start()
|
||||
|
||||
elif msg.payload == b'stop':
|
||||
print("Stop")
|
||||
self.x.terminate()
|
||||
|
||||
|
||||
print(self.videos[randint(0, len(self.videos)-1)])
|
||||
|
||||
def idle(self):
|
||||
while True:
|
||||
#if self.x is not None:
|
||||
# self.x.terminate()
|
||||
video = self.videos[randint(0, len(self.videos))]
|
||||
self.video.start(video)
|
||||
last = -1
|
||||
|
||||
while True:
|
||||
# if i == last:
|
||||
# continue
|
||||
if randint(0,5) == 0:
|
||||
self.showimage()
|
||||
else:
|
||||
self.playvideo()
|
||||
|
||||
def showimage(self):
|
||||
totalimages = len(self.images)-1
|
||||
i = randint(0, totalimages)
|
||||
if i == self.lastimage:
|
||||
i += 1
|
||||
if i > totalimages:
|
||||
i = 0
|
||||
self.lastimage = i
|
||||
self.image.show(self.images[i])
|
||||
cv2.waitKey(10000)
|
||||
|
||||
def playvideo(self):
|
||||
totalvideos = len(self.videos)-1
|
||||
i = randint(0, totalvideos)
|
||||
if i == self.lastvideo:
|
||||
i += 1
|
||||
if i > totalvideos:
|
||||
i = 0
|
||||
self.lastvideo = i
|
||||
video = self.videos[i]
|
||||
print(video)
|
||||
self.video.start(video)
|
||||
self.image.blank()
|
||||
cv2.waitKey(1)
|
||||
|
||||
def main():
|
||||
|
||||
client = mqtt.Client()
|
||||
app = App(client, int(sys.argv[1]), int(sys.argv[2]))
|
||||
client.on_connect = app.on_connect
|
||||
client.on_message = app.on_message
|
||||
|
||||
client.connect("10.1.1.162", 1883, 60)
|
||||
|
||||
client.loop_forever()
|
||||
|
||||
app = App(int(sys.argv[1]), int(sys.argv[2]))
|
||||
app.idle()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
@@ -2,6 +2,7 @@ from random import randint
|
||||
import cv2
|
||||
import multiprocessing
|
||||
import time
|
||||
import sys
|
||||
|
||||
class Video:
|
||||
def __init__(self, x, y):
|
||||
@@ -19,15 +20,20 @@ class Video:
|
||||
|
||||
print("The total number of frames in this video is ", totalframecount)
|
||||
|
||||
# self.cap.set(cv2.CAP_PROP_POS_FRAMES, randint(0, totalframecount* 0.9))
|
||||
i = randint(0, int(totalframecount * 0.9))
|
||||
self.cap.set(cv2.CAP_PROP_POS_FRAMES, i)
|
||||
|
||||
# Read until video is completed
|
||||
fps = self.cap.get(cv2.CAP_PROP_FPS)
|
||||
delay = 1/fps * 1000
|
||||
print(fps, delay)
|
||||
i = 0
|
||||
playframes = randint(300, 500)
|
||||
while(self.cap.isOpened() ):
|
||||
i += 1
|
||||
if i > playframes:
|
||||
break
|
||||
|
||||
while(self.cap.isOpened()):
|
||||
|
||||
# Capture frame-by-frame
|
||||
ret, frame = self.cap.read()
|
||||
if ret == True:
|
||||
@@ -40,26 +46,20 @@ class Video:
|
||||
|
||||
cv2.imshow("window", frame)
|
||||
|
||||
cv2.waitKey(int(delay))
|
||||
if cv2.waitKey(int(delay)) & 0xFF == ord('q'):
|
||||
self.cap.release()
|
||||
cv2.destroyAllWindows()
|
||||
sys.exit(0)
|
||||
|
||||
# Break the loop
|
||||
else:
|
||||
break
|
||||
self.cap.release()
|
||||
|
||||
# Closes all the frames
|
||||
cv2.destroyAllWindows()
|
||||
#cv2.destroyAllWindows()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
video = Video(0, 0)
|
||||
x = multiprocessing.Process(target = video.start, args=("slave/sample-mp4-file.mp4",))
|
||||
x.start()
|
||||
time.sleep(2)
|
||||
x.terminate()
|
||||
time.sleep(1)
|
||||
video = Video(4000, 0)
|
||||
x = multiprocessing.Process(target = video.start, args=("slave/sample-mp4-file.mp4",))
|
||||
x.start()
|
||||
time.sleep(1)
|
||||
x.terminate()
|
||||
video.start("slave/videos/sample-mp4-file.mp4")
|
||||
|
Reference in New Issue
Block a user