def gpio_output_1_off_after_timer(): if (timers.val == "Timer_1"): tkMessageBox.showinfo( "unimplemented", "GPIO: " + gpio_array[0].gpio_label + "Port: " + gpio_array[0].gpio_port + "OFF after timer: " + timers.timer_1 + "(seconds)") rpi_gpio_lib.set_port(gpio_array[0].gpio_port) rpi_gpio_lib.set_timer(timers.timer_1) # timer from timers.txt rpi_gpio_lib.run_off_after_timer() if (timers.val == "Timer_2"): tkMessageBox.showinfo( "unimplemented", "GPIO: " + gpio_array[0].gpio_label + "Port: " + gpio_array[0].gpio_port + "OFF after timer: " + timers.timer_2 + "(seconds)") rpi_gpio_lib.set_port(gpio_array[0].gpio_port) rpi_gpio_lib.set_timer(timers.timer_2) # timer from timers.txt rpi_gpio_lib.run_off_after_timer() if (timers.val == "Timer_3"): tkMessageBox.showinfo( "unimplemented", "GPIO: " + gpio_array[0].gpio_label + "Port: " + gpio_array[0].gpio_port + "OFF after timer: " + timers.timer_3 + "(seconds)") rpi_gpio_lib.set_port(gpio_array[0].gpio_port) rpi_gpio_lib.set_timer(timers.timer_3) # timer from timers.txt rpi_gpio_lib.run_off_after_timer() message = "GPIO 1 -> ___ " + gpio_array[0].gpio_label + " ___ ON ! " log_creator.log_write(message)
def gpio_output_script(): name = askopenfilename() rpi_gpio_lib.set_path(name) rpi_gpio_lib.run_my_script() message = "Loaded " + name + " script" log_creator.log_write(message)
def save_conf(): conf = open("conf.txt", "wb") conf.write("===== GPIO 1 =====\r\n") conf.write("type=" + str(var_gpio1.get()) + "\r\n") conf.write("port=" + str(gpio1_op.get()) + "\r\n") conf.write("label=" + str(gpio_1_text_label.get()) + "\r\n") conf.write("==================\r\n") conf.write("===== GPIO 2 =====\r\n") conf.write("type=" + str(var_gpio2.get()) + "\r\n") conf.write("port=" + str(gpio2_op.get()) + "\r\n") conf.write("label=" + str(gpio_2_text_label.get()) + "\r\n") conf.write("==================\r\n") conf.write("===== GPIO 3 =====\r\n") conf.write("type=" + str(var_gpio3.get()) + "\r\n") conf.write("port=" + str(gpio3_op.get()) + "\r\n") conf.write("label=" + str(gpio_3_text_label.get()) + "\r\n") conf.write("==================\r\n") conf.write("===== GPIO 4 =====\r\n") conf.write("type=" + str(var_gpio4.get()) + "\r\n") conf.write("port=" + str(gpio4_op.get()) + "\r\n") conf.write("label=" + str(gpio_4_text_label.get()) + "\r\n") conf.write("==================\r\n") conf.write("===== GPIO 5 =====\r\n") conf.write("type=" + str(var_gpio5.get()) + "\r\n") conf.write("port=" + str(gpio5_op.get()) + "\r\n") conf.write("label=" + str(gpio_5_text_label.get()) + "\r\n") conf.write("==================\r\n") conf.close() tkMessageBox.showinfo("save", "Saved Configuration to conf.txt") log_creator.log_write("Saved new configuration to conf.txt")
def gui_main_window(): #main_window = Tkinter.Tk() # ai voie doar o instanta de Tk(), restul trebe sa fie Toplevel #main_window.title("RPI GPIO Manager") #main_window.geometry("200x200") menu_bar = Menu(main_window) main_window.config(menu=menu_bar) file_menu = Menu(menu_bar) # menu item 1 config_menu = Menu(menu_bar) # menu item 2 settings_menu = Menu(menu_bar) # menu item 3 # menu item 1 menu_bar.add_cascade(label="File", menu=file_menu) file_menu.add_command(label="Load Configuration", command=load_configuration) file_menu.add_command(label="Exit", command=exit_app) # menu item 2 menu_bar.add_cascade(label="Configure", menu=config_menu) config_menu.add_command(label="GPIO Layout", command=gui_gpio_layout) config_menu.add_command(label="Configure GPIO", command=gui_config_window) config_menu.add_command(label="Configure Timers", command=gui_timers_window) # menu item 3 menu_bar.add_cascade(label="Settings", menu=settings_menu) settings_menu.add_command(label="Options", command=gui_options_window) main_window.mainloop() log_creator.log_write("Main Window opened")
def gui_options_window(): option_window = Tkinter.Toplevel() option_window.title("Options") option_window.geometry("600x200") load_options_frame(option_window) log_creator.log_write("Options window opened")
def gui_config_window(): config_window = Tkinter.Toplevel() # ai voie doar o instanta de Tk() config_window.title("Configuration") config_window.geometry("500x350") load_config_frame(config_window) log_creator.log_write("Configure window opened")
def gui_timers_window(): timers_window = Tkinter.Toplevel() # ai voie doar o instanta de Tk() timers_window.title("Timers") timers_window.geometry("400x250") load_timers_frame(timers_window) log_creator.log_write("Configure window opened")
def gpio_output_5_off_command(): GPIO.setup( int(gpio_array[4].gpio_port), GPIO.OUT ) # must be int (string not allowed)(comes as string when reading from conf file) GPIO.output(int(gpio_array[4].gpio_port), GPIO.LOW) message = "GPIO 5 -> ___ " + gpio_array[4].gpio_label + " ___ OFF ! " log_creator.log_write(message)
def gpio_output_4_on_command(): GPIO.setup( int(gpio_array[3].gpio_port), GPIO.OUT ) # must be int (string not allowed)(comes as string when reading from conf file) GPIO.output(int(gpio_array[3].gpio_port), GPIO.HIGH) message = "GPIO 4 -> ___ " + gpio_array[3].gpio_label + " ___ ON ! " log_creator.log_write(message)
def save_timers(): timers = open("timers.txt", "wb") timers.write("timer_1 =" + str(t1.get()) + "\r\n") timers.write("timer_2 =" + str(t2.get()) + "\r\n") timers.write("timer_3 =" + str(t3.get()) + "\r\n") timers.close() tkMessageBox.showinfo("save", "Saved Timers to timers.txt") log_creator.log_write("Saved new timers values to timers.txt")
def create_config_gui(): input_label = Label(main_window, text="INPUTS") input_label.place(x=0, y=0) log_creator.log_write("Creating Configure Inputs panel ...") generate_inputs() output_label = Label(main_window, text="OUTPUTS") output_label.place(x=0, y=300) generate_outputs() log_creator.log_write("Finished generating Config panel")
def gpio_output_1_on_command(): GPIO.setup( int(gpio_array[0].gpio_port), GPIO.OUT ) # must be int (string not allowed)(comes as string when reading from conf file) GPIO.output(int(gpio_array[0].gpio_port), GPIO.HIGH) #rpi_gpio_lib.run() #subprocess.rpi_gpio_lib.run() #subprocess.call("/home/pi/dizertatie/app/rpi_gpio_lib.py", shell=True) #rpi_gpio_lib.run(int(gpio_array[0].gpio_port), 15) #print type(gpio_array[0].gpio_port) #print int(gpio_array[0].gpio_port) #print type(int(gpio_array[0].gpio_port)) message = "GPIO 1 -> ___ " + gpio_array[0].gpio_label + " ___ ON ! " log_creator.log_write(message)
def generate_outputs(): if (gpio_array[0].gpio_type[0] == "1"): gpio_1_label = Label(main_window, text=gpio_array[0].gpio_label) gpio_1_label.place(x=30, y=330) gpio_output_1_on = Button(main_window, text="ON", width=3, command=gpio_output_1_on_command) gpio_output_1_on.place(x=50, y=350) optionList = ('Timer_1', 'Timer_2', 'Timer_3') timers_op = StringVar() timers_op.set(optionList[0]) om_gpio1 = OptionMenu(main_window, timers_op, *optionList) om_gpio1.place(x=320, y=350) def set_timer_op(): timers.val = timers_op.get() tkMessageBox.showinfo("Timer Dialog", timers.val + " was set !") set_timers_button = Button(main_window, text="Set", width=3, command=set_timer_op) set_timers_button.place(x=400, y=350) gpio_output_1_stay_awake = Button(main_window, text="ON after", width=6, command=gpio_output_1_on_after_timer) gpio_output_1_stay_awake.place(x=170, y=350) gpio_output_1_off_after = Button(main_window, text="OFF after", width=6, command=gpio_output_1_off_after_timer) gpio_output_1_off_after.place(x=240, y=350) gpio_output_1_off = Button(main_window, text="OFF", width=3, command=gpio_output_1_off_command) gpio_output_1_off.place(x=100, y=350) gpio_output_1_script = Button(main_window, text="Run Script", width=5, command=gpio_output_script) gpio_output_1_script.place(x=300, y=450) log_creator.log_write("Finished creating output GPIO 1") if (gpio_array[1].gpio_type[0] == "1"): gpio_2_label = Label(main_window, text=gpio_array[1].gpio_label) gpio_2_label.place(x=30, y=380) gpio_input_2_on = Button(main_window, text="ON", width=10, command=gpio_output_2_on_command) gpio_input_2_on.place(x=50, y=400) gpio_input_2_off = Button(main_window, text="OFF", width=10, command=gpio_output_2_off_command) gpio_input_2_off.place(x=150, y=400) log_creator.log_write("Finished creating output GPIO 2") if (gpio_array[2].gpio_type[0] == "1"): gpio_3_label = Label(main_window, text=gpio_array[2].gpio_label) gpio_3_label.place(x=30, y=430) gpio_input_3_on = Button(main_window, text="ON", width=10, command=gpio_output_3_on_command) gpio_input_3_on.place(x=50, y=450) gpio_input_3_off = Button(main_window, text="OFF", width=10, command=gpio_output_3_off_command) gpio_input_3_off.place(x=150, y=450) log_creator.log_write("Finished creating output GPIO 3") if (gpio_array[3].gpio_type[0] == "1"): gpio_4_label = Label(main_window, text=gpio_array[3].gpio_label) gpio_4_label.place(x=30, y=480) gpio_input_4_on = Button(main_window, text="ON", width=10, command=gpio_output_4_on_command) gpio_input_4_on.place(x=50, y=500) gpio_input_4_off = Button(main_window, text="OFF", width=10, command=gpio_output_4_off_command) gpio_input_4_off.place(x=150, y=500) log_creator.log_write("Finished creating output GPIO 4") if (gpio_array[4].gpio_type[0] == "1"): gpio_5_label = Label(main_window, text=gpio_array[4].gpio_label) gpio_5_label.place(x=30, y=530) gpio_input_5_on = Button(main_window, text="ON", width=10, command=gpio_output_5_on_command) gpio_input_5_on.place(x=50, y=550) gpio_input_5_off = Button(main_window, text="OFF", width=10, command=gpio_output_5_off_command) gpio_input_5_off.place(x=150, y=550) log_creator.log_write("Finished creating output GPIO 5") log_creator.log_write("Finished generating Outputs panel")
def generate_inputs(): if (gpio_array[0].gpio_type[0] == "0"): gpio_1_label = Label(main_window, text=gpio_array[0].gpio_label) gpio_1_label.place(x=30, y=30) gpio_input_button_1 = Button(main_window, text="Get Data", width=10, command=get_store_input_gpio_5) gpio_input_button_1.place(x=50, y=50) gpio_1_label_store = Label( main_window, text= "D:\\USERDATA\\E4COSVL\\Personal\\Dizertatie\\app\\temp_log.txt") gpio_1_label_store.place(x=150, y=50) log_creator.log_write("Finished creating input GPIO 1") if (gpio_array[1].gpio_type[0] == "0"): gpio_2_label = Label(main_window, text=gpio_array[1].gpio_label) gpio_2_label.place(x=30, y=80) gpio_input_button_2 = Button(main_window, text="Get Data", width=10, command=get_store_input_gpio_5) gpio_input_button_2.place(x=50, y=100) gpio_2_label_store = Label( main_window, text= "D:\\USERDATA\\E4COSVL\\Personal\\Dizertatie\\app\\temp_log.txt") gpio_2_label_store.place(x=150, y=100) log_creator.log_write("Finished creating input GPIO 2") if (gpio_array[2].gpio_type[0] == "0"): gpio_3_label = Label(main_window, text=gpio_array[2].gpio_label) gpio_3_label.place(x=30, y=130) gpio_input_button_3 = Button(main_window, text="Get Data", width=10, command=get_store_input_gpio_5) gpio_input_button_3.place(x=50, y=150) gpio_3_label_store = Label( main_window, text= "D:\\USERDATA\\E4COSVL\\Personal\\Dizertatie\\app\\temp_log.txt") gpio_3_label_store.place(x=150, y=150) log_creator.log_write("Finished creating input GPIO 3") if (gpio_array[3].gpio_type[0] == "0"): gpio_4_label = Label(main_window, text=gpio_array[3].gpio_label) gpio_4_label.place(x=20, y=20) gpio_input_button_4 = Button(main_window, text="Get Data", width=10, command=get_store_input_gpio_5) gpio_input_button_4.place(x=30, y=40) #gpio_4_label_store = Label(main_window, text="D:\\USERDATA\\E4COSVL\\Personal\\Dizertatie\\app\\log.txt") #gpio_4_label_store.place(x=150, y=30) log_creator.log_write("Finished creating input GPIO 4") if (gpio_array[4].gpio_type[0] == "0"): gpio_5_label = Label(main_window, text=gpio_array[4].gpio_label) gpio_5_label.place(x=30, y=230) gpio_input_button_5 = Button(main_window, text="Get Data", width=10, command=get_store_input_gpio_5) gpio_input_button_5.place(x=50, y=250) gpio_5_label_store = Label( main_window, text= "D:\\USERDATA\\E4COSVL\\Personal\\Dizertatie\\app\\temp_log.txt") gpio_5_label_store.place(x=150, y=250) log_creator.log_write("Finished creating input GPIO 5") log_creator.log_write("Finished generating Inputs panel")
def load_configuration(): log_creator.log_write("Load configuration conf.txt") get_data_from_conf() log_creator.log_write("Loaded Configuration conf.txt")