-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexecuteCmds.py
127 lines (109 loc) · 4.33 KB
/
executeCmds.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import imageFilter
import random
import RPi.GPIO as GPIO
import re
import takepic
#from ServoLib import RocketServos
from PIL import Image
import moveServo
import asyncio
from datetime import datetime
import timeStamper
#example_APRS = "XX4XXX C3 A1 D4 C3 F6 C3 F6 B2 B2 C3"
#example_APRS = "XX4XXX C3 E5 C3 D4 C3 F6 B2 C3 B2 C3"
#APRS_clip = aprsMsg[7:]
def executeCmds(APRS_clip, cam, folder_name):
# Initialize filter variables
x = 0
gray = 0
randnum = 0
numTurns = 0 # no. times turned 60 deg clockwise
# Executing commands
print("Executing Commands")
pinServo = 8
# Servo pins based on
#if cam == "big":
# pinServo = 22
#elif cam == "pinky":
# pinServo = 23
#elif cam == "ring":
# pinServo = 21
#elif cam == "jahn":
# pinServo = 24
#else:
# pinServo = 22 # big = default
# print("No pin assigned for servo, green servo chosen")
#GPIO.setmode(GPIO.BCM)
GPIO.setup(pinServo,GPIO.OUT)
pwm = GPIO.PWM(pinServo, 500)
while x < len(APRS_clip):
if APRS_clip[x] == "A": # Move servo +60 deg
if numTurns >= 3:
moveServo.moveServo(-300,pwm)
numTurns = numTurns - 5
else:
moveServo.moveServo(60,pwm)
numTurns = numTurns + 1
print("A1")
elif APRS_clip[x] == "B": # Move servo -60 deg
if numTurns <= -3:
moveServo.moveServo(300,pwm)
numTurns = numTurns + 5
else:
moveServo.moveServo(-60,pwm)
numTurns = numTurns - 1
print("B2")
elif APRS_clip[x] == "C": # Take picture
takepic.takepic(cam, x, folder_name)
currentTime = datetime.now()
picName = f"{folder_name}capture_{cam}_{x}.jpg" # Current image path name
timeStamper.timeStamper(currentTime, picName) # Replace unfiltered img w/ timestamped image
if gray == 1: # 1 if grayscale filter applied
pic2gray = Image.open(picName)
pic2gray = imageFilter.blackandwhite(pic2gray,x)
pic2gray.save(f"{folder_name}gray_{cam}_{x}.jpg")
#picName = f"gray_{cam}_{x}.jpg" # Current image path name
# If randnum~=0, then a random filter has been applied
if randnum == 1:
#pic2filter = "capture_%s_%d.jpg" % (cam, x)
#pic2filter = imageFilter.fry(pic2filter)
#pic2filter.save("capture_%s_%d.jpg" % (cam, x))
print('whoops cant fry lol')
elif randnum == 2:
pic2filter = Image.open(picName)
pic2filter = imageFilter.grassless(pic2filter)
pic2filter.save(f"{folder_name}grassless_{cam}_{x}.jpg")
picName = f"{folder_name}grassless_{cam}_{x}.jpg" # Current image path name
elif randnum == 3:
pic2filter = Image.open(picName)
pic2filter = imageFilter.meme(pic2filter)
pic2filter.save(f"{folder_name}meme_{cam}_{x}.jpg")
picName = f"{folder_name}meme_{cam}_{x}.jpg" # Current image path name
elif randnum != 0:
print('Your RNG is broken')
timeStamper.timeStamper(currentTime, picName) # Replace unfiltered img w/ timestamped image
print("C3")
elif APRS_clip[x] == "D": # Grayscale to color
gray = 0
print("D4")
elif APRS_clip[x] == "E": # Color to grayscale
gray = 1
print("E5")
elif APRS_clip[x] == "F": # Rotate image 180deg
#pic2rotate = Image.open(f"capture_{cam}_{x-3}.jpg")
pic2rotate = Image.open(picName)
pic2rotate = imageFilter.rotate180(pic2rotate,x)
pic2rotate.save(f"{folder_name}rotated_{x}.jpg")
print("F6")
elif APRS_clip[x] == "G": # Special effects filter
print("G7")
randnum = random.randint(2,3)
elif APRS_clip[x] == "H": # Clear all filters
randnum = 0
gray = 0
print("H8")
elif APRS_clip[x] == '1':
print("ignoring _1 at end")
else:
print("Either indexing is wrong or the received msg is off-center")
x = x + 3