예제 #1
0
    def redraw(self):
        wlogger.log_info("Redraw Lights")
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        glPushMatrix()
        # Translate to face location.
        glTranslatef(0.0, 0.0, -0.5)
        glColor(0.0, 0.3, 0.1)

        glBegin(GL_QUADS)  # start drawing a rectangle
        glVertex2f(-3, -3)  # bottom left point
        glVertex2f(3, -3)  # bottom right point
        glVertex2f(3, 3)  # top right point
        glVertex2f(-3, 3)  # top left point
        glEnd()
        glPopMatrix()

        glPushMatrix()
        glTranslatef(-2.8, 2.8, -0.47)

        for strip in self.LightStripArray:
            glPushMatrix()
            self.drawStrip(strip)
            glPopMatrix()
            glTranslate(0.0, -self.led_row_spacing, 0.0)

        glPopMatrix()

        # Refresh display
        pygame.display.flip()
예제 #2
0
def all_off(strip, blockList):
    """ This function turns all LEDs in the blocks given off."""

    if not blockList:
        return

    if print_debug:
        print("----------------------------")
        print("All Off")
        print(config.current_brightness)

    # The index of the LED within the current blocks.
    local_led_index = 0

    for block in blockList:
        if block.get_direction():
            ledList = np.arange(block.get_end_index() - 1,
                                block.get_start_index() - 1, -1)
        else:
            ledList = np.arange(block.get_start_index(), block.get_end_index())

        for led in ledList:

            # Paint LED black.
            strip.set_pixel(led, 0.0, 0.0, 0.0)
            local_led_index += 1

    info_string = "Pattern: All Off."
    wlogger.log_info(info_string)
예제 #3
0
    def __init__(self,
                 num_led,
                 global_brightness=MAX_BRIGHTNESS,
                 order='rgb',
                 mosi=10,
                 sclk=11,
                 max_speed_hz=8000000):
        """Initializes the library.

        """

        wlogger.log_info("Set up Strip")
        self.num_led = num_led  # The number of LEDs in the Strip
        order = order.lower()
        self.rgb = RGB_MAP.get(order, RGB_MAP['rgb'])

        self.strip_id = APA102.NEXT_STRIP_ID
        APA102.NEXT_STRIP_ID += 1

        wlight.lightController.LightStripArray.append(self)

        # Limit the brightness to the maximum if it's set higher
        if global_brightness > self.MAX_BRIGHTNESS:
            self.global_brightness = self.MAX_BRIGHTNESS
        else:
            self.global_brightness = global_brightness

        self.leds = [self.LED_START, 0, 0, 0] * self.num_led  # Pixel buffer
예제 #4
0
    def re_centre(self, stepSize):
        """ This function calculates which eye is further from the centre and then calls the StepTowardsCentre function to move that eye closer to the centre"""
        wlogger.log_info("Performing Recentre")

        tol = 0.01

        while ((-tol > abs(self.RightEye.eye_vert_angle)
                or abs(self.RightEye.eye_vert_angle) > tol)
               or (-tol > abs(self.RightEye.eye_horiz_angle)
                   or abs(self.RightEye.eye_horiz_angle) > tol)
               or (-tol > abs(self.LeftEye.eye_vert_angle)
                   or abs(self.LeftEye.eye_vert_angle) > tol)
               or (-tol > abs(self.LeftEye.eye_horiz_angle)
                   or abs(self.LeftEye.eye_horiz_angle) > tol)):

            right_eye_distance_sq = self.RightEye.eye_vert_angle**2 + self.RightEye.eye_horiz_angle**2
            left_eye_distance_sq = self.LeftEye.eye_vert_angle**2 + self.LeftEye.eye_horiz_angle**2

            # If the step size is bigger than the distance remaining there is a chance of overstepping
            # - only step the smaller distance.
            if right_eye_distance_sq > left_eye_distance_sq:
                if stepSize**2 > right_eye_distance_sq:
                    self.StepTowardsCentre(self.RightEye,
                                           math.sqrt(right_eye_distance_sq))
                else:
                    self.StepTowardsCentre(self.RightEye, stepSize)
            else:
                if stepSize**2 > left_eye_distance_sq:
                    self.StepTowardsCentre(self.LeftEye,
                                           math.sqrt(left_eye_distance_sq))
                else:
                    self.StepTowardsCentre(self.LeftEye, stepSize)
예제 #5
0
    def show(self):
        """Sends the content of the pixel buffer to the strip.

        Todo: More than 1024 LEDs requires more than one xfer operation.
        Done by mikey- needs testing
        """

        start_frame = self.clock_start_frame()
        end_frame = self.clock_end_frame()

        led_buffer = np.concatenate((start_frame, self.leds, end_frame))

        packetnum = len(list(led_buffer))
        transfersize = 4096
        transfernum = int(packetnum / transfersize)

        for x in range(0, transfernum):

            out_array = led_buffer[x * transfersize:(x + 1) * transfersize]
            outArrayAsList = out_array.tolist()

            if log_buffer:
                wlogger.log_info(outArrayAsList)

            self.spi.write(outArrayAsList)

        out_array = led_buffer[(transfernum * transfersize):packetnum]
        outArrayAsList = out_array.tolist()

        if log_buffer:
            wlogger.log_info(outArrayAsList)
        self.spi.write(outArrayAsList)
예제 #6
0
    def unsafe_move_to_mapped_position(self, horiz_angle, vert_angle):
        # Map the new angle against a correction matrix, which accounts for the mechanism of the eye.
        servo_angle_horiz, servo_angle_vert = self.map_eye_to_servo(
            horiz_angle, vert_angle)

        # Convert the corrected angle into a PWM tick count and therefore duty cycle
        servo_pwm_period_vert = self.conv_servo_angle_ms(int(servo_angle_vert))
        servo_pwm_period_horiz = self.conv_servo_angle_ms(
            int(servo_angle_horiz))

        #print("Servo PWM period Vert: " + str(servo_pwm_period_vert))
        #print("Servo PWM period Horiz: " + str(servo_pwm_period_horiz))

        # Apply this new duty cycle to the servomotor

        successful_move = False
        num_tries = 0
        while not successful_move and num_tries < 1000:
            try:
                self.eye.set_pwm(self.vert_ch, 0, int(servo_pwm_period_vert))
                self.eye.set_pwm(self.horiz_ch, 0, int(servo_pwm_period_horiz))
                successful_move = True
            except IOError as e:
                if print_debug:
                    print("ExceptionCaught")
                wlogger.log_info("Exception Caught")
                wlogger.log_info(e)
                successful_move = False
                num_tries += 1
                pass

        #Update the positions
        self.eye_horiz_angle = horiz_angle
        self.eye_vert_angle = vert_angle
예제 #7
0
def end_test(strip, blockList):
    """ This function turns the LEDs in the given blocks on."""

    if not blockList:
        return

    current_colour = blockList[0].get_colour()

    if print_debug:
        print("----------------------------")
        print("End Test")

    for block in blockList:
        # Paint single LEDS with given colour
        strip.set_pixel(
            block.get_start_index(),
            math.floor(enums.colourDi[enums.WColour.Blue][0] * 255),
            math.floor(enums.colourDi[enums.WColour.Blue][1] * 255),
            math.floor(enums.colourDi[enums.WColour.Blue][2] * 255),
            config.current_brightness)

        strip.set_pixel(block.get_start_index() + 1,
                        math.floor(enums.colourDi[enums.WColour.Red][0] * 255),
                        math.floor(enums.colourDi[enums.WColour.Red][1] * 255),
                        math.floor(enums.colourDi[enums.WColour.Red][2] * 255),
                        config.current_brightness)

        strip.set_pixel(block.get_start_index() + 2,
                        math.floor(enums.colourDi[enums.WColour.Red][0] * 255),
                        math.floor(enums.colourDi[enums.WColour.Red][1] * 255),
                        math.floor(enums.colourDi[enums.WColour.Red][2] * 255),
                        config.current_brightness)

        strip.set_pixel(
            block.get_end_index() - 1,
            math.floor(enums.colourDi[enums.WColour.Blue][0] * 255),
            math.floor(enums.colourDi[enums.WColour.Blue][1] * 255),
            math.floor(enums.colourDi[enums.WColour.Blue][2] * 255),
            config.current_brightness)

        strip.set_pixel(block.get_end_index() - 2,
                        math.floor(enums.colourDi[enums.WColour.Red][0] * 255),
                        math.floor(enums.colourDi[enums.WColour.Red][1] * 255),
                        math.floor(enums.colourDi[enums.WColour.Red][2] * 255),
                        config.current_brightness)

        strip.set_pixel(block.get_end_index() - 3,
                        math.floor(enums.colourDi[enums.WColour.Red][0] * 255),
                        math.floor(enums.colourDi[enums.WColour.Red][1] * 255),
                        math.floor(enums.colourDi[enums.WColour.Red][2] * 255),
                        config.current_brightness)



    info_string = "Pattern: End Test. Colour: " + str(current_colour) \
                    + ". Brightness: " + str(config.current_brightness)
    wlogger.log_info(info_string)
예제 #8
0
def singles(strip, num_steps_per_cycle, current_step, current_cycle,
            blockList):
    """ This function moves single LEDs along the LED strip indices given"""

    if not blockList:
        return

    single_gap = 9

    current_colour = blockList[0].get_colour()
    current_speed = blockList[0].get_speed()

    if print_debug:
        print("----------------------------")
        print("Singles")
        print(current_speed)
        print(current_colour)
        print(config.current_brightness)

    # Pattern specific behaviour
    pattern_speed_factor = 1
    num_steps_per_pattern_step = enums.speedDi[
        current_speed] * pattern_speed_factor

    # The index of the LED within the current blocks.
    local_led_index = 0

    for block in blockList:
        if block.get_direction():
            ledList = np.arange(block.get_end_index() - 1,
                                block.get_start_index() - 1, -1)
        else:
            ledList = np.arange(block.get_start_index(), block.get_end_index())

        for led in ledList:
            if (local_led_index +
                    blockList[0].get_pattern_index()) % (single_gap + 1) == 0:
                # Paint single LEDS with given colour
                strip.set_pixel(
                    led, math.floor(enums.colourDi[current_colour][0] * 255),
                    math.floor(enums.colourDi[current_colour][1] * 255),
                    math.floor(enums.colourDi[current_colour][2] * 255),
                    config.current_brightness)
            else:
                # Paint gap LED black.
                strip.set_pixel(led, 0.0, 0.0, 0.0)

            local_led_index += 1

    if (current_step % num_steps_per_pattern_step == 0):
        blockList[0].increment_pattern_index(1)

    info_string = "Pattern: Singles. Colour: " + str(current_colour) + ". Speed: " \
                  + str(current_speed) + ". Brightness: " + str(config.current_brightness)
    wlogger.log_info(info_string)
예제 #9
0
    def extreme_left(self, stepSize):
        """ This function moves the eyes to the extreme left position. It only affects the Y Axis (left to right)"""
        wlogger.log_info("Performing Extreme Left")

        while (self.LeftEye.eye_horiz_angle -
               stepSize) > -self.LeftEye.eye_movement_max_radius and (
                   self.RightEye.eye_horiz_angle -
                   stepSize) > -self.LeftEye.eye_movement_max_radius:
            self.LeftEye.step_horiz_angle(-stepSize)
            self.RightEye.step_horiz_angle(-stepSize)
            self.redraw()
예제 #10
0
    def Straight_Eye_Roll(self, stepSize):
        """ This function represents one of Gromits animated eye rolls."""
        wlogger.log_info("Performing Straight Eye Roll")
        restPosition = [20, 0, -20, 0]
        startPosition = [0, -25, 0, -25]

        self.straight_to_point(stepSize, startPosition)

        #Section for individual movements

        self.straight_to_point(stepSize, restPosition)
예제 #11
0
    def kbhit(self):
        ''' Returns True if keyboard character was hit, False otherwise.
        '''

        wlogger.log_info("Keyboard Polled")
        if os.name == 'nt':
            return msvcrt.kbhit()

        else:
            dr, dw, de = select([sys.stdin], [], [], 0)
            return dr != []
예제 #12
0
    def extreme_down(self, stepSize):
        """ This function moves the eyes to the extreme down position. It only affects the X Axis (up and down)
        This assumes that the eye is starting at the centre and is a test routine"""
        wlogger.log_info("Performing Extreme Down")

        while (self.LeftEye.eye_vert_angle -
               stepSize) > -self.LeftEye.eye_movement_max_radius and (
                   self.RightEye.eye_vert_angle -
                   stepSize) > -self.RightEye.eye_movement_max_radius:
            self.LeftEye.step_vert_angle(-stepSize)
            self.RightEye.step_vert_angle(-stepSize)
            self.redraw()
예제 #13
0
    def extreme_right(self, stepSize):
        """ This function moves the eyes to the extreme right position. It only affects the Y Axis (left to right)
        This assumes that the eye is starting at the centre and is a test routine"""
        wlogger.log_info("Performing Extreme Right")

        while (self.LeftEye.eye_horiz_angle +
               stepSize) < self.LeftEye.eye_movement_max_radius and (
                   self.RightEye.eye_horiz_angle +
                   stepSize) < self.RightEye.eye_movement_max_radius:
            self.LeftEye.step_horiz_angle(stepSize)
            self.RightEye.step_horiz_angle(stepSize)
            self.redraw()
예제 #14
0
    def __init__(self):
        """
        Create Controller
        """

        wlogger.log_info("Initialising Light Controller")
        self.LightStripArray = []

        self.led_size = 0.1
        self.led_spacing = 0.11
        self.led_row_length = 50
        self.led_row_spacing = 1
예제 #15
0
    def acquire(self, blocking=True):
        """Acquire the lock.
        If the lock is not already acquired, return None.  If the lock is
        acquired and blocking is True, block until the lock is released.  If
        the lock is acquired and blocking is False, raise an IOError.
        """
        ops = fcntl.LOCK_EX
        if not blocking:
            ops |= fcntl.LOCK_NB
        fcntl.flock(self.lock_file, ops)

        wlogger.log_info("Lock Aquired")
예제 #16
0
    def cross_eyes_checker(self):
        """ This function checks the current positions of the eyes in relation to each other and returns an integer
        symbolising how to proceed with crossing the eyes"""
        wlogger.log_info("Performing Eye Position Check")

        if self.LeftEye.eye_horiz_angle < self.LeftEye.eye_movement_max_radius and self.RightEye.eye_horiz_angle > -self.RightEye.eye_movement_max_radius:
            return 1
        elif self.LeftEye.eye_horiz_angle < self.LeftEye.eye_movement_max_radius and self.RightEye.eye_horiz_angle == -self.RightEye.eye_movement_max_radius:
            return 2
        elif self.LeftEye.eye_horiz_angle == self.LeftEye.eye_movement_max_radius and self.RightEye.eye_horiz_angle > -self.RightEye.eye_movement_max_radius:
            return 3
        else:
            return 0
예제 #17
0
    def set_tail_on(self):
        if print_debug:
            print("Tail On")
        GPIO.output(config.touchOutputPin, GPIO.HIGH)

        successful_move = False
        num_tries = 0
        while not successful_move and num_tries < 1000:
            try:
                self.motor.set_pwm(self.forward_ch, 0, 2250)  # Calibrated
                self.motor.set_pwm(self.backwards_ch, 0, 0)
                successful_move = True
            except IOError as e:
                if print_debug:
                    print("ExceptionCaught")
                wlogger.log_info("Exception Caught")
                wlogger.log_info(e)
                successful_move = False
                num_tries += 1
                pass

        if num_tries >= 1000:
            wlogger.log_info("Num Tries Reached")

        wlogger.log_info("Set Tail On")
예제 #18
0
    def Eye_Roll(self, start_angle, end_angle, num_steps):
        """Performs a full circle of the eyes."""

        # Convert cartesian step size to an angle step.
        interval = (end_angle - start_angle) / num_steps
        rad_interval = interval * math.pi / 180
        angle_rad = start_angle * math.pi / 180
        end_angle_rad = end_angle * math.pi / 180

        # If the distance is 0 just stay in one place
        if interval == 0:
            for i in range(0, num_steps):
                horiz_angle = self.LeftEye.eye_movement_max_radius * math.cos(
                    start_angle)
                vert_angle = self.LeftEye.eye_movement_max_radius * math.sin(
                    start_angle)

                #print(vert_angle)
                #print(horiz_angle)

                self.move_to(horiz_angle, vert_angle)
                time.sleep(0.01)

        wlogger.log_info("Performing Eye Roll")

        while angle_rad < end_angle_rad:
            horiz_angle = self.LeftEye.eye_movement_max_radius * math.cos(
                angle_rad)
            vert_angle = self.LeftEye.eye_movement_max_radius * math.sin(
                angle_rad)
            angle_rad += rad_interval

            #print(horiz_angle)
            #print(vert_angle)

            self.move_to(horiz_angle, vert_angle)
            time.sleep(0.01)

        horiz_angle = self.LeftEye.eye_movement_max_radius * math.cos(
            end_angle_rad)
        vert_angle = self.LeftEye.eye_movement_max_radius * math.sin(
            end_angle_rad)
        angle_rad += rad_interval

        #print(horiz_angle)
        #print(vert_angle)

        self.move_to(horiz_angle, vert_angle)
        time.sleep(0.01)
예제 #19
0
    def test_file_rotation(self, mock_get_now):
        mock_get_now = mock.Mock.return_value = datetime.datetime(1960, 1, 1, 8, 10, 10)
        wlogger.setup_loggers(os.path.join(self.test_data_dir, 'Temp'),
                              debug_on=True,
                              test_mode_on=True,
                              name='test_file_rotation',
                              maxBytes=1000)

        for i in range(0, 1000):
            wlogger.log_info('Info Message ' + str(i),        name='test_file_rotation')
            wlogger.log_debug('Debug Message ' + str(i),      name='test_file_rotation')
            wlogger.log_error('Error Message ' + str(i),      name='test_file_rotation')

        wlogger.tear_down_loggers(name='test_file_rotation')
        self.log_test_compare()
예제 #20
0
def fixed_morse(strip, num_steps_per_cycle, current_step, current_cycle, morse,
                colour_b, blockList):
    """ This function moves Renishaw in morse code along the LED strip indices given"""

    if not blockList:
        return

    current_colour = blockList[0].get_colour()
    current_b = colour_b

    if print_debug:
        print("----------------------------")
        print("Fixed Morse")
        print(current_colour)
        print(config.current_brightness)

    # The index of the LED within the current blocks.
    local_led_index = 0

    for block in blockList:

        if block.get_direction():
            ledList = np.arange(block.get_end_index() - 1,
                                block.get_start_index() - 1, -1)
        else:
            ledList = np.arange(block.get_start_index(), block.get_end_index())

        for led in ledList:
            if local_led_index < len(morse) and morse[local_led_index]:
                # Paint snake LEDS with given colour
                strip.set_pixel(led,
                                math.floor(enums.colourDi[colour_b][0] * 255),
                                math.floor(enums.colourDi[colour_b][1] * 255),
                                math.floor(enums.colourDi[colour_b][2] * 255),
                                config.current_brightness)
            else:
                # Paint gap LED black.
                strip.set_pixel(
                    led, math.floor(enums.colourDi[colour_b][0] * 255),
                    math.floor(enums.colourDi[current_colour][1] * 255),
                    math.floor(enums.colourDi[current_colour][2] * 255),
                    config.current_brightness)

            local_led_index += 1

    info_string = "Pattern: Fixed Morse. Colour: " + str(current_colour) \
                    + ". Brightness: " + str(config.current_brightness)
    wlogger.log_info(info_string)
예제 #21
0
    def Low_Cross_Eyes(self, stepSize):
        """This function represents Gromit's eyes focussing on his nose"""
        wlogger.log_info("Performing Low Cross Eyes")

        while ((self.LeftEye.eye_vert_angle - stepSize) >
               -self.LeftEye.eye_movement_corner_angle
               and (self.LeftEye.eye_horiz_angle + stepSize) <
               self.LeftEye.eye_movement_corner_angle
               and (self.RightEye.eye_vert_angle - stepSize) >
               -self.RightEye.eye_movement_corner_angle
               and (self.RightEye.eye_horiz_angle - stepSize) >
               -self.RightEye.eye_movement_corner_angle):
            self.LeftEye.step_vert_angle(-stepSize)
            self.RightEye.step_vert_angle(-stepSize)
            self.LeftEye.step_horiz_angle(stepSize)
            self.RightEye.step_horiz_angle(-stepSize)
예제 #22
0
    def test_message_levels_debug_off(self, mock_get_now):
        mock_get_now = mock.Mock.return_value = datetime.datetime(1960, 1, 1, 8, 10, 10)
        wlogger.setup_loggers(os.path.join(self.test_data_dir, 'Temp'),
                              debug_on=False,
                              test_mode_on=True,
                              name='test_message_levels_debug_off')

        wlogger.log_info('Info Message',        name='test_message_levels_debug_off')
        wlogger.log_debug('Debug Message',      name='test_message_levels_debug_off')
        wlogger.log_error('Error Message',      name='test_message_levels_debug_off')
        wlogger.log_info('Info Message',        name='test_message_levels_debug_off')
        wlogger.log_debug('Debug Message',      name='test_message_levels_debug_off')
        wlogger.log_warning('Warning Message',  name='test_message_levels_debug_off')
        wlogger.tear_down_loggers(name='test_message_levels_debug_off')

        self.log_test_compare()
예제 #23
0
def control_big_leds():

    # Set up pins.
    set_up_pins()

    # Set LEDs on to start.
    change_leds()
    is_LEDs_on = True

    continue_control = True
    button_already_pressed = False
    button_press_count = 0
    count = 0

    while continue_control:
        count += 1
        # Gather button input
        inputButton = GPIO.input(config.touchInputPin)

        # Change BigLED if button is pressed.
        if inputButton and not button_already_pressed:
            GPIO.output(config.touchOutputPin, GPIO.HIGH)
            button_press_count += 1
            button_already_pressed = True

            change_leds()
            wlogger.log_info("Button press -> LEDs Changed")

            if print_debug:
                print("Button press -> LEDs Changed", flush=True)

        elif not inputButton:
            GPIO.output(config.touchOutputPin, GPIO.LOW)
            button_already_pressed = False

        try:
            if count % config.num_cycles_between_button_recording == 0:
                record_button_presses(button_press_count)
                button_press_count = 0

        except Exception as e:
            print("Recording Error")
            wlogger.log_info(e)
            pass

        # Small time delay between each run through.
        time.sleep(0.1)
예제 #24
0
    def __init__(self):
        """
        Create Controller
        """

        wlogger.log_info("Initialising Controller")
        self.LeftEye = weye.Eye(1, (1, 0, 0), 4, 5)
        self.RightEye = weye.Eye(1, (-1, 0, 0), 6, 7)

        # Set up initial position - this would make more sense to do internally
        # but calling PCA9685(0x40) resets the signals to zero.

        self.LeftEye.move_to(0, 0)
        self.RightEye.move_to(0, 0)
        self.redraw()

        # Calibrate
        #Speeds
        self.sloth_step_size = 0.5
        self.tortoise_step_size = 1
        self.hare_step_size = 3
        self.ostrich_step_size = 6
        self.cheetah_step_size = 10
        self.speeds = [
            self.sloth_step_size, self.tortoise_step_size, self.hare_step_size,
            self.ostrich_step_size, self.cheetah_step_size
        ]

        #Positions
        self.resting = [20, 0, -20, 0]
        self.extremeLeft = [-60, 0]
        self.extremeRight = [60, 0]
        self.extremeUp = [0, 60]
        self.extremeDown = [0, -60]
        self.crossEyes = [60, 0, -60, 0]
        self.upLeft = [-48, 48]
        self.upRight = [48, 48]
        self.downLeft = [-48, -48]
        self.downRight = [48, -48]

        self.positions = [
            self.resting, self.extremeLeft, self.extremeRight, self.extremeUp,
            self.extremeDown, self.crossEyes, self.upLeft, self.upRight,
            self.downLeft, self.downRight
        ]
예제 #25
0
    def StepTowardsCentre(self, eye, stepSize):
        """ This function moves the given eye a step closer to the centre in either axis depending on which is further away"""
        wlogger.log_info("Performing Step Towards Centre")

        if abs(eye.eye_vert_angle) > abs(eye.eye_horiz_angle):
            #print("Vertical Step")
            if eye.eye_vert_angle > 0:
                eye.step_vert_angle(-stepSize)
            else:
                eye.step_vert_angle(stepSize)
        else:
            #print("Horizontal Step")
            if eye.eye_horiz_angle > 0:
                eye.step_horiz_angle(-stepSize)
            else:
                eye.step_horiz_angle(stepSize)

        self.redraw()
예제 #26
0
    def cross_eyes(self, stepSize):
        """ This function makes Gromit go cross-eyed and the returns to centre"""
        wlogger.log_info("Performing Cross-Eyes")

        while self.cross_eyes_checker() == 1:
            self.LeftEye.step_horiz_angle(stepSize)
            self.RightEye.step_horiz_angle(-stepSize)
            self.redraw()

        while self.cross_eyes_checker() == 2:
            self.LeftEye.step_horiz_angle(stepSize)
            self.redraw()

        while self.cross_eyes_checker() == 3:
            self.RightEye.step_horiz_angle(-stepSize)
            self.redraw()

        while self.LeftEye.eye_horiz_angle > 0 > self.RightEye.eye_horiz_angle:
            self.LeftEye.step_horiz_angle(-stepSize)
            self.RightEye.step_horiz_angle(stepSize)
            self.redraw()
예제 #27
0
 def test_basic_log(self, mock_get_now):
     mock_get_now = mock.Mock.return_value = datetime.datetime(1960, 1, 1, 8, 10, 10)
     wlogger.setup_loggers(os.path.join(self.test_data_dir, 'Temp'), test_mode_on=True, name='test_basic_log')
     wlogger.log_info('First Info Message',  name='test_basic_log')
     wlogger.log_info('Second Info Message',  name='test_basic_log')
     wlogger.log_info('Third Info Message',  name='test_basic_log')
     wlogger.tear_down_loggers(name='test_basic_log')
     self.log_test_compare()
예제 #28
0
def all_on(strip, blockList):
    """ This function turns the LEDs in the given blocks on."""

    if not blockList:
        return

    current_colour = blockList[0].get_colour()

    if print_debug:
        print("----------------------------")
        print("All On")
        print(current_colour)
        print(config.current_brightness)

    # The index of the LED within the current blocks.
    local_led_index = 0

    for block in blockList:
        if block.get_direction():
            ledList = np.arange(block.get_end_index() - 1,
                                block.get_start_index() - 1, -1)
        else:
            ledList = np.arange(block.get_start_index(), block.get_end_index())

        for led in ledList:

            # Paint single LEDS with given colour
            strip.set_pixel(
                led, math.floor(enums.colourDi[current_colour][0] * 255),
                math.floor(enums.colourDi[current_colour][1] * 255),
                math.floor(enums.colourDi[current_colour][2] * 255),
                config.current_brightness)

            local_led_index += 1

    info_string = "Pattern: All On. Colour: " + str(current_colour) \
                    + ". Brightness: " + str(config.current_brightness)
    wlogger.log_info(info_string)
예제 #29
0
    def __init__(self):
        '''Creates a KBHit object that you can call to do various keyboard things.
        '''

        wlogger.log_info("Keyboard Listener Initialised")

        if os.name == 'nt':
            pass

        else:

            # Save the terminal settings
            self.fd = sys.stdin.fileno()
            self.new_term = termios.tcgetattr(self.fd)
            self.old_term = termios.tcgetattr(self.fd)

            # New terminal setting unbuffered
            self.new_term[3] = (self.new_term[3] & ~termios.ICANON
                                & ~termios.ECHO)
            termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.new_term)

            # Support normal-terminal reset at exit
            atexit.register(self.set_normal_term)
예제 #30
0
    def test_dir_does_not_exist(self, mock_get_now):
        mock_get_now = mock.Mock.return_value = datetime.datetime(1960, 1, 1, 8, 10, 10)

        # Extend filepath required to check that sub directories are created.
        file_path = os.path.join(self.test_data_dir, 'Temp', 'SubDirectory', 'SubSubDirectory')
        wlogger.setup_loggers(file_path,
                              test_mode_on=True,
                              name='test_dir_does_not_exist')

        wlogger.log_info('First Info Message', name='test_dir_does_not_exist')
        wlogger.log_info('Second Info Message', name='test_dir_does_not_exist')
        wlogger.log_info('Third Info Message', name='test_dir_does_not_exist')
        wlogger.tear_down_loggers(name='test_dir_does_not_exist')

        self.log_test_compare()