示例#1
0
    def addNeutralValues(self, startTime, endTime):
        if len(self.recordedRotations) > 0:
            if self.recordedRotations[0].getTime() != startTime:
                newEvent = RotationEvent(startTime, Decimal('0'), Decimal('0'))
                self.recordedRotations.insert(0, newEvent)
            if self.recordedRotations[len(self.recordedRotations) -
                                      1].getTime() != endTime:
                lastEvent = self.recordedRotations[len(self.recordedRotations)
                                                   - 1]
                newEvent = RotationEvent(endTime,
                                         (Decimal('-1') *
                                          lastEvent.getValue()).normalize(),
                                         Decimal('0'))
                self.recordedRotations.append(newEvent)

        if len(self.recordedButtons) > 0:
            if self.recordedButtons[0].getTime() != startTime:
                newEvent = ButtonEvent(startTime, Decimal('0'))
                self.recordedButtons.insert(0, newEvent)
            if self.recordedButtons[len(self.recordedButtons) -
                                    1].getTime() != endTime:
                newEvent = ButtonEvent(endTime, Decimal('0'))
                self.recordedButtons.append(newEvent)

        for location in self.touches:
            touchEvents = self.touches[location]
            if touchEvents[0].getTime() != startTime:
                newEvent = TouchEvent(startTime, location, Decimal('0'))
                touchEvents.insert(0, newEvent)
            if touchEvents[len(touchEvents) - 1].getTime() != endTime:
                newEvent = TouchEvent(endTime, location, Decimal('0'))
                touchEvents.append(newEvent)
示例#2
0
    def addNeutralValues(self, startTime, endTime):
        #Add startTime and endTime if not present
        #Should be able to workaround this with adapted calculations
        if len(self.recordedRotations) > 0:
            if self.recordedRotations[0].getTime() != startTime:
                newEvent = RotationEvent(startTime, Decimal('0'), Decimal('0'))
                self.recordedRotations.insert(0, newEvent)
            if self.recordedRotations[len(self.recordedRotations) -
                                      1].getTime() != endTime:
                lastEvent = self.recordedRotations[len(self.recordedRotations)
                                                   - 1]
                newEvent = RotationEvent(endTime,
                                         (Decimal('-1') *
                                          lastEvent.getValue()).normalize(),
                                         Decimal('0'))
                self.recordedRotations.append(newEvent)
        else:
            newEvent = RotationEvent(startTime, Decimal('0'), Decimal('0'))
            self.recordedRotations.append(newEvent)
            newEvent = RotationEvent(endTime, Decimal('0'), Decimal('0'))
            self.recordedRotations.append(newEvent)

        if len(self.recordedButtons) > 0:
            if self.recordedButtons[0].getTime() != startTime:
                newEvent = ButtonEvent(startTime, Decimal('0'))
                self.recordedButtons.insert(0, newEvent)
            if self.recordedButtons[len(self.recordedButtons) -
                                    1].getTime() != endTime:
                newEvent = ButtonEvent(endTime, Decimal('0'))
                self.recordedButtons.append(newEvent)
        else:
            newEvent = ButtonEvent(startTime, Decimal('0'))
            self.recordedButtons.append(newEvent)
            newEvent = ButtonEvent(endTime, Decimal('0'))
            self.recordedButtons.append(newEvent)

        if len(self.recordedTouches) > 0:
            if self.recordedTouches[0].getTime() != startTime:
                newEvent = TouchEvent(startTime, None, Decimal('0'))
                self.recordedTouches.insert(0, newEvent)
            if self.recordedTouches[len(self.recordedTouches) -
                                    1].getTime() != endTime:
                newEvent = TouchEvent(endTime, None, Decimal('0'))
                self.recordedTouches.append(newEvent)
        else:
            newEvent = TouchEvent(startTime, None, Decimal('0'))
            self.recordedTouches.append(newEvent)
            newEvent = TouchEvent(endTime, None, Decimal('0'))
            self.recordedTouches.append(newEvent)
