Ejemplo n.º 1
0
    def test_capabilities(self):
        conn = ConnectionMock()
        conn.notifications.append(
            (14, '1b0e00 0f00 04 01 0125000000001000000010'))
        conn.notifications.append(
            (14, '1b0e00 0f00 04 02 0126000000001000000010'))
        conn.notifications.append(
            (14, '1b0e00 0f00 04 37 0127000100000001000000'))
        conn.notifications.append(
            (14, '1b0e00 0f00 04 38 0127000100000001000000'))
        conn.notifications.append((14, '1b0e00 0900 04 39 0227003738'))
        conn.notifications.append(
            (14, '1b0e00 0f00 04 32 0117000100000001000000'))
        conn.notifications.append(
            (14, '1b0e00 0f00 04 3a 0128000000000100000001'))
        conn.notifications.append(
            (14, '1b0e00 0f00 04 3b 0115000200000002000000'))
        conn.notifications.append(
            (14, '1b0e00 0f00 04 3c 0114000200000002000000'))
        conn.notifications.append((14, '1b0e00 0f00 8202 01'))
        conn.notifications.append((14, '1b0e00 0f00 8202 0a'))

        self._inject_notification(
            conn, '1b0e00 1200 0101 06 4c45474f204d6f766520487562', 1)
        self._inject_notification(
            conn, '1b0e00 1200 0108 06 4c45474f204d6f766520487562', 2)
        self._inject_notification(conn, '1b0e00 0900 47 3c 0227003738', 3)
        self._inject_notification(conn, '1b0e00 0600 45 3c 020d', 4)
        hub = MoveHub(conn)
        # demo_all(hub)
        self._wait_notifications_handled(hub)
Ejemplo n.º 2
0
def main():
    global update, movehub, shutDown, step, currentMotor, conn
    print("Si-clops - Colour sensor sequencer")
    print("press the green button now")
    conn = get_connection_auto()
    print("Looking for Hub")
    movehub = MoveHub(conn)
    print("Hub connected")
    init()
    initMIDI()
    print("Initialised - Press green button to scan")
    drawScreen()
    while not shutDown:
        checkForEvent()
        if newScan:
            sensorScan()
        if time.time() > nextStep:
            doMIDIstep()
Ejemplo n.º 3
0
def main():
    print("Mike's Demo - put the LEGO Boost trough its paces")
    conn = get_connection_auto()
    try:
        movehub = MoveHub(conn)
        demo_voltage(movehub)
        demo_button(movehub)
        demo_led_colors(movehub)
        demo_motors_timed(movehub)
        demo_motors_angled(movehub)
        demo_port_cd_motor(movehub)
        demo_tilt_sensor_simple(movehub)
        demo_tilt_sensor_precise(movehub)
        demo_color_sensor(movehub)
        demo_motor_sensors(movehub)
        sleep(1)
        print("That's all folks")
    finally:
        conn.disconnect()
Ejemplo n.º 4
0
def main():
  global update
  print("Colour sensor test start with tile against sensor")
  conn=get_connection_auto()
  print("Hub connected - press Green button to end")
  print("Starting scan")
  try:
    movehub = MoveHub(conn)
    init(movehub)
    while not shutDown and currentMotor <= 1480:
      checkForEvent()
      displayPrams(movehub)

  finally:
    retMotor()
    logFile.close()
    print("Shutting down")
    movehub.button.unsubscribe(call_button)
    movehub.color_distance_sensor.unsubscribe(callback_colour)
    conn.disconnect()
    pygame.quit()
Ejemplo n.º 5
0
 def __init__(self):
     super(Automata, self).__init__()
     self.__hub = MoveHub()
     self.__hub.color_distance_sensor.subscribe(self.__on_sensor, mode=ColorDistanceSensor.COLOR_ONLY)
     self._sensor = []
Ejemplo n.º 6
0
from pylgbst import get_connection_auto
from pylgbst.movehub import MoveHub

conn = get_connection_auto()  # ! don't put this into `try` block
try:
    hub = MoveHub(conn)
finally:
    conn.disconnect()
Ejemplo n.º 7
0
    time.sleep(5)
    movehub.amperage.unsubscribe(callback1)
    movehub.voltage.unsubscribe(callback2)


def demo_all(movehub):
    demo_voltage(movehub)
    demo_led_colors(movehub)
    demo_motors_timed(movehub)
    demo_motors_angled(movehub)
    demo_port_cd_motor(movehub)
    demo_tilt_sensor_simple(movehub)
    demo_tilt_sensor_precise(movehub)
    demo_color_sensor(movehub)
    demo_motor_sensors(movehub)


