forked from zietzm/Helmholtz_Test_Bench
added edit_config function
This commit is contained in:
+18
-5
@@ -172,20 +172,33 @@ class ArduinoCtrl(Arduino):
|
||||
self.digitalWrite(pin, "LOW")
|
||||
|
||||
|
||||
def read_config(section, key): # attempt to read config file
|
||||
def read_config(section, key): # read specific value from config file
|
||||
# ToDo (optional) better error handling
|
||||
file = g.CONFIG_FILE
|
||||
config_object = ConfigParser()
|
||||
try:
|
||||
config_object.read(file)
|
||||
config_object.read(g.CONFIG_FILE)
|
||||
section_obj = config_object[section]
|
||||
return section_obj[key]
|
||||
except KeyError as e:
|
||||
ui_print("Error while reading config file: e")
|
||||
ui_print("Error while reading config file:", e)
|
||||
raise KeyError("Could not find key", key, "in config file.")
|
||||
|
||||
|
||||
def create_default_config(file):
|
||||
def edit_config(section, key, value): # edit specific value in config file
|
||||
config_object = ConfigParser()
|
||||
try:
|
||||
config_object.read(g.CONFIG_FILE)
|
||||
section_obj = config_object[section]
|
||||
section_obj[key] = str(value)
|
||||
|
||||
with open(g.CONFIG_FILE, 'w') as conf: # Write changes back to file
|
||||
config_object.write(conf)
|
||||
except KeyError as e:
|
||||
ui_print("Error while editing config file:", e)
|
||||
raise KeyError("Could not find key", key, "in config file.")
|
||||
|
||||
|
||||
def create_default_config(file): # create config file from default values (stored in globals.py)
|
||||
config = ConfigParser()
|
||||
|
||||
i = 0
|
||||
|
||||
@@ -17,12 +17,6 @@ AXIS_NAMES = ["X-Axis", "Y-Axis", "Z-Axis"]
|
||||
|
||||
global CONFIG_FILE
|
||||
|
||||
'''global COIL_CONST
|
||||
global RESISTANCES
|
||||
global MAX_WATTS
|
||||
global MAX_VOLTS
|
||||
global AMBIENT_FIELD'''
|
||||
|
||||
global XY_PORT
|
||||
global Z_PORT
|
||||
global RELAY_PINS
|
||||
|
||||
Reference in New Issue
Block a user