示例#3
0
    def startListening(self):
        self.sum = 0

        while True:
            self.checkSharedMemory()

            pollResult = self.knob.read_event(0)
            if pollResult is None:
                continue

            (time, event, val) = pollResult
            time = Decimal('{}'.format(time)).normalize()
            val = Decimal('{}'.format(val)).normalize()

            if event == EVENT_ROTATE:
                self.sum = Decimal(self.sum) + val
                event = RotationEvent(time, val, self.sum)
            elif event == EVENT_BUTTON:
                event = ButtonEvent(time, val)

            self.bareSignalsLock.acquire()
            self.bareSignals.append(event)
            self.bareSignalsLock.release()

        self.cleanUp()
    def startListening(self):
        tapTimeStamp = None
        timeout = 0.5

        self.sum = 0

        while True:
            self.checkSharedMemory()

            pollResult = self.knob.read_event(0)
            if pollResult is None:
                continue

            (time, event, val) = pollResult
            time = Decimal('{}'.format(time)).normalize()
            val = Decimal('{}'.format(val)).normalize()

            if event == EVENT_ROTATE:
                self.sum = Decimal(self.sum) + val
                event = RotationEvent(time, val, self.sum)
            elif event == EVENT_BUTTON:
                event = ButtonEvent(time, val)

            #Check For Double Tap
            if event.getEvent() == EVENT_BUTTON and event.getValue(
            ) == Decimal('0'):
                if tapTimeStamp != None and (event.getTime() -
                                             tapTimeStamp) <= Decimal(
                                                 '{}'.format(timeout)):
                    pass
                tapTimeStamp = event.getTime()

            self.signalsLock.acquire()
            self.signals.append(event)
            self.signalsLock.release()

        self.cleanUp()
示例#5
0
    #     (4, 6), (5, 7), (6, 8), (7, 9), (10, 10),
    #     (11, 11), (13, 12), (14, 13), (15, 14), (16, 15),
    #     (17, 16), (18, 17), (19, 18), (19.5, 19), (20, 20)
    #     ], n))

    #print(myLinearInterpolation(
    #    [(0, 1), (1.5, 2), (1.7, 3), (3, 4), (3.1, 5),
    #     (4, 6), (5, 7), (6, 8), (6.5, 9), (11, 10),
    #     (11.5, 11), (13, 12), (14, 13), (15, 14), (16, 15),
    #     (17, 16), (18, 17), (19, 18), (19.5, 19), (20, 20)
    #     ], n))

    #print(myLinearInterpolation(
    #    [(0, 1), (6, 3), (13, 8), (20, 12)], n))

    r1 = RotationEvent(1, 1, 1)
    r2 = RotationEvent(2, 2, 3)
    r3 = RotationEvent(3, 1, 4)
    r4 = RotationEvent(4, 1, 5)
    r5 = RotationEvent(5, -2, 3)

    r6 = RotationEvent(1, 1, 1)
    r7 = RotationEvent(2, -1, 0)
    r8 = RotationEvent(3, 2, 2)
    r9 = RotationEvent(4, 4, 6)
    r10 = RotationEvent(5, -2, 3)

    m1 = Motion()
    m2 = Motion()

    m1.addEvent(r1)
示例#6
0
    def transformMotion(self, signals):
        self.signals = signals
        interpolator = Interpolator()
        n = 64

        startTime = None
        endTime = None

        for event in self.signals:
            if startTime == None:
                startTime = event.getTime()
            elif startTime > event.getTime():
                startTime = event.getTime()

            if endTime == None:
                endTime = event.getTime()
            elif endTime < event.getTime():
                endTime = event.getTime()

            if isinstance(event, RotationEvent):
                self.recordedRotations.append(event)
            elif isinstance(event, ButtonEvent):
                self.recordedButtons.append(event)
            elif isinstance(event, TouchEvent):
                self.recordedTouches.append(event)
            else:
                pass

        if startTime is None or endTime is None:
            raise NotEnoughSignals()

        #Construct Motion
        transformedMotion = Motion()
        transformedMotion.setStartTime(startTime)
        transformedMotion.setEndTime(endTime)

        self.addNeutralValues(startTime, endTime)

        #Rotation Part of Motion
        result = interpolator.linearInterpolation(self.recordedRotations, n)

        transformedTime = result[0]
        transformedSum = result[1]

        for i in range(len(transformedTime)):
            event = RotationEvent(transformedTime[i], None, transformedSum[i])
            transformedMotion.addEvent(event)

        #Button Part of Motion
        result = interpolator.linearInterpolation(self.recordedButtons, n)

        transformedTime = result[0]
        transformedValue = result[1]

        for i in range(len(transformedTime)):
            event = ButtonEvent(transformedTime[i], transformedValue[i])
            transformedMotion.addEvent(event)

        #Touch Part of Motion
        touchEventDictionary = self.sortTouches()
        for touchLocation in touchEventDictionary:
            result = interpolator.linearInterpolation(touchLocation[1], n)

            transformedTime = result[0]
            transformedValue = result[1]

            for i in range(len(transformedTime)):
                event = TouchEvent(transformedTime[i], touchLocation[0],
                                   transformedValue[i])
                transformedMotion.addEvent(event)

        #Scaling and adjustment
        self.scaleMotion(transformedMotion)
        self.adjustValues(transformedMotion)

        return transformedMotion