if __name__ == '__main__':
    logging.basicConfig(level=logging.INFO)

    try:
        connection = DebugServerConnection()
    except BaseException:
        logging.warning("Failed to use debug server: %s",
                        traceback.format_exc())
        connection = BLEConnection().connect()

    hub = MoveHub(connection)
    sleep(10000)
    #demo_all(hub)
Ejemplo n.º 8
0
        else:
            logging.warning(u"Неизвестная команда: %s", c)


if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)
    logging.getLogger('').setLevel(logging.DEBUG)

    try:
        conn = DebugServerConnection()
    except BaseException:
        logging.warning("Failed to use debug server: %s",
                        traceback.format_exc())
        conn = get_connection_auto()

    hub = MoveHub(conn) if 1 else get_hub_mock()

    plotter = Plotter(hub, 0.75)
    FIELD_WIDTH = 0.9

    try:
        """
        while True:
            cmd = six.moves.input("программа> ").decode('utf8')
            if not cmd.strip():
                continue
            plotter.initialize()
            interpret_command(cmd, plotter)
            plotter.finalize()
        """
Ejemplo n.º 9
0
def main():
  global shutDown, movehub
  print("Colour tile Simon - press the green hub button to connect")
  conn=get_connection_auto()
  print("Trying to connect Hub")
  try:
    movehub = MoveHub(conn)
    print("Hub now connected - press Green button to end")
    init()
    espeak.synth("Colour Simon game")
    time.sleep(1)
    while not shutDown:
      fail = 0  # number of fails
      #generate new sequence
      for c in range(0,maxLength):
         sequence[c] = random.randint(0,4) #use five colours  
      far = 2
      while fail < maxFails and not shutDown: # number of fail attempts before reset
         print("a sequence of length",far)
         saySeq(far)
         if getSeq(far) != -1 and not shutDown:# if entered sequence is correct  
            far = far + 1            
            if far <= maxLength:
               espeak.synth("yes")
               print("Yes - now try a longer one")
               time.sleep(1)
               espeak.synth("adding one more")
               time.sleep(1)
            fail = 0 # reset number of fails
         else:
             if not shutDown:
                fail = fail +1
                print("Wrong",fail,"fail")
                if fail < maxFails:
                   espeak.synth("no")
                   print("try that one again")
                   espeak.synth("try that one again")
                else :
                  print("maximum tries exceeded")
                  espeak.synth("maximum tries exceeded")
                  time.sleep(2)
                  espeak.synth("your score is")
                  time.sleep(1)
                  espeak.synth(str(far- 1))
                time.sleep(1.5)
         if far > maxLength and not shutDown:
            print("Well done Master Mind")
            espeak.synth("this is too easy for you")
            shutDown = True
      if not shutDown:
         espeak.synth("Game over")
         print("Game over - Your score is",far-1)
         print("Try again")
         time.sleep(2.0)
      else:
        espeak.synth("closing down  good bye")
      
  finally:
    print("shutting down")
    movehub.button.unsubscribe(call_button)
    movehub.color_distance_sensor.unsubscribe(callback_colour)
    conn.disconnect()
Ejemplo n.º 10
0
from pylgbst.movehub import MoveHub, ColorDistanceSensor
import time


def callback(clr, distance):
    if clr <= 10:
        print("Colour number", clr, LED_COLORS[clr], " / Distance", distance)
    else:
        print("Color: %s / Distance: %s" % (clr, distance))


hub = MoveHub()

LED_COLORS = [
    'BLACK', '', '', 'BLUE', '', 'GREEN', '', 'YELLOW', '', 'RED', 'WHITE'
]
hub.color_distance_sensor.subscribe(
    callback, mode=ColorDistanceSensor.COLOR_DISTANCE_FLOAT)
time.sleep(60)  # play with sensor while it waits
hub.color_distance_sensor.unsubscribe(callback)
'''
Subscription mode constants in class `ColorDistanceSensor` are:
- `COLOR_DISTANCE_FLOAT` - default mode, use `callback(color, distance)` where `distance` is float value in inches
- `COLOR_ONLY` - use `callback(color)`
- `DISTANCE_INCHES` - use `callback(color)` measures distance in integer inches count
- `COUNT_2INCH` - use `callback(count)` - it counts crossing distance ~2 inches in front of sensor
- `DISTANCE_HOW_CLOSE` - use `callback(value)` - value of 0 to 255 for 30 inches, larger with closer distance
- `DISTANCE_SUBINCH_HOW_CLOSE` - use `callback(value)` - value of 0 to 255 for 1 inch, larger with closer distance
- `LUMINOSITY` - use `callback(luminosity)` where `luminosity` is float value from 0 to 1
- `OFF1` and `OFF2` - seems to turn sensor LED and notifications off
- `STREAM_3_VALUES` - use `callback(val1, val2, val3)`, sends some values correlating to distance, not well understood at the moment