Skip to content

Commit

Permalink
Add scale settings
Browse files Browse the repository at this point in the history
  • Loading branch information
sedevc committed Jul 13, 2015
1 parent 99eee0c commit f4550ec
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 13 deletions.
1 change: 1 addition & 0 deletions cfg/WriteConfig.py
Expand Up @@ -57,6 +57,7 @@
config.set('limits', 'tank_set_temp', '30')
config.set('limits', 'boiler_set_temp', '85')
config.set('limits', 'fire_set_temp', '300')
config.set('limits', 'lambda_set_value', '1.34')
config.set('limits', 'idle_fire_set_temp', '200')

config.add_section('fan')
Expand Down
7 changes: 4 additions & 3 deletions cfg/openBC.cfg
@@ -1,6 +1,6 @@
[info]
hw_name = openWB_viktor_edition
ip = 127.5.0.2
ip = 127.0.0.44
evok_url = http://127.0.0.1/rpc

[boiler_temp_sensor]
Expand Down Expand Up @@ -38,7 +38,7 @@ auto_man_gpio = 2
man_screw_forward_gpio = 3
man_screw_backward_gpio = 4
man_fan_forward_gpio = 4
reset_gpio = 5
reset_gpio = 5

[timers]
block_time = 100
Expand All @@ -52,6 +52,7 @@ log_block_time = 15
tank_set_temp = 30
boiler_set_temp = 85
fire_set_temp = 300
lambda_set_value = 1.34
idle_fire_set_temp = 200

[fan]
Expand All @@ -62,7 +63,7 @@ safe_mode_speed = 2
contactor_pin = 8

[screw]
enabled = True
enabled = 1
type = Relay
contactor_pin = 5

Expand Down
80 changes: 74 additions & 6 deletions gui.py
Expand Up @@ -3,13 +3,18 @@
from Tkinter import *
import Tkinter as tk
import ttk as ttk
import PIL, tkFont
import socket, json, os
import PIL, tkFont, socket, json, os
from openbccfg import OpenBCcfg
import ConfigParser

REST_SERVER_URL = "http://127.0.0.1:5000"

CFG_PATH = "/cfg/"
CFG_FILE = "openBC.cfg"
CFG = os.path.dirname(os.path.abspath(__file__)) + CFG_PATH + CFG_FILE


OB = OpenBCcfg(CFG) # Read config file.
OB.readConfigFile()

#################################################################
######################### GUI ###################################
Expand All @@ -30,6 +35,23 @@ def task():
pass
s.close()
root.after(1000,task)


def GetScaleValues():
tScaleInt.set(int(OB.TANK_SET_TEMP))
bScaleInt.set(int(OB.BOILER_SET_TEMP))
fScaleInt.set(int(OB.FIRE_SET_TEMP))
lScaleFloat.set(float(OB.LAMBDA_SET_VALUE))

def SetScaleValues():
config = ConfigParser.RawConfigParser()
config.set('limits', 'tank_set_temp', '15')
config.set('limits', 'boiler_set_temp', '40')
config.set('limits', 'fire_set_temp', '300')
config.set('limits', 'lambda_set_value', '1.34')
with open(CFG, 'ab') as configfile:
config.write(configfile)

# ----------- GUI ROOT ------------ #

root = tk.Tk()
Expand All @@ -43,6 +65,12 @@ def task():
fTempVar = StringVar()
fanRpmVar = StringVar()

tScaleInt = IntVar()
bScaleInt = IntVar()
fScaleInt = IntVar()
lScaleFloat = DoubleVar()


tTempVar.set(0)
bTempVar.set(0)
fTempVar.set(0)
Expand Down Expand Up @@ -93,9 +121,49 @@ def task():
FanLabel.place(x=510, y=190)
# ------------------------------- #

# put a button widget on child frame f1 on page1
btn1 = tk.Button(log, text='button1')
btn1.pack(side='left', anchor='nw', padx=3, pady=5)
GetScaleValues()

# ---------- Slides ------------- #

tankLabel = Label(settings, font=("Helvetica", 14), text="Tank target ℃")
tankLabel.grid(sticky=SE, row=0, column=0)

tankScale = Scale(settings, variable=tScaleInt, takefocus=0, from_=0, to=100, length=600, width="25", orient=HORIZONTAL)

tankScale.grid(padx=20, pady=0,row=0, column=1)
#########
boilerLabel = Label(settings, font=("Helvetica", 14), text="Boiler target ℃")
boilerLabel.grid(sticky=SE, row=1, column=0)

