def test_tinker_output(self):
     command_handler = Esp4sCommandHandlers('/dev/ttyACM0')
     rval = command_handler.tinker_output(['tinker_out', 'A', '200'])
     self.assertEqual(rval, "okay")
     rval = command_handler.tinker_output(['tinker_out', 'B', '200'])
     self.assertEqual(rval, "okay")
     rval = command_handler.tinker_output(['tinker_out', 'A', '0'])
     self.assertEqual(rval, "okay")
     rval = command_handler.tinker_output(['tinker_out', 'B', '0'])
     self.assertEqual(rval, "okay")
 def test_set_leds(self):
     command_handler = Esp4sCommandHandlers('/dev/ttyACM0')
     rval = command_handler.set_leds(['leds', 'Red', '240'])
     self.assertEqual(rval, "okay")
     rval = command_handler.set_leds(['leds', 'Red', '0'])
     self.assertEqual(rval, "okay")
     rval = command_handler.set_leds(['leds', 'Blue', '240'])
     self.assertEqual(rval, "okay")
     rval = command_handler.set_leds(['leds', 'Blue', '0'])
     self.assertEqual(rval, "okay")
     rval = command_handler.set_leds(['leds', 'Green', '240'])
     self.assertEqual(rval, "okay")
     rval = command_handler.set_leds(['leds', 'Green', '0'])
     self.assertEqual(rval, "okay")
Esempio n. 3
0
def esp4s():
    """
    This is the "main" function of the program.
    """
    # make sure we have a log directory and if not, create it.
    if not os.path.exists('log'):
        os.makedirs('log')

    # turn on logging
    logging.basicConfig(filename='./log/esp4s_debugging.log',
                        filemode='w',
                        level=logging.DEBUG)
    logging.info(
        'esp4s Version 1.0    Copyright(C) 2015 Alan Yorinks    All Rights Reserved '
    )
    print(
        'esp4s version 1.0   Copyright(C) 2015 Alan Yorinks    All Rights Reserved '
    )

    # get the com_port from the command line or default if none given
    # if user specified the com port on the command line, use that when invoking PyMata,
    # else use '/dev/ttyACM0'
    if len(sys.argv) == 2:
        com_port = str(sys.argv[1])
    else:
        com_port = '/dev/ttyACM0'
    logging.info('com port = %s' % com_port)

    try:
        # instantiate the command handler
        command_handler = Esp4sCommandHandlers(com_port)
        # start the esp4s_http server
        command_handler.start_http_server()
    except OSError:
        print("\nDid you plug in the Esplora? Can't find " + com_port)
    except serial.SerialException:
        print("")
        print("Could not open serial port" + com_port)
        print("Did you plug in the Esplora?")
    except IndexError:
        print("Reset the Esplora and reset the server.")
    except TypeError:
        print("Reset the Esplora and reset the server.")
    except Exception:
        logging.debug('Exception in esp4s_http.py %s' % str(Exception))
    except KeyboardInterrupt:
        # give control back to the shell that started us
        logging.debug('Exception in esp4s_http.py %s' % str(Exception))
 def test_set_board_led(self):
     command_handler = Esp4sCommandHandlers('/dev/ttyACM0')
     rval = command_handler.set_board_led(['board_led', 'On'])
     self.assertEqual(rval, "okay")
     rval = command_handler.set_board_led(['board_led', 'Off'])
     self.assertEqual(rval, "okay")
 def test_reset_esplora(self):
     command_handler = Esp4sCommandHandlers('/dev/ttyACM0')
     rval = command_handler.reset_esplora("abc")
     self.assertEqual(rval, "okay")
 def test_send_cross_domain_policy(self):
     command_handler = Esp4sCommandHandlers('/dev/ttyACM0')
     #noinspection PyUnusedLocal
     rval = None
     rval = command_handler.send_cross_domain_policy("crossdomain.xml")
     self.assertNotEqual(rval, None)
 def test_pop_status(self):
     command_handler = Esp4sCommandHandlers('/dev/ttyACM0')
     rval = command_handler.pop_status()
     self.assertEqual(rval, False)
 def test_poll(self):
     command_handler = Esp4sCommandHandlers('/dev/ttyACM0')
     rval = command_handler.do_command(["poll"])
     self.assertEqual(rval, "okay")
 def test_temp_units(self):
     command_handler = Esp4sCommandHandlers('/dev/ttyACM0')
     rval = command_handler.temp_units(["a", "b"])
     self.assertEqual(rval, "okay")
Esempio n. 10
0
 def test_orientation(self):
     command_handler = Esp4sCommandHandlers('/dev/ttyACM0')
     rval = command_handler.orientation(["a", "b"])
     self.assertEqual(rval, "okay")
Esempio n. 11
0
 def test_get_snap_status(self):
     command_handler = Esp4sCommandHandlers('/dev/ttyACM0')
     rval = command_handler.get_snap_status(["light"])
     self.assertEqual(rval, "okay")
Esempio n. 12
0
 def test_continuous_tone(self):
     command_handler = Esp4sCommandHandlers('/dev/ttyACM0')
     command_handler.continuous_tone(['tone2', '1000'])
     rval = command_handler.play_tone(['play_tone', 'Note_Off'])
     self.assertEqual(rval, "okay")
Esempio n. 13
0
 def test_play_tone(self):
     command_handler = Esp4sCommandHandlers('/dev/ttyACM0')
     # noinspection PyUnusedLocal
     rval = command_handler.play_tone(['play_tone', 'C'])
     rval = command_handler.play_tone(['play_tone', 'Note_Off'])
     self.assertEqual(rval, "okay")