diff --git a/config.json b/config.json index 41ec195..221b362 100644 --- a/config.json +++ b/config.json @@ -87,7 +87,7 @@ }, "activated-channels": [ 0, 1], "interval": 1, - "use_difference": false, + "use_difference": true, "thresholds-for": "inside", "thresholds": { "off":{ @@ -123,4 +123,4 @@ "pwm-low": 100.0 } } -} \ No newline at end of file +} diff --git a/scripts/pwm.py b/scripts/pwm.py old mode 100644 new mode 100755 index ceb1be4..29fc37c --- a/scripts/pwm.py +++ b/scripts/pwm.py @@ -1,10 +1,11 @@ +#! /usr/bin/env python3 #import RPIO import RPi.GPIO as GPIO import time from datetime import datetime from datetime import timedelta -switch = 15 -pwm = 14 +switch = 17 +pwm = 18 fan_speed =18 #RPIO.setup(switch, RPIO.OUT) @@ -17,7 +18,14 @@ GPIO.setup(switch, GPIO.OUT) GPIO.setup(pwm, GPIO.OUT) fan = GPIO.PWM(pwm, 25000) -GPIO.setup(fan_speed, GPIO.IN, pull_up_down=GPIO.PUD_UP) +uswitch = 22 +upwm = 23 + +GPIO.setup(uswitch, GPIO.OUT) +GPIO.setup(upwm, GPIO.OUT) +ufan = GPIO.PWM(pwm,25000) + +# GPIO.setup(fan_speed, GPIO.IN, pull_up_down=GPIO.PUD_UP) global last_ts global current_ts global diff @@ -45,29 +53,44 @@ def speed_callback(channel): # print("{:d} | \t{:.2f} | \t{} | \t{} | \t{}".format(diff.microseconds, rpm, diff, current_ts, last_ts), end="\r") -GPIO.add_event_detect(fan_speed, GPIO.FALLING, callback=speed_callback) - +# GPIO.add_event_detect(fan_speed, GPIO.FALLING, callback=speed_callback) +import sys try: GPIO.output(switch, True) + GPIO.output(uswitch, True) step = 10 c = 0 direction = 1 diff=timedelta() fan.start(c) + ufan.start(c) while True: - if c == 100: - direction = -1 - elif c == 0: - direction = 1 - c += step*direction - fan.ChangeDutyCycle(c) + 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) # print("{} ".format(c)) - time.sleep(5) + # while True: + time.sleep(0.1) except KeyboardInterrupt: pass finally: - fan.stop() - GPIO.output(switch, False) + #fan.stop() + #GPIO.output(switch, False) GPIO.cleanup() diff --git a/scripts/test.py b/scripts/test.py old mode 100644 new mode 100755 index 3a13bc0..79c93cf --- a/scripts/test.py +++ b/scripts/test.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#! /usr/bin/env python3 import spidev import time @@ -9,12 +9,12 @@ tnom = 25 rnom = 10000.0 corr = 4800 temp_gpio = { - 0: { - "BCM": 20, - "Rk": 9770.0 #9770, - }, 1: { "BCM": 26, + "Rk": 9770.0 #9770, + }, + 0: { + "BCM": 20, "Rk": 10000.0 } } diff --git a/src/lowlevel.py b/src/lowlevel.py index db0424e..c6429e0 100644 --- a/src/lowlevel.py +++ b/src/lowlevel.py @@ -41,31 +41,31 @@ class LowLevel(metaclass=Singleton): self.__spi.cshigh = True def retrieve_adc(self, channel): - if channel > 7 or channel < 0: + if channel > 7 or channel < 0: return None pin = self.__cfg.get_sensors_dict()[str(channel)]["BCM"] - GPIO.output(pin, True) + GPIO.output(pin, True) hchbit = channel >> 2 - lchbits = channel & 0x03 + lchbits = channel & 0x03 to_send = [hchbit | 0x06, lchbits << 6, 0x00] self.__activate() r = self.__spi.xfer(to_send) self.__deactivate() - GPIO.output(pin, False) - highbyte = r[1] - lowbyte = r[2] - value = (highbyte << 8) | lowbyte + GPIO.output(pin, False) + highbyte = r[1] + lowbyte = r[2] + value = (highbyte << 8) | lowbyte return value def upper_fan(self, on): GPIO.output(self.__cfg.get_pwm_upper()["on-off"]["BCM"], on) def upper_fan_pwm(self, percent): - self.__pwmu.ChangeDutyCycle(percent) + self.__pwmu.ChangeDutyCycle(100 - percent) def lower_fan(self, on): GPIO.output(self.__cfg.get_pwm_lower()["on-off"]["BCM"], on) def lower_fan_pwm(self, percent): - self.__pwml.ChangeDutyCycle(percent) + self.__pwml.ChangeDutyCycle(100 - percent)