boilerScale = Scale(settings, variable=bScaleInt, takefocus=0, from_=0, to=100, length=600, width="25", orient=HORIZONTAL)

boilerScale.grid(padx=20, pady=0,row=1, column=1)
##########
fireLabel = Label(settings, font=("Helvetica", 14), text="Fire target ℃")
fireLabel.grid(sticky=SE, row=2, column=0)

fireScale = Scale(settings, variable=fScaleInt, takefocus=0, from_=0, to=800, length=600, width="25", orient=HORIZONTAL)

fireScale.grid(padx=20, pady=0,row=2, column=1)
##########
lambdaLabel = Label(settings, font=("Helvetica", 14), text="Lambda target λ")
lambdaLabel.grid(sticky=SE, row=3, column=0)

lambdaScale = Scale(settings, variable=lScaleFloat, takefocus=0, from_=0.65, to=1.6, resolution=0.02, length=600, width="25", orient=HORIZONTAL)

lambdaScale.grid(padx=20, pady=0,row=3, column=1)


setButton = Button(settings, command=SetScaleValues, text='SET')
#setButton.pack(side='left', anchor='nw', padx=3, pady=5)
setButton.grid(sticky=SE, padx=5, pady=25, row=4, column=0)

setButton = Button(settings, command=GetScaleValues, text='GET')
#setButton.pack(side='left', anchor='nw', padx=3, pady=5)
setButton.grid(sticky=SW, padx=5, pady=25, row=4, column=0)

# ------------------------------- #



root.after(1000,task)
Expand Down
98 changes: 95 additions & 3 deletions openbccfg.py
Expand Up @@ -5,7 +5,11 @@ class OpenBCcfg(object):
def __init__(self, file_name):

self.config = ConfigParser.RawConfigParser()
self.config.read(file_name)
self.file_name = file_name


def readConfigFile(self):
self.config.read(self.file_name)

self.HW_NAME = self.config.get("info", "hw_name")
self.IP = self.config.get("info", "ip")
Expand Down Expand Up @@ -55,6 +59,7 @@ def __init__(self, file_name):
self.TANK_SET_TEMP = self.config.get("limits", "tank_set_temp")
self.BOILER_SET_TEMP = self.config.get("limits", "boiler_set_temp")
self.FIRE_SET_TEMP = self.config.get("limits", "fire_set_temp")
self.LAMBDA_SET_VALUE = self.config.get("limits", "lambda_set_value")
self.IDLE_FIRE_SET_TEMP = self.config.get("limits", "idle_fire_set_temp")

self.FAN_ENABLED = self.config.get("fan", "enabled")
Expand All @@ -74,6 +79,93 @@ def __init__(self, file_name):
self.LOG_BASE_DIR = self.config.get("log", "base_dir")
self.LOG_FILE_NAME = self.config.get("log", "file_name")

def WriteConfigFile(self):


self.config.set('info', 'hw_name', self.HW_NAME)
self.config.set('info', 'ip', self.IP)
self.config.set('info', 'evok_url', self.EVOK_URL)

self.config.set('boiler_temp_sensor', 'enabled', self.BOILER_TEMP_SENSOR_ENABLED)
self.config.set('boiler_temp_sensor', 'type', self.BOILER_TEMP_SENSOR_TYPE)
self.config.set('boiler_temp_sensor', 'base_dir', self.BOILER_TEMP_SENSOR_BASE_DIR)
self.config.set('boiler_temp_sensor', 'file_name', self.BOILER_TEMP_SENSOR_FILE_NAME)
self.config.set('boiler_temp_sensor', 'id', self.BOILER_TEMP_SENSOR_ID)

self.config.set('tank_temp_sensor', 'enabled', self.TANK_TEMP_SENSOR_ENABLED)
self.config.set('tank_temp_sensor', 'type', self.TANK_TEMP_SENSOR_TYPE)
self.config.set('tank_temp_sensor', 'base_dir', self.TANK_TEMP_SENSOR_BASE_DIR)
self.config.set('tank_temp_sensor', 'file_name', self.TANK_TEMP_SENSOR_FILE_NAME)
self.config.set('tank_temp_sensor', 'id', self.TANK_TEMP_SENSOR_ID)


self.config.set('fire_temp_sensor', 'enabled', self.FIRE_TEMP_SENSOR_ENABLED)
self.config.set('fire_temp_sensor', 'type', self.FIRE_TEMP_SENSOR_TYPE)
self.config.set('fire_temp_sensor', 'analog_pin', self.FIRE_TEMP_SENSOR_ANALOG_PIN)