示例#7
0
    def transformMotion(self, signals):
        self.signals = signals
        interpolator = Interpolator()
        n = 64

        startTime = None
        endTime = None

        for event in self.signals:
            if startTime == None:
                startTime = event.getTime()
            elif startTime > event.getTime():
                startTime = event.getTime()

            if endTime == None:
                endTime = event.getTime()
            elif endTime < event.getTime():
                endTime = event.getTime()

            if isinstance(event, RotationEvent):
                self.recordedRotations.append(event)
            elif isinstance(event, ButtonEvent):
                self.recordedButtons.append(event)
            elif isinstance(event, TouchEvent):
                #self.recordedTouches.append(event)

                if event.getLocation is None:
                    raise NameError('Hier ist ein Fehler aufgetreten')

                #Sort Touches by Locations
                if event.getLocation() not in self.touches:
                    self.touches[event.getLocation()] = []

                self.touches[event.getLocation()].append(event)

            else:
                pass

        if startTime is None or endTime is None:
            raise NotEnoughSignals()

        #Construct Motion
        transformedMotion = Motion()
        transformedMotion.setStartTime(startTime)
        transformedMotion.setEndTime(endTime)

        self.addNeutralValues(startTime, endTime)

        #print('ROTATIONS')
        #print(self.recordedRotations)
        #print('BUTTONS')
        #print(self.recordedButtons)
        #print('TOUCHES ARRAY')
        #print(self.recordedTouches)
        #print('TOUCHES DIC')
        #print(self.touches)
        #return

        #Rotation Part of Motion
        if len(self.recordedRotations) > 0:
            result = interpolator.linearInterpolation(self.recordedRotations,
                                                      n)

            transformedTime = result[0]
            transformedSum = result[1]

            for i in range(len(transformedTime)):
                event = RotationEvent(transformedTime[i], None,
                                      transformedSum[i])
                transformedMotion.addEvent(event)
        else:
            print('Es wurde keine Rotation hinzugefügt')

        #Button Part of Motion
        if len(self.recordedButtons) > 0:
            result = interpolator.linearInterpolation(self.recordedButtons, n)

            transformedTime = result[0]
            transformedValue = result[1]

            for i in range(len(transformedTime)):
                event = ButtonEvent(transformedTime[i], transformedValue[i])
                transformedMotion.addEvent(event)
        else:
            print('Es wurde kein Button hinzugefügt')

        #Touch Part of Motion
        for location in self.touches:
            touchEvents = self.touches[location]
            result = interpolator.linearInterpolation(touchEvents, n)

            transformedTime = result[0]
            transformedValue = result[1]

            for i in range(len(transformedTime)):
                event = TouchEvent(transformedTime[i], location,
                                   transformedValue[i])
                transformedMotion.addEvent(event)

        #Scaling and adjustment
        self.scaleMotion(transformedMotion)
        self.adjustValues(transformedMotion)

        return transformedMotion
示例#8
0
    def getMotion(self, path):
        deviceManager = DeviceManager()
        f = open(path, 'r')

        motion = Motion()

        for line in f:
            if line[:len("Name")] == "Name":
                motion.setName(line[len("Name:"):line.find(";")])
                continue
            elif line[:len("Device")] == "Device":
                deviceName = line[len("Device:"):line.find(";")]
                if deviceName == 'None':
                    continue
                device = deviceManager.getDevice(deviceName)
                motion.assignDevice(device)
                continue
            elif line[:len("Function")] == "Function":
                functionName = line[len("Function:"):line.find(";")]
                if functionName == 'None':
                    continue
                device = motion.getAssignedDevice()
                function = getattr(device, functionName)
                motion.assignFunction(function)
                continue

            time = line[line.find("Time:") + len("Time:"):line.find(";")]
            time = Decimal(time)
            line = line[line.find(";") + 1:]
            event = line[line.find("Event:") + len("Event:"):line.find(";")]
            line = line[line.find(";") + 1:]
            location = line[line.find("Location:") +
                            len("Location:"):line.find(";")]
            line = line[line.find(";") + 1:]
            if location == 'None':
                location = None
            value = line[line.find("Value:") + len("Value:"):line.find(";")]
            if value == 'None':
                value = None
            else:
                value = Decimal(value)
            line = line[line.find(";") + 1:]
            sum = line[line.find("Sum:") + len("Sum:"):line.find(";")]
            if sum == 'None':
                sum = None
            else:
                sum = Decimal(sum)
            line = line[line.find(";"):]

            if event == EVENT_BASE:
                event = BaseEvent(time)
            elif event == EVENT_ROTATE:
                event = RotationEvent(time, value, sum)
            elif event == EVENT_BUTTON:
                event = ButtonEvent(time, value)
            elif event == EVENT_TOUCH:
                event = TouchEvent(time, location, value)

            motion.addEvent(event)

        return motion