60 lines
1.7 KiB
Python
60 lines
1.7 KiB
Python
import time
|
|
import os
|
|
|
|
from config import *
|
|
from tcp_io_module import TcpIoModule
|
|
from hvs import HvService
|
|
from mqtt_client import mqtt_client
|
|
|
|
# pinctrl set 26 op pn dl
|
|
|
|
def main():
|
|
#通过pinctrl打开电源
|
|
os.system("pinctrl set 26 op pn dl")
|
|
|
|
io_module = TcpIoModule(host='192.168.8.211', port=502)
|
|
io_module.start()
|
|
|
|
hv_service = HvService()
|
|
hv_service.start()
|
|
|
|
light_state = False
|
|
light_new_state = False
|
|
|
|
light_state_update_time = 0.0
|
|
xray_off_time = 0.0
|
|
|
|
while True:
|
|
try:
|
|
if time.time() - hv_service.last_hvs_update_time > 5.0:
|
|
hv_service.xray_on = [False, False]
|
|
if hv_service.xray_on[0] or hv_service.xray_on[1]:
|
|
light_new_state = True
|
|
else:
|
|
if light_new_state == True:
|
|
xray_off_time = time.time()
|
|
light_new_state = False
|
|
|
|
if light_state != light_new_state and time.time() - light_state_update_time > 2 and time.time() - xray_off_time > 2:
|
|
# if light_new_state == False:
|
|
# if time.time() - xray_off_time > 12.0:
|
|
# light_state = light_new_state
|
|
# else:
|
|
# light_state = light_new_state
|
|
light_state = light_new_state
|
|
io_module.control_light(8, light_state)
|
|
mqtt_client.control_xray_light(light_state)
|
|
light_state_update_time = time.time()
|
|
|
|
time.sleep(0.1)
|
|
except KeyboardInterrupt:
|
|
print("程序收到中断信号,正在退出...")
|
|
io_module.stop()
|
|
hv_service.stop()
|
|
mqtt_client.stop()
|
|
break
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|