This repository has been archived by the owner on Jun 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
temp-hum-control.py
92 lines (67 loc) · 2.18 KB
/
temp-hum-control.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from grapher import grapher_process_main
from secretary import file_process_main
from arduinoer import arduino_process_main
from multiprocessing import (Process, Queue)
from queue import Empty
from threading import Thread
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
import pandas as pd
import numpy as np
import time
import configparser
from itertools import count
# The boss of the Processes is this script reading the stdin
# Command expected as:
# [TO] [CMD] [Value]
# Where CMD is the command
def loop(queue):
while True:
cmd = input('[Command] ')
# fstrings are interesting
print(f'[Boss] Sending command "{cmd}" to the control software.')
cmd_split = cmd.split(' ')
queue.put(cmd_split)
if cmd_split[0] == 'close':
print('[Boss] Closing everything.')
break
time.sleep(1.0/1000)
def read_config():
config = configparser.ConfigParser()
with open('file.cfg') as f:
config.read_file(f)
return config['MAIN']
def main():
try:
config = read_config()
ardInQueue = Queue()
ardOutQueue = Queue()
graQueue = Queue()
consoleQueue = Queue()
# iv_Queue = Queue()
# Arduino code that measures the humidity/temperature measurements
humtemp_process = Process(target=arduino_process_main, \
kwargs={'inQueue' : ardOutQueue, 'outQueue' : ardInQueue })
# Secretary (file Manager)
file_process = Process(target=file_process_main, \
kwargs={'bossQueue' : consoleQueue, 'graQueue' : graQueue, \
'ardOutQueue' : ardOutQueue, 'ardInQueue' : ardInQueue, \
'ivOutQueue' : None, 'ivInQueue' : None })
# Code that plots every data avaliable
gra_process = Process(target=grapher_process_main, args=(graQueue,), kwargs={'humidity_only' : True})
# Reads stdin
# https://stackoverflow.com/questions/8976962/is-there-any-way-to-pass-stdin-as-an-argument-to-another-process-in-python
boss_thread = Thread(target=loop, args=(consoleQueue,))
# if config.getboolean('IVMeasurements'):
boss_thread.start()
humtemp_process.start()
file_process.start()
gra_process.start()
boss_thread.join()
humtemp_process.join()
file_process.join()
gra_process.join()
finally:
pass
if __name__ == '__main__':
main()