included temperature recording
This commit is contained in:
parent
6734e26a7d
commit
dec2fc40bf
133
rasp_grid.py
133
rasp_grid.py
@ -1,5 +1,6 @@
|
||||
from __future__ import print_function
|
||||
import os
|
||||
import glob
|
||||
import datetime
|
||||
from shutil import copyfile
|
||||
try:
|
||||
@ -29,11 +30,11 @@ def GPIO_setup(LED1_pin, LED2_pin, Button1_pin, Button2_pin):
|
||||
LED_status = [False, False]
|
||||
|
||||
# switch controlled input
|
||||
GPIO.setup(Button1_pin, GPIO.IN)
|
||||
GPIO.setup(Button2_pin, GPIO.IN)
|
||||
# GPIO.setup(Button1_pin, GPIO.IN)
|
||||
# GPIO.setup(Button2_pin, GPIO.IN)
|
||||
|
||||
# GPIO.setup(Button1_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
# GPIO.setup(Button2_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
GPIO.setup(Button1_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
GPIO.setup(Button2_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
|
||||
return LED_status
|
||||
|
||||
@ -171,13 +172,14 @@ def main():
|
||||
channels, rate = read_cfg(cfgfile, now)
|
||||
|
||||
file = os.path.join(path, 'traces-grid1.raw')
|
||||
temp_file = os.path.join(path, 'temp_file.txt')
|
||||
|
||||
w1_bus_path = glob.glob('/sys/bus/w1/device/28*/w1-slave')[0]
|
||||
f = open(file, 'wb')
|
||||
temp_f = open(temp_file, 'w')
|
||||
|
||||
# f.close()
|
||||
|
||||
#embed()
|
||||
#quit()
|
||||
|
||||
LED1_pin = 11
|
||||
LED2_pin = 13
|
||||
Button1_pin = 16
|
||||
@ -272,61 +274,76 @@ def main():
|
||||
LED_t = time()
|
||||
LED_t_interval = 2
|
||||
|
||||
temp_t0 = time()
|
||||
next_temp_t = 0
|
||||
temp_interval = 10 # sec --> 5 min
|
||||
|
||||
disp_eth_power = True
|
||||
|
||||
try:
|
||||
while GPIO.input(Button1_pin) == GPIO.HIGH:
|
||||
# blinking LED
|
||||
if time() - LED_t < .1 and LED_status[0] == False:
|
||||
LED_status[0] = True
|
||||
GPIO.output(LED1_pin, GPIO.HIGH)
|
||||
if time() - LED_t >= .1 and LED_status[0] == True:
|
||||
LED_status[0] = False
|
||||
GPIO.output(LED1_pin, GPIO.LOW)
|
||||
if time() - LED_t >= LED_t_interval:
|
||||
LED_t = time()
|
||||
|
||||
# dist & eth0 controll
|
||||
if GPIO.input(Button2_pin) == GPIO.HIGH:
|
||||
if disp_eth_power == True:
|
||||
subprocess.run(['tvservice', '-o'])
|
||||
subprocess.run(['vcgencmd', 'display_power', '0'])
|
||||
|
||||
subprocess.run(['sudo', 'ip', 'link', 'set', 'eth0', 'down'])
|
||||
disp_eth_power = False
|
||||
else:
|
||||
if disp_eth_power == False:
|
||||
subprocess.run(['tvservice', '-p'])
|
||||
subprocess.run(['vcgencmd', 'display_power', '1'])
|
||||
subprocess.run(['sudo', '/bin/chvt', '6'])
|
||||
subprocess.run(['sudo', '/bin/chvt', '7'])
|
||||
|
||||
subprocess.run(['sudo', 'ip', 'link', 'set', 'eth0', 'up'])
|
||||
disp_eth_power = True
|
||||
|
||||
# Get the status of the background operation
|
||||
status, transfer_status = ai_device.get_scan_status()
|
||||
|
||||
index = transfer_status.current_index
|
||||
|
||||
if (last_idx > index) and (index != -1):
|
||||
np.array(data[last_idx:], dtype=np.float32).tofile(f)
|
||||
np.array(data[:index], dtype=np.float32).tofile(f)
|
||||
if index == -1:
|
||||
pass
|
||||
else:
|
||||
np.array(data[last_idx:index], dtype=np.float32).tofile(f)
|
||||
|
||||
if index == -1:
|
||||
last_idx= len(data)
|
||||
else:
|
||||
last_idx = index
|
||||
|
||||
except KeyboardInterrupt:
|
||||
embed()
|
||||
pass
|
||||
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))
|
||||
break
|
||||
|
||||
w1_f.close()
|
||||
next_temp_t += temp_interval
|
||||
|
||||
# blinking LED
|
||||
if time() - LED_t < .1 and LED_status[0] == False:
|
||||
LED_status[0] = True
|
||||
GPIO.output(LED1_pin, GPIO.HIGH)
|
||||
if time() - LED_t >= .1 and LED_status[0] == True:
|
||||
LED_status[0] = False
|
||||
GPIO.output(LED1_pin, GPIO.LOW)
|
||||
if time() - LED_t >= LED_t_interval:
|
||||
LED_t = time()
|
||||
|
||||
# dist & eth0 controll
|
||||
if GPIO.input(Button2_pin) == GPIO.HIGH:
|
||||
if disp_eth_power == True:
|
||||
subprocess.run(['tvservice', '-o'])
|
||||
subprocess.run(['vcgencmd', 'display_power', '0'])
|
||||
|
||||
subprocess.run(['sudo', 'ip', 'link', 'set', 'eth0', 'down'])
|
||||
disp_eth_power = False
|
||||
|
||||
elif disp_eth_power == False:
|
||||
subprocess.run(['tvservice', '-p'])
|
||||
subprocess.run(['vcgencmd', 'display_power', '1'])
|
||||
subprocess.run(['sudo', '/bin/chvt', '6'])
|
||||
subprocess.run(['sudo', '/bin/chvt', '7'])
|
||||
|
||||
subprocess.run(['sudo', 'ip', 'link', 'set', 'eth0', 'up'])
|
||||
disp_eth_power = True
|
||||
|
||||
# Get the status of the background operation
|
||||
status, transfer_status = ai_device.get_scan_status()
|
||||
|
||||
index = transfer_status.current_index
|
||||
|
||||
if (last_idx > index) and (index != -1):
|
||||
np.array(data[last_idx:], dtype=np.float32).tofile(f)
|
||||
np.array(data[:index], dtype=np.float32).tofile(f)
|
||||
if index == -1:
|
||||
pass
|
||||
else:
|
||||
np.array(data[last_idx:index], dtype=np.float32).tofile(f)
|
||||
|
||||
if index == -1:
|
||||
last_idx= len(data)
|
||||
else:
|
||||
last_idx = index
|
||||
|
||||
|
||||
|
||||
f.close()
|
||||
temp_f.close()
|
||||
|
||||
if daq_device:
|
||||
# Stop the acquisition if it is still running.
|
||||
if status == ScanStatus.RUNNING:
|
||||
|
Loading…
Reference in New Issue
Block a user