2019-11-24 21:16:03 +01:00
|
|
|
#! /usr/bin/env python3
|
2017-10-15 16:44:23 +02:00
|
|
|
#import RPIO
|
|
|
|
import RPi.GPIO as GPIO
|
|
|
|
import time
|
|
|
|
from datetime import datetime
|
|
|
|
from datetime import timedelta
|
2019-11-24 21:16:03 +01:00
|
|
|
switch = 17
|
|
|
|
pwm = 18
|
2017-10-15 16:44:23 +02:00
|
|
|
fan_speed =18
|
|
|
|
#RPIO.setup(switch, RPIO.OUT)
|
|
|
|
|
|
|
|
#RPIO.output(switch, True)
|
|
|
|
|
|
|
|
# RPIO.PWM.setup()
|
|
|
|
#fan = RPIO.PWM.Servo(0, 40, 1)
|
|
|
|
GPIO.setmode(GPIO.BCM)
|
|
|
|
GPIO.setup(switch, GPIO.OUT)
|
|
|
|
GPIO.setup(pwm, GPIO.OUT)
|
|
|
|
fan = GPIO.PWM(pwm, 25000)
|
|
|
|
|
2019-11-24 21:16:03 +01:00
|
|
|
uswitch = 22
|
|
|
|
upwm = 23
|
|
|
|
|
|
|
|
GPIO.setup(uswitch, GPIO.OUT)
|
|
|
|
GPIO.setup(upwm, GPIO.OUT)
|
2019-12-17 10:11:00 +01:00
|
|
|
ufan = GPIO.PWM(upwm,25000)
|
2019-11-24 21:16:03 +01:00
|
|
|
|
|
|
|
# GPIO.setup(fan_speed, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
2017-10-15 16:44:23 +02:00
|
|
|
global last_ts
|
|
|
|
global current_ts
|
|
|
|
global diff
|
|
|
|
diff = timedelta()
|
|
|
|
last_ts = datetime.now()
|
|
|
|
current_ts = 0
|
|
|
|
global counter
|
|
|
|
counter = 0
|
|
|
|
def speed_callback(channel):
|
|
|
|
global last_ts
|
|
|
|
global current_ts
|
|
|
|
global diff
|
|
|
|
global counter
|
|
|
|
current_ts = datetime.now()
|
|
|
|
if current_ts != 0 and last_ts != 0:
|
|
|
|
diff = current_ts - last_ts
|
|
|
|
if diff.seconds < 1:
|
|
|
|
counter+=1
|
|
|
|
else:
|
|
|
|
rpm = (counter/2)*60
|
|
|
|
print("{} ||| {} ".format(counter, rpm), end="\r")
|
|
|
|
last_ts = current_ts
|
|
|
|
counter = 0
|
|
|
|
# print("{} ".format(rpm), end="\r")
|
|
|
|
# print("{:d} | \t{:.2f} | \t{} | \t{} | \t{}".format(diff.microseconds, rpm, diff, current_ts, last_ts), end="\r")
|
|
|
|
|
|
|
|
|
2019-11-24 21:16:03 +01:00
|
|
|
# GPIO.add_event_detect(fan_speed, GPIO.FALLING, callback=speed_callback)
|
|
|
|
import sys
|
2017-10-15 16:44:23 +02:00
|
|
|
try:
|
|
|
|
GPIO.output(switch, True)
|
2019-11-24 21:16:03 +01:00
|
|
|
GPIO.output(uswitch, True)
|
2017-10-15 16:44:23 +02:00
|
|
|
step = 10
|
|
|
|
c = 0
|
|
|
|
direction = 1
|
|
|
|
diff=timedelta()
|
|
|
|
fan.start(c)
|
2019-11-24 21:16:03 +01:00
|
|
|
ufan.start(c)
|
2017-10-15 16:44:23 +02:00
|
|
|
while True:
|
2019-11-24 21:16:03 +01:00
|
|
|
l = input().strip().split(" ")
|
|
|
|
if len(l) == 2:
|
|
|
|
if int(l[0]) < 0:
|
|
|
|
GPIO.output(switch, False)
|
|
|
|
else:
|
|
|
|
GPIO.output(switch, True)
|
|
|
|
fan.ChangeDutyCycle(100 - int(l[0]))
|
|
|
|
if int(l[1]) < 0:
|
|
|
|
GPIO.output(uswitch, False)
|
|
|
|
else:
|
|
|
|
GPIO.output(uswitch, True)
|
|
|
|
ufan.ChangeDutyCycle(100 - int(l[1]))
|
|
|
|
# if c == 100:
|
|
|
|
# direction = -1
|
|
|
|
# elif c == 0:
|
|
|
|
# direction = 1
|
|
|
|
# c += step*direction
|
|
|
|
# fan.ChangeDutyCycle(c)
|
2017-10-15 16:44:23 +02:00
|
|
|
# print("{} ".format(c))
|
2019-11-24 21:16:03 +01:00
|
|
|
# while True:
|
|
|
|
time.sleep(0.1)
|
2017-10-15 16:44:23 +02:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
pass
|
|
|
|
finally:
|
2019-11-24 21:16:03 +01:00
|
|
|
#fan.stop()
|
|
|
|
#GPIO.output(switch, False)
|
2017-10-15 16:44:23 +02:00
|
|
|
GPIO.cleanup()
|
|
|
|
|
|
|
|
|