From 21020f398560ba00409936947a0721833bc63cf0 Mon Sep 17 00:00:00 2001 From: sedevc Date: Wed, 15 Jul 2015 15:35:42 +0200 Subject: [PATCH] [F] Status bar, Time left of block timer GUI - add server status, mode, time and block timer in status bar Server - add logic to pass block timer to gui --- abio.py | 6 +++--- cfg/openBC.cfg | 4 ++-- gui.py | 28 +++++++++++++++++++++------- server.py | 9 +++++---- 4 files changed, 31 insertions(+), 16 deletions(-) diff --git a/abio.py b/abio.py index 55a7f2a..4182dc3 100755 --- a/abio.py +++ b/abio.py @@ -34,7 +34,7 @@ def decrease_voltage(self, decrease_value): self.s.ao_set_value(self.analog_pin, self.voltage) def get_rpm(self): temp = self.translate(self.voltage) - if temp < 1.2 or self.contactor == False: + if temp < 244 or self.contactor == False: return 0 elif temp > 2200: return 2200 @@ -104,8 +104,8 @@ def __init__(self): self.data = "" def get(self): return self.data - def put(self, tank_temp, boiler_temp, fire_temp, fan_rpm): - self.data = json.dumps({'TANK': tank_temp, 'BOILER': boiler_temp, 'FIRE': fire_temp, 'FAN RPM': fan_rpm, }) + def put(self, tank_temp, boiler_temp, fire_temp, fan_rpm, mode, time_left): + self.data = json.dumps({'TANK': tank_temp, 'BOILER': boiler_temp, 'FIRE': fire_temp, 'FAN RPM': fan_rpm, 'AUTO': mode, 'TIMER': time_left}) def startWebbServer(a): @route('/api/status') diff --git a/cfg/openBC.cfg b/cfg/openBC.cfg index 6f05ac3..1c6d2dc 100755 --- a/cfg/openBC.cfg +++ b/cfg/openBC.cfg @@ -41,7 +41,7 @@ man_fan_forward_gpio = 4 reset_gpio = 5 [timers] -block_time = 113 +block_time = 210 block_time_idle = 300 run_time_fan_idle = 30 run_time_screw = 2 @@ -49,7 +49,7 @@ run_time_screw_idle = 5 log_block_time = 15 [limits] -tank_set_temp = 27 +tank_set_temp = 24 boiler_set_temp = 35 fire_set_temp = 237 lambda_set_value = 0.9 diff --git a/gui.py b/gui.py index 7640219..7e85212 100755 --- a/gui.py +++ b/gui.py @@ -2,8 +2,7 @@ # -*- coding: utf-8 -*- from Tkinter import * import Tkinter as tk -import ttk as ttk -import PIL, tkFont, socket, json, os, urllib, ConfigParser +import PIL, tkFont, socket, json, os, urllib, ConfigParser, ttk from time import gmtime, strftime from openbccfg import OpenBCcfg @@ -29,6 +28,11 @@ def task(): bTempVar.set(str(int(result['BOILER'])) + "℃") fTempVar.set(str(int(result['FIRE'])) + "℃") fanRpmVar.set(str(int(result['FAN RPM'])) + "rpm") + timeLeftVar.set( "BLOCK TIMER " + str(int(result['TIMER'])) + " (S)") + if result['AUTO'] == 0: + serverModeVar.set("MODE: MANUAL") + else: + serverModeVar.set("MODE: AUTO ") serverStatusVar.set("ONLINE") print result except: @@ -47,6 +51,7 @@ def GetScaleValues(): blockTimeInt.set(int(OB.BLOCK_TIME)) screwRuntimeInt.set(int(OB.RUN_TIME_SCREW)) + def SetScaleValues(): OB.TANK_SET_TEMP = str(tScaleInt.get()) OB.BOILER_SET_TEMP = str(bScaleInt.get()) @@ -70,8 +75,9 @@ def SetScaleValues(): fanRpmVar = StringVar() timeStatusVar = StringVar() serverStatusVar = StringVar() +serverModeVar = StringVar() timeStatusVar.set(str(strftime("%Y-%m-%d %H:%M:%S", gmtime()))) - +timeLeftVar = StringVar() tScaleInt = IntVar() @@ -138,11 +144,19 @@ def SetScaleValues(): statusBar = Label(status, bd=1, relief=SUNKEN, anchor=W, font=("Helvetica", 10)) statusBar.pack(side=BOTTOM ,fill=X) -timeStatus = Label(statusBar, textvariable=timeStatusVar, bd=1, relief=SUNKEN, anchor=W, font=("Helvetica", 10)) -timeStatus.pack(side=LEFT) +timeStatus = Label(statusBar, textvariable=timeStatusVar, bd=1, relief=SUNKEN, anchor=CENTER, font=("Helvetica", 10)) +timeStatus.pack(side=LEFT, ipadx=10) + +serverStatus = Label(statusBar, textvariable=serverStatusVar, bd=1, relief=SUNKEN, anchor=CENTER, font=("Helvetica", 10)) +serverStatus.pack(side=RIGHT, ipadx=10) + +serverMode = Label(statusBar, textvariable=serverModeVar, bd=1, relief=SUNKEN, anchor=CENTER, font=("Helvetica", 10)) +serverMode.pack(side=LEFT, ipadx=10) + +timeLeft = Label(statusBar, textvariable=timeLeftVar, bd=1, relief=SUNKEN, anchor=CENTER, font=("Helvetica", 10)) +timeLeft.pack(side=LEFT, ipadx=10) + -serverStatus = Label(statusBar, textvariable=serverStatusVar, bd=1, relief=SUNKEN, anchor=W, font=("Helvetica", 10)) -serverStatus.pack(side=RIGHT) # ------------------------------- # diff --git a/server.py b/server.py index 7aa914e..ab4f6f4 100755 --- a/server.py +++ b/server.py @@ -1,8 +1,7 @@ #!/usr/bin/env python #!/usr/bin/env python -import socket, sys, time, json, threading -import logging, time, os, sys, os.path +import json, threading, logging, time, os, sys, os.path from pid import Pid from openbccfg import OpenBCcfg from jsonrpclib import Server @@ -25,6 +24,7 @@ TIMESTAMP_CFG = time.ctime(os.path.getmtime(CFG)) TEMP_SCREW_BLOCK_TIMER = time.time() # Read current time, need this for screw controll TEMP_LOG_BLOCK_TIMER = time.time() +TIME_LEFT_OF_BLOCK_TIMER = 0 # Make sure all relay is deactivated for x in xrange(1,9): @@ -57,7 +57,7 @@ logging.info('%s', "Enter main loop") while True: - q.put(TANK.get_temp(), BOILER.get_temp(), FIRE.get_temp(), int(FAN.get_rpm())) # UPPDATE VALUE FOR GUI + q.put(TANK.get_temp(), BOILER.get_temp(), FIRE.get_temp(), int(FAN.get_rpm()), S.input_get_value(OB.BUTTON_AUTO_MAN), TIME_LEFT_OF_BLOCK_TIMER)# UPPDATE VALUE FOR GUI if not TIMESTAMP_CFG == time.ctime(os.path.getmtime(CFG)): # RELOAD CONFIG IF TIMESTAMP CHANGED TIMESTAMP_CFG = time.ctime(os.path.getmtime(CFG)) OB.readConfigFile() @@ -84,6 +84,7 @@ if not FAN.contactor: # ACTIVATE FAN logging.info('%s', "FAN Activate contactor") FAN.activate_contactor() + TIME_LEFT_OF_BLOCK_TIMER = int((int(TEMP_SCREW_BLOCK_TIMER) + int(OB.BLOCK_TIME)) - time.time()) if time.time() > (int(TEMP_SCREW_BLOCK_TIMER) + int(OB.BLOCK_TIME)): # TIMER BELOW BLOCKTIMER? if FIRE.get_temp() <= float(OB.FIRE_SET_TEMP): # FIRE BELOW SET TEMP? if TANK.get_temp() <= float(OB.TANK_SET_TEMP): # TANK BELOW SET TEMP? @@ -115,7 +116,7 @@ FAN.set_voltage(int(OB.FAN_SAFE_MODE_SPEED)) logging.info('%s', "MAN Fan pressed") while S.input_get_value(OB.BUTTON_MAN_FAN_FORWARD): - q.put(TANK.get_temp(), BOILER.get_temp(), FIRE.get_temp(), int(FAN.get_rpm())) # UPPDATE VALUE FOR GUI + q.put(TANK.get_temp(), BOILER.get_temp(), FIRE.get_temp(), int(FAN.get_rpm()), S.input_get_value(OB.BUTTON_AUTO_MAN), TIME_LEFT_OF_BLOCK_TIMER)# UPPDATE VALUE FOR GUI if S.input_get_value(OB.BUTTON_RESET): # REBOOT (MAN FAN + RESET) os.system("sudo reboot") logging.info('%s', "MAN Fan released")