From 2ea01845533dfe83692b05832a08b8471cc27788 Mon Sep 17 00:00:00 2001 From: tillraab Date: Thu, 19 Sep 2019 12:09:44 +0200 Subject: [PATCH] looking for temp sensor. if available use it --- rasp_grid.py | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/rasp_grid.py b/rasp_grid.py index 527aad2..78c0603 100644 --- a/rasp_grid.py +++ b/rasp_grid.py @@ -174,7 +174,11 @@ def main(): file = os.path.join(path, 'traces-grid1.raw') temp_file = os.path.join(path, 'temp_file.txt') - w1_bus_path = '/sys/bus/w1/devices/28-00000aee438d/w1_slave' + record_temp = False + w1_bus_path = glob.glob('/sys/bus/w1/devices/28*/w1_slave') + if len(w1_bus_path) > 0: + w1_bus_path = w1_bus_path[0] + record_temp = True f = open(file, 'wb') temp_f = open(temp_file, 'w') @@ -188,6 +192,9 @@ def main(): LED_status = GPIO_setup(LED1_pin, LED2_pin, Button1_pin, Button2_pin, power_controll_pin) + last_button_1_t = time() + last_button_2_t = time() + # DAQ setup if True: # channels = 16 @@ -277,6 +284,7 @@ def main(): emergency_LED_t = time() emergency_LED_interval = 0.5 + LED_t = time() LED_t_interval = 2 @@ -287,18 +295,19 @@ def main(): disp_eth_power = True while GPIO.input(Button1_pin) == GPIO.LOW: - if time() - temp_t0 > next_temp_t: - w1_f = open(w1_bus_path, 'r') - w1_file = w1_f.readlines() - for line in w1_file: - if 't=' in line: - temp = float((line.split('=')[-1].strip())) / 1000 - temp_f.write('sec: %.0f; %.3f\n' % (next_temp_t, temp)) - temp_f.flush() - break - - w1_f.close() - next_temp_t += temp_interval + if record_temp == True: + if time() - temp_t0 > next_temp_t: + w1_f = open(w1_bus_path, 'r') + w1_file = w1_f.readlines() + for line in w1_file: + if 't=' in line: + temp = float((line.split('=')[-1].strip())) / 1000 + temp_f.write('sec: %.0f; %.3f\n' % (next_temp_t, temp)) + temp_f.flush() + break + + w1_f.close() + next_temp_t += temp_interval # blinking LED if GPIO.input(power_controll_pin) == GPIO.HIGH: @@ -334,12 +343,13 @@ def main(): # dist & eth0 controll - if GPIO.input(Button2_pin) == GPIO.HIGH: + if GPIO.input(Button2_pin) == GPIO.HIGH and (time() - last_button_2_t) > 5: if disp_eth_power == True: subprocess.run(['tvservice', '-o']) subprocess.run(['vcgencmd', 'display_power', '0']) subprocess.run(['sudo', 'ip', 'link', 'set', 'eth0', 'down']) + GPIO.output(LED2_pin, GPIO.LOW) disp_eth_power = False elif disp_eth_power == False: @@ -349,6 +359,7 @@ def main(): subprocess.run(['sudo', '/bin/chvt', '7']) subprocess.run(['sudo', 'ip', 'link', 'set', 'eth0', 'up']) + GPIO.output(LED2_pin, GPIO.HIGH) disp_eth_power = True # Get the status of the background operation