included temperature recording
This commit is contained in:
		
							parent
							
								
									6734e26a7d
								
							
						
					
					
						commit
						dec2fc40bf
					
				
							
								
								
									
										117
									
								
								rasp_grid.py
									
									
									
									
									
								
							
							
						
						
									
										117
									
								
								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() |  | ||||||
| 
 | 
 | ||||||
|             # dist & eth0 controll |             w1_f.close() | ||||||
|             if GPIO.input(Button2_pin) == GPIO.HIGH: |             next_temp_t += temp_interval | ||||||
|                 if disp_eth_power == True: |  | ||||||
|                     subprocess.run(['tvservice', '-o']) |  | ||||||
|                     subprocess.run(['vcgencmd', 'display_power', '0']) |  | ||||||
| 
 | 
 | ||||||
|                     subprocess.run(['sudo', 'ip', 'link', 'set', 'eth0', 'down']) |         # blinking LED | ||||||
|                     disp_eth_power = False |         if time() - LED_t < .1 and LED_status[0] == False: | ||||||
|             else: |             LED_status[0] = True | ||||||
|                 if disp_eth_power == False: |             GPIO.output(LED1_pin, GPIO.HIGH) | ||||||
|                     subprocess.run(['tvservice', '-p']) |         if time() - LED_t >= .1 and LED_status[0] == True: | ||||||
|                     subprocess.run(['vcgencmd', 'display_power', '1']) |             LED_status[0] = False | ||||||
|                     subprocess.run(['sudo', '/bin/chvt', '6']) |             GPIO.output(LED1_pin, GPIO.LOW) | ||||||
|                     subprocess.run(['sudo', '/bin/chvt', '7']) |         if time() - LED_t >= LED_t_interval: | ||||||
|  |             LED_t = time() | ||||||
| 
 | 
 | ||||||
|                     subprocess.run(['sudo', 'ip', 'link', 'set', 'eth0', 'up']) |         # dist & eth0 controll | ||||||
|                     disp_eth_power = True |         if GPIO.input(Button2_pin) == GPIO.HIGH: | ||||||
|  |             if disp_eth_power == True: | ||||||
|  |                 subprocess.run(['tvservice', '-o']) | ||||||
|  |                 subprocess.run(['vcgencmd', 'display_power', '0']) | ||||||
| 
 | 
 | ||||||
|             # Get the status of the background operation |                 subprocess.run(['sudo', 'ip', 'link', 'set', 'eth0', 'down']) | ||||||
|             status, transfer_status = ai_device.get_scan_status() |                 disp_eth_power = False | ||||||
| 
 | 
 | ||||||
|             index = transfer_status.current_index |             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']) | ||||||
| 
 | 
 | ||||||
|             if (last_idx > index) and (index != -1): |                 subprocess.run(['sudo', 'ip', 'link', 'set', 'eth0', 'up']) | ||||||
|                 np.array(data[last_idx:], dtype=np.float32).tofile(f) |                 disp_eth_power = True | ||||||
|                 np.array(data[:index], dtype=np.float32).tofile(f) | 
 | ||||||
|             if index == -1: |         # Get the status of the background operation | ||||||
|                 pass |         status, transfer_status = ai_device.get_scan_status() | ||||||
|             else: | 
 | ||||||
|                 np.array(data[last_idx:index], dtype=np.float32).tofile(f) |         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 | ||||||
| 
 | 
 | ||||||
|             if index == -1: |  | ||||||
|                 last_idx= len(data) |  | ||||||
|             else: |  | ||||||
|                 last_idx = index |  | ||||||
| 
 | 
 | ||||||
|     except KeyboardInterrupt: |  | ||||||
|         embed() |  | ||||||
|         pass |  | ||||||
| 
 | 
 | ||||||
|     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