예제 #1
0
    def cb_enumerate(self, uid, connected_uid, position, hardware_version, 
                 firmware_version, device_identifier, enumeration_type):
        
        if enumeration_type == IPConnection.ENUMERATION_TYPE_CONNECTED or \
           enumeration_type == IPConnection.ENUMERATION_TYPE_AVAILABLE:
            
            # Initialize GPS
            if device_identifier == BrickletGPSV2.DEVICE_IDENTIFIER:
                self.gps = BrickletGPSV2(uid, self.ipcon)

                self.gps.set_date_time_callback_period(TimeServer.GPS_UPDATE_PERIOD)
                self.gps.set_coordinates_callback_period(TimeServer.GPS_UPDATE_PERIOD)

                self.gps.register_callback(BrickletGPSV2.CALLBACK_DATE_TIME, self.cb_time_updated)
                self.gps.register_callback(BrickletGPSV2.CALLBACK_COORDINATES, self.cb_location_updated)

            # Initialize OLED display
            if device_identifier == BrickletOLED128x64.DEVICE_IDENTIFIER:
                self.oled = BrickletOLED128x64(uid, self.ipcon)
                self.oled.clear_display()

            # Initialize RTC
            if device_identifier == BrickletRealTimeClock.DEVICE_IDENTIFIER:
                self.rtc = BrickletRealTimeClock(uid, self.ipcon)

                self.rtc.register_callback(BrickletRealTimeClock.CALLBACK_DATE_TIME, self.cb_rtc_time_update)
                self.rtc.set_date_time_callback_period(TimeServer.RTC_UPDATE_PERIOD)
예제 #2
0
 def __init__(self, controller, uid):
     self.controller = controller
     self.device = BrickletOLED128x64(uid, self.controller.ipcon)
     self.device.clear_display()
     self.device.set_display_configuration(0, False)
     self.draw_splash()
     controller.add_event_handler("sleep", self.on_sleep)
     controller.add_event_handler("wake", self.on_wake)
예제 #3
0
 def try_bricklet(self, uid, device_identifier, position):
     if not self.controller.screen:
         if device_identifier == 263:
             self.device = BrickletOLED128x64(uid, self.controller.ipcon)
             self.device.clear_display()
             self.device.set_display_configuration(0, False)
             self.draw_splash()
             print("Screen Initialised")
             return True
         return False
예제 #4
0
        for column in range(column_count):
            data.append(pages[row][column])

    # Set new window
    oled.new_window(start_column, start_column + column_count - 1, start_row,
                    start_row + row_count - 1)

    # Write page data in 64 byte blocks
    for i in range(0, len(data), 64):
        block = data[i:i + 64]
        oled.write(block + [0] * (64 - len(block)))


if __name__ == "__main__":
    ipcon = IPConnection()  # Create IP connection
    oled = BrickletOLED128x64(UID, ipcon)  # Create device object

    ipcon.connect(HOST, PORT)  # Connect to brickd
    # Don't use device before ipcon is connected

    # Clear display
    oled.clear_display()

    # Draw checkerboard pattern
    pixels = []

    for row in range(HEIGHT * 8):
        pixels.append([])

        for column in range(WIDTH):
            pixels[row].append((row // 8) % 2 == (column // 8) % 2)
예제 #5
0
    elif distance <= 150:
        print("Stepper -> Stop")
        stepper.stop()
    elif distance <= 130:
        print("Stepper -> Zurück")
        stepper.drive_backward()
    else:
        print("Puffer erreicht")
        stepper.stop()


if __name__ == "__main__":

    ipcon = IPConnection()
    dcb = BrickDC(UIDdcb, ipcon)
    oled = BrickletOLED128x64(UIDoled, ipcon)
    poti = BrickletLinearPoti(UIDpoti, ipcon)
    ropoti = BrickletRotaryPoti(UIDropoti, ipcon)
    stepper = BrickStepper(UIDstepper, ipcon)
    joystick = BrickletJoystick(UIDjoystick, ipcon)
    irsensor = BrickletDistanceIR(UIDirsensor, ipcon)

    ipcon.connect(HOST, PORT)
    print("Verbindung unter folgenden Daten: \nIP: " + HOST + "\nPort: " +
          PORT)

    o_clear()
    print("Einstellungen werden gesetzt")
    o_write(1, 5, "Einstellungen")
    o_write(1, 5, "werden gesetzt")
    for i in range(len(column)):
        oled.write(column[i])


def line_at_angle(startx, starty, angle, length):
    radian_angle = math.pi * angle / 180.0
    x = startx + length * math.cos(radian_angle)
    y = starty + length * math.sin(radian_angle)
    return (startx, starty, x, y)


if __name__ == "__main__":
    # Create Brick/Bricklet objects
    ipcon = IPConnection()
    oled = BrickletOLED128x64('x5U', ipcon)
    poti = BrickletRotaryPoti('8Co', ipcon)
    servo = BrickServo('6e8MF1', ipcon)

    # Connect to brickd
    ipcon.connect(HOST, PORT)

    # Configure Servo so that it rotates 180°
    servo.set_pulse_width(6, 650, 2350)
    servo.enable(6)

    # Clear display
    oled.clear_display()

    # Draw text once at beginning, the window in draw_matrix does not overwrite
    # the last line of the display
예제 #7
0
HOST = "localhost"
PORT = 4223
UID = "xpN"  # UID of Distance IR Bricklet
UID_dual_button = "mMX"
UID_dual_relay = "E8x"
UID_oled = "yqA"

isObjectPresent = False
objCount = 0

ipcon = IPConnection()  # Create IP connection
dir = BrickletDistanceIR(UID, ipcon)  # Create device object
db = BrickletDualButton(UID_dual_button, ipcon)
m_relay = BrickletDualRelay(UID_dual_relay, ipcon)  # Create device object
display = BrickletOLED128x64(UID_oled, ipcon)
pygame.mixer.init(44100, -16, 2, 1024)
sound = pygame.mixer.Sound('laser.wav')
denied_sound = pygame.mixer.Sound('denied.wav')
backend_connected = False
user_logged_in = False
user_name = ""
last_object = ""


def timeout():
    global isObjectPresent
    timer.cancel()
    if isObjectPresent:
        print("object out")
        isObjectPresent = False
예제 #8
0
 def __init__(self, controller, uid):
     self.controller = controller
     self.device = BrickletOLED128x64(uid, self.controller.ipcon)
     self.device.clear_display()
     self.device.set_display_configuration(0, False)
     self.draw_splash()