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