Skip to content
Snippets Groups Projects
Commit 800f51c3 authored by TERRU Theo's avatar TERRU Theo
Browse files

Ajout prepare_command

parent 0a5a7fbd
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,10 @@ import sys
increment = 0
nbrBoucle = 0
nbrCyclesPompage = 0
stop = 0
currentQuantity = -1
pwmMotor = 0
args = []
nbrArgs = len(sys.argv) # Ordre : Pompe1 Pompe2 Pompe3 EV1 EV2 EV3 EV4 EV5 EV6 EV7
......@@ -22,36 +25,94 @@ EV7 = 9
args = [1,1,0]
def testDebimetre(bec, quantite): # quantité en cl (int), bec (int)
# Setup des composants
def prepare_commande(commande):
for bec, quantite in commande:
setupGpio()
print("in prepare commande, bec : "+str(bec)+", quantite : "+ str(quantite))
#startLine(bec, quantite, 0)
# Setup des composants
def setupGpio():
global pwmMotor
GPIO.setmode(GPIO.BCM) # set up BCM GPIO numbering
GPIO.setup(25, GPIO.IN, pull_up_down = GPIO.PUD_DOWN) # DEBITMETRE
GPIO.setup(24, GPIO.OUT, initial=GPIO.LOW) # ELECTROVANNE 1
GPIO.setup(21, GPIO.OUT, initial=GPIO.LOW) # ELECTROVANNE 2
GPIO.setup(23, GPIO.OUT) # POMPE
p = GPIO.PWM(23,100)
pwmMotor = GPIO.PWM(23,300)
# Démarrage des composants requis
def startPompage(quantite):
global increment
global pwmMotor
PWM = 0
increment = 1
while PWM <= 50:
pwmMotor.start(PWM)
print("PWM =", PWM)
PWM += 5
sleep(0.1)
#sleep(0.3)
def stopLine():
global pwmMotor
pwmMotor.stop()
#GPIO.remove_event_detect(25)
GPIO.cleanup() # clean up after yourself
print("GPIO cleaned")
def startLine(bec, quantite, amorcage): # quantité en cl (int), bec (int)
global currentQuantity
global stop
currentQuantity = quantite
print("Start : Ligne", bec)
print("Quantité voulue : ", quantite)
openMotorPompe1 = 0
stop = 0
if not amorcage:
if bec == 1:
GPIO.output(24, GPIO.HIGH)
print("Electrovanne1 ouverte")
startMotorPompe1 = 1
elif bec == 2:
GPIO.output(21, GPIO.HIGH)
print("Electrovanne2 ouverte")
startMotorPompe1 = 1
else:
print("NON IMPLEMENTE")
else:
print("Phase amorcage")
GPIO.output(24, GPIO.HIGH)
print("Electrovanne1 ouverte")
GPIO.output(21, GPIO.HIGH)
print("Electrovanne2 ouverte")
Q = int(quantite / 5)
q = int(quantite % 5)
print("Q =", Q)
print("q =", q)
startMotorPompe1 = 0
sleep(10)
# Define a threaded callback function to run in another thread when events are detected
def my_callback(channel):
def flowmeterTrigger(channel):
global nbrBoucle
global increment
global nbrCyclesPompage
global currentQuantity
global stop
global nbrBoucle
# Si la quantité désirée a été pompée
if nbrBoucle == Q-1 and not stop:
if increment == currentQuantity:
# Arrêt de tous les composants
p.stop()
#pwmMotor.stop()
print("Pompe fermée")
GPIO.output(24, GPIO.LOW)
......@@ -59,8 +120,9 @@ def testDebimetre(bec, quantite): # quantité en cl (int), bec (int)
GPIO.output(21, GPIO.LOW)
print("Electrovanne 2 fermée")
stopLine()
stop = 1
stop=1
# Tant qu'il manque du liquide on continue de pomper
elif GPIO.input(25): # if port 25 == 1
......@@ -68,61 +130,30 @@ def testDebimetre(bec, quantite): # quantité en cl (int), bec (int)
increment+=1
print(increment)
# Ajout du callback débitmètre
GPIO.add_event_detect(25, GPIO.RISING, callback=my_callback, bouncetime=5)
# Ajout du trigger débitmètre
GPIO.add_event_detect(25, GPIO.RISING, callback=flowmeterTrigger, bouncetime=5)
if args[EV1]:
GPIO.output(24, GPIO.HIGH)
print("Electrovanne1 ouverte")
if startMotorPompe1:
startPompage(currentQuantity)
if args[EV2]:
GPIO.output(21, GPIO.HIGH)
print("Electrovanne2 ouverte")
# Démarrage des composants requis
if args[Pompe1]:
global nbrBoucle
print("Pompe1 ouverte")
for i in range(Q):
PWM = 0
increment = 1
while PWM <= 50:
p.start(PWM)
print("PWM =", PWM)
PWM += 5
sleep(0.1)
while increment % 5 != 0:
pass
increment = 1
p.stop()
nbrBoucle+=1
#sleep(0.3)
#GPIO.output(23, GPIO.HIGH)
try:
# Thread du débitmètre tourne en fond
try:
while not stop:
pass
finally:
print("CLEANUP")
GPIO.cleanup()
finally: # this block will run no matter how the try block exits
p.stop()
#GPIO.remove_event_detect(25)
GPIO.cleanup() # clean up after yourself
print("GPIO cleaned")
print("Fin du programme")
increment = 0
stop = 0
if __name__=="__main__":
args = []
for strParam in sys.argv[1:]:
try:
args.append(int(strParam))
except ValueError:
print( "Bad parameter value: %s" % strParam, file=sys.stderr )
testDebimetre(2, 28)
#setupGpio()
#stopLine()
setupGpio()
startLine(2, 100, 0)
#setupGpio()
#startLine(2, 30, 0)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment