Пример #1
0
Файл: main.py Проект: mr-pf/co2
def start_app():

    # Create Tinkerforge instances
    ip_con = IPConnection()
    ip_con.set_timeout(10)
    ip_con.connect('localhost', 4223)
    controller.BrickletHandler.monitor_ip_connection(ip_con=ip_con)

    bricklet_factory = controller.BrickletFactory()
    quad_relay_1 = bricklet_factory. \
        create_and_configure_bricklet('quad_relay', 'BC8', ip_con)
    quad_relay_2 = bricklet_factory. \
        create_and_configure_bricklet('quad_relay', 'BCE', ip_con)
    rs232 = bricklet_factory. \
        create_and_configure_bricklet('rs232', 'Cvu', ip_con)
    analog_in = bricklet_factory. \
        create_and_configure_bricklet('analog_in', 'CNA', ip_con)

    # controller Setup
    channel = controller.ChannelController(quad_relay_1, quad_relay_2)
    co2flow = controller.Co2FlowController(rs232)
    airflow = controller.AirFlowController(analog_in)
    sensor = controller.SensorController(analog_in)
    concentration = controller.ConcentrationController(sensor, airflow, co2flow)
    sequence = controller.SequenceController(concentration, channel)

    # logging
    data_logger = data.DataLogger()
    log_dir = 'log'
    if not os.path.exists(log_dir):
        os.mkdir(log_dir)
    prefix = time.strftime('%y%m%d_%H%M%S')

    data_file_path = os.path.join(log_dir, f'{prefix}_data.csv')
    log_file_path = os.path.join(log_dir, f'{prefix}_log.txt')

    logger.set_log_file(log_file_path)
    data_logger.set_file(data_file_path)

    # main components
    main_controller = controller.MainController(
        channel_controller=channel,
        co2_flow_controller=co2flow,
        air_flow_controller=airflow,
        sensor_controller=sensor,
        concentration_controller=concentration,
        sequence_controller=sequence,
        data_logger=data_logger
    )
    gui = tk_gui.MainFrame()
    main_controller.set_gui(gui)

    # Start app
    main_controller.initialize()
    gui.mainloop()

    # Wrap up
    main_controller.set_co2_flow(flow_rate=0)
    main_controller.set_channel(data.Channels.NONE)
    ip_con.disconnect()
Пример #2
0
 def __init__(self):
     #no more than one instance is needed at a time
     if Bot.__single:
         raise ErrorHandler("Bot class cannot be instantiated more than once")
     Bot.__single = self
     
     self.primary_controller = controller.MainController()
Пример #3
0
def main():

    disp = display.pilcddisplay.PiLcdDisplay(lines=4,
                                             line_length=20,
                                             update_interval=0.5)

    cont = controller.MainController(
        interface.mpdinterface.MpdInterface(), disp,
        formatter.standardformatter.StandardFormatter())

    cont.init()

    try:
        cont.start()

        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        print("Caught KeyboardInterrupt...")
        cont.stop()
        sys.exit(1)
Пример #4
0
def main_controller():
    main_controller = controller.MainController(
        power_controller=mock.Mock(controller.PowerController(mock.Mock())),
        channel_controller=mock.Mock(
            controller.ChannelController(mock.Mock(), mock.Mock())),
        co2_flow_controller=mock.Mock(controller.Co2FlowController(
            mock.Mock())),
        air_flow_controller=mock.Mock(
            controller.AirFlowController(mock.Mock(), mock.Mock())),
        sensor_controller=mock.Mock(controller.SensorController(mock.Mock())),
        concentration_controller=mock.Mock(
            controller.ConcentrationController(mock.Mock(), mock.Mock(),
                                               mock.Mock())),
        sequence_controller=mock.Mock(
            controller.SequenceController(mock.Mock(), mock.Mock())),
        data_logger=mock.Mock(data.DataLogger))

    main_controller._gui = mock.Mock(interfaces.GuiInterface)
    main_controller._power_controller.state_main = True
    main_controller._power_controller.state_pump = True
    main_controller._concentration_controller.active = True
    main_controller._sequence_controller.active = False
    return main_controller