self.config.set('lambda_sensor', 'enabled', self.LAMBDA_SENSOR_ENABLED)
self.config.set('lambda_sensor', 'type', self.LAMBDA_SENSOR_TYPE)
self.config.set('lambda_sensor', 'port', self.LAMBDA_SENSOR_PORT)
self.config.set('lambda_sensor', 'baud', self.LAMBDA_SENSOR_BAUD)
self.config.set('lambda_sensor', 'sync_header_attempt', self.LAMBDA_SENSOR_SYNC_HEADER_ATTEMPT)
self.config.set('lambda_sensor', 'analog_pin', self.LAMBDA_SENSOR_ANALOG_PIN)
self.config.set('lambda_sensor', 'contactor_pin', self.LAMBDA_SENSOR_CONTACTOR_PIN)


self.config.set('control_button', 'contactor_pin', self.BUTTON_CONTACTOR_PIN)
self.config.set('control_button', 'emergency_stop_gpio', self.BUTTON_EMERGENCY_STOP)
self.config.set('control_button', 'auto_man_gpio', self.BUTTON_AUTO_MAN)
self.config.set('control_button', 'man_screw_forward_gpio', self.BUTTON_MAN_SCREW_FORWARD)
self.config.set('control_button', 'man_screw_backward_gpio', self.BUTTON_MAN_SCREW_BACKWARD)
self.config.set('control_button', 'man_fan_forward_gpio', self.BUTTON_MAN_FAN_FORWARD)
self.config.set('control_button', 'reset_gpio', self.BUTTON_RESET)


self.config.set('timers', 'block_time', self.BLOCK_TIME)
self.config.set('timers', 'block_time_idle', self.BLOCK_TIME_IDLE)
self.config.set('timers', 'run_time_fan_idle', self.RUN_TIME_FAN_IDLE)
self.config.set('timers', 'run_time_screw', self.RUN_TIME_SCREW)
self.config.set('timers', 'run_time_screw_idle', self.RUN_TIME_SCREW_IDLE)
self.config.set('timers', 'log_block_time', self.LOG_BLOCK_TIME)


self.config.set('limits', 'tank_set_temp', self.TANK_SET_TEMP)
self.config.set('limits', 'boiler_set_temp', self.BOILER_SET_TEMP)
self.config.set('limits', 'fire_set_temp', self.FIRE_SET_TEMP)
self.config.set('limits', 'lambda_set_value', self.LAMBDA_SET_VALUE)
self.config.set('limits', 'idle_fire_set_temp', self.IDLE_FIRE_SET_TEMP)


self.config.set('fan', 'enabled', self.FAN_ENABLED)
self.config.set('fan', 'type', self.FAN_TYPE)
self.config.set('fan', 'analog_pin', self.FAN_ANALOG_PIN)
self.config.set('fan', 'safe_mode_speed', self.FAN_SAFE_MODE_SPEED)
self.config.set('fan', 'contactor_pin', self.FAN_CONTACTOR_PIN)


self.config.set('screw', 'enabled', self.SCREW_ENABLED)
self.config.set('screw', 'type', self.SCREW_TYPE)
self.config.set('screw', 'contactor_pin', self.SCREW_CONTACTOR_PIN)


self.config.set('database', 'enabled', self.DATABASE_ENABLED)
self.config.set('database', 'type', self.DATABASE_TYPE)
self.config.set('database', 'db_name', self.DATABASE_NAME)

self.config.set('log', 'base_dir', self.LOG_BASE_DIR)
self.config.set('log', 'file_name', self.LOG_FILE_NAME)

with open(self.file_name, 'wb') as configfile:
self.config.write(configfile)

if __name__ == "__main__":
openBCcfg = openBCcfg("openWB.cfg")
print openBCcfg.LAMBDA_SENSOR_PORT
openBCcfg = OpenBCcfg("cfg/openBC.cfg")
openBCcfg.readConfigFile()
openBCcfg.IP = "127.0.0.44"
openBCcfg.SCREW_ENABLED = "1"
openBCcfg.WriteConfigFile()




3 changes: 2 additions & 1 deletion server.py
Expand Up @@ -23,7 +23,8 @@


CFG = os.path.dirname(os.path.abspath(__file__)) + CFG_PATH + CFG_FILE
OB = OpenBCcfg(CFG) # Read config file.
OB = OpenBCcfg(CFG)
OB.readConfigFile() # Read config file.
time.sleep(2)
S = Server(OB.EVOK_URL) # Connection to evok api

Expand Down

0 comments on commit f4550ec

Please sign in to comment.