From a47d7c2bd92a7e4bff62f25bdd8a7abe38c99100 Mon Sep 17 00:00:00 2001 From: "support.sampyo" Date: Wed, 12 Jun 2024 05:16:08 +0000 Subject: [PATCH] Commit message --- control.json | 6 ++++- framework.yaml | 2 +- main.py | 66 +++++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 66 insertions(+), 8 deletions(-) diff --git a/control.json b/control.json index d60174b..116a3a3 100644 --- a/control.json +++ b/control.json @@ -27,7 +27,11 @@ }, "motor": { "action": "Off" - } + }, + "main": { + "action": "Off", + "duration": 1.5 + } }, "maintenance": { "clean": { diff --git a/framework.yaml b/framework.yaml index 081e8a7..60e9491 100644 --- a/framework.yaml +++ b/framework.yaml @@ -7,5 +7,5 @@ spec: virtualEnv: base # 사용할 가상환경 이름입니다. package: requirements.txt # 설치할 Python 패키지 정보 파일입니다.(기본 값은 requirement.txt 입니다.) stackbase: - tagName: v0.0.38 # Stackbase(gitea)에 릴리즈 태그명 입니다. + tagName: v0.0.39 # Stackbase(gitea)에 릴리즈 태그명 입니다. repoName: sampyo-dio # Stackbase(gitea)에 저장될 저장소 이릅니다. diff --git a/main.py b/main.py index efd5756..0d0fa16 100644 --- a/main.py +++ b/main.py @@ -51,6 +51,37 @@ def Valve_EnterWater(chip, status, action): chip.set_values(status) +def Valve_MainWater(chip, status, action, duration=7): + global main_valve_status + + status[5] = 0 + status[6] = 0 + chip.set_values(status) + time.sleep(0.05) + + if action == 'On': + status[5] = 1 + status[6] = 0 + chip.set_values(status) + time.sleep(duration) + else: + status[5] = 0 + status[6] = 1 + chip.set_values(status) + time.sleep(7) + + status[5] = 0 + status[6] = 0 + chip.set_values(status) + time.sleep(0.05) + + if action == 'On' and duration == 7: + main_valve_status = 2 + elif action = 'On' and duration != 7: + main_valve_status = 1 + else: + main_valve_status = 0 + def Measure_Weight(client): # print('in') val = 0 @@ -80,16 +111,12 @@ def Set_Zero(client): client.write_coil(1, 1) def Command_Read(): - global client + global client, main_valve_status with open('./control.json', 'r') as f: cmd = json.load(f) if cmd['type'] == 'auto': - - Valve_Vent(chip=output_lines, status=status, action='Off') - Motor(chip=output_lines, status=status, action='Off') - mixed_duration = int(cmd['device']['mixed']['duration']) pure_duration = int(cmd['device']['pure']['duration']) pure_holding = int(cmd['device']['pure']['holding']) @@ -97,6 +124,16 @@ def Command_Read(): vent_holding = int(cmd['device']['vent']['holding']) measure_duration = int(cmd['device']['measure']['duration']) enter_duration = int(cmd['device']['enter']['duration']) + main_duration = float(cmd['device']['main']['duration']) + + if main_valve_status == 0: + Valve_MainWater(chip=output_lines, status=status, action='On', duration=main_duration) + else: + Valve_MainWater(chip=output_lines, status=status, action='Off') + Valve_MainWater(chip=output_lines, status=status, action='On', duration=main_duration) + + Valve_Vent(chip=output_lines, status=status, action='Off') + Motor(chip=output_lines, status=status, action='Off') time.sleep(5) start = Measure_Weight(client=client) @@ -168,6 +205,7 @@ def Command_Read(): elif cmd['type'] == 'clean': clean_system() + time.sleep(3) else: # cmd['type'] == 'manual' Motor(chip=output_lines, status=status, action=cmd['device']['motor']['action']) @@ -176,6 +214,12 @@ def Command_Read(): Valve_PureWater(chip=output_lines, status=status, action=cmd['device']['pure']['action']) Valve_EnterWater(chip=output_lines, status=status, action=cmd['device']['enter']['action']) + if cmd['device']['main']['duration'] == 0: + Valve_MainWater(chip=output_lines, status=status, action=cmd['device']['main']['action']) + else: + Valve_MainWater(chip=output_lines, status=status, action=cmd['device']['main']['action'], duration=cmd['device']['main']['duration']) + + if cmd['device']['measure']['action'] == 'On': result = Measure_Weight(client=client) Calculate_Concentration(result) @@ -187,6 +231,7 @@ def Command_Read(): return 0 def clean_system(): + global main_valve_status with open('./control.json', 'r') as f: cmd = json.load(f) @@ -195,11 +240,16 @@ def clean_system(): if cmd['type'] == 'clean': Valve_EnterWater(chip=output_lines, status=status, action='Off') time.sleep(0.5) + + Valve_MainWater(chip=output_lines, status=status, action='On') + time.sleep(0.5) Valve_PureWater(chip=output_lines, status=status, action='On') time.sleep(0.5) Valve_MixedWater(chip=output_lines, status=status, action='On') time.sleep(clean_duration) + Valve_MainWater(chip=output_lines, status=status, action='Off') + time.sleep(0.5) Valve_PureWater(chip=output_lines, status=status, action='Off') time.sleep(0.5) Valve_MixedWater(chip=output_lines, status=status, action='Off') @@ -393,6 +443,7 @@ def exit_handler(signum, frame): Valve_MixedWater(chip=output_lines, status=status, action='Off') Valve_PureWater(chip=output_lines, status=status, action='Off') Valve_EnterWater(chip=output_lines, status=status, action='Off') + Valve_MainWater(chip=output_lines, status=status, action='Off') client.close() @@ -410,7 +461,10 @@ if __name__ == "__main__": status = [0, 0, 0, 0, 0, 0, 0, 0] signal.signal(signal.SIGINT, exit_handler) - + + main_valve_status = 0 + Valve_MainWater(chip=output_lines, status=status, action='Off') + with open('./config.json', encoding='UTF-8') as f: jsonData = json.load(f)