Exemple #1
0
class MainApp():
    class Constants:
        port = "/dev/tty.usbmodem1421"
        baud = 115200
        close_event = "WM_DELETE_WINDOW"

    def __init__(self):
        for port in list_ports.comports(include_links=True):
            print(port.device, port.name, port.description)

        self.__master = MainView()
        self.__arduino = serial.Serial(self.Constants.port, self.Constants.baud)
        self.__master.protocol(self.Constants.close_event, self.__on_closing)
        self.__update_clock()

    def run(self):
        self.__master.mainloop()

    def __handle_data(self, data):
        clean_values = data.strip(' \n\r').split(",")
        bar_value = int(clean_values[1])
        value_text = clean_values[0]

        self.__master.update_bar(bar_value)
        self.__master.update_text(value_text)


    def __update_clock(self):
        data = self.__arduino.readline().decode()
        self.__handle_data(data)
        self.__master.after(1, self.__update_clock)

    def __on_closing(self):
        self.__arduino.close()
        self.__master.destroy()
Exemple #2
0
class MainApp():
    class Constants:
        port = "COM8"
        baud = 115200
        close_event = "WM_DELETE_WINDOW"
        heigth = 500
        width = 600

    def __init__(self):
        for port in list_ports.comports(include_links=True):
            print(port.device, port.name, port.description)

        self.__master = MainView()
        self.__brain = DrawBrain()
        self.__arduino = serial.Serial(self.Constants.port,
                                       self.Constants.baud)
        self.__master.protocol(self.Constants.close_event, self.__on_closing)
        self.__initial_position = False
        self.__update_clock()
        self.__color = None

    def run(self):
        self.__master.mainloop()

    def __handle_data(self, data):
        clean_values = data.strip(' \r\n').split(',')
        try:
            vertical_value = self.Constants.heigth - int(clean_values[0])
            horizontal_value = int(clean_values[1])
        except Exception:
            return
        else:
            if self.__initial_position:
                coordinates = self.__brain.coordinates(vertical_value,
                                                       horizontal_value)
                self.__master.update_line(coordinates)
            else:
                self.__brain.start(vertical_value, horizontal_value)
                self.__initial_position = True
            self.__master.update_position('Posición: ' +
                                          str(horizontal_value) + ',' +
                                          str(clean_values[0]))

    def __update_clock(self):
        data = self.__arduino.readline().decode()
        self.__handle_data(data)
        self.__master.after(1, self.__update_clock)

    def __on_closing(self):
        self.__arduino.close()
        self.__master.destroy()
Exemple #3
0
class MainApp():
    class Constants:
        port = 'COM3'
        baud = 115200
        close_event = "WM_DELETE_WINDOW"

    def __init__(self):
        self.__master = MainView(tap_button_handler=self.__did_button_tap,
                                 tap_space_handler=self.__did_space_tap)
        self.__port = serial.Serial(self.Constants.port, self.Constants.baud)
        self.__master.protocol(self.Constants.close_event, self.__on_closing)
        self.__update_coordinate()

    def run(self):
        self.__master.mainloop()

    def __did_button_tap(self, color):
        self.__master.ChangeColor.line_color = color

    def __did_space_tap(self):
        self.__master.clean_screen()

    def __update_coordinate(self):
        coordinates = self.__port.readline().decode()
        self.__handle_coordinate(coordinates)
        self.__master.after(5, self.__update_coordinate)

    def __handle_coordinate(self, coordinate):
        clean_values = coordinate.strip(' \n\r').split(",")
        coordinate_y = int(clean_values[1])
        coordinate_x = int(clean_values[3])
        self.__master.update_canvas(coordinate_x, coordinate_y)

    def __on_closing(self):
        self.__port.close()
        self.__master.destroy()