Example #1
0
def degree_to_visca(value, what, flip=False):
    if what == 'pan':
        # value must be between -170 & 170
        if value >= 0:
            old_min = 0
            old_max = 170
            new_min = 0
            new_max = 7708
        else:
            old_min = -170
            old_max = 0
            new_min = 57829
            new_max = 65535
    elif what == 'tilt':
        # value must be between -20 & 90
        if value >= 0:
            old_min = 0
            old_max = 90
            new_min = 0
            new_max = 4080
        else:
            old_min = -20
            old_max = 0
            new_min = 61455
            new_max = 65535
        if flip:
            # value must be between -90 & 20
            pass
            print('flip function is not yet implemented for tilt')
    return int(scale(value, old_min, old_max, new_min, new_max))
Example #2
0
def visca_to_degree(value, what, flip=False):
    if what == 'pan':
        # value must be between -170 & 170
        # value must be between -170 & 170
        if value <= 7708:
            old_min = 0
            old_max = 7708
            new_min = 0
            new_max = 170
        else:
            old_min = 57829
            old_max = 65535
            new_min = -170
            new_max = 0
    elif what == 'tilt':
        # value must be between -20 & 90
        if value <= 4080:
            old_min = 0
            old_max = 4080
            new_min = 0
            new_max = 90
        else:
            old_min = 61455
            old_max = 65535
            new_min = -20
            new_max = 0
        if flip:
            # value must be between -90 & 20
            print('flip function is not yet implemented for tilt')
    value = scale(value, old_min, old_max, new_min, new_max)
    return round(value, 1)
Example #3
0
    def _query(self, function=None):
        """
        Query method needs a parameter as argument
            :Return False if no parameter is provided
            :Return False if parameter provided does not exist
            :Return
        """
        if not function:
            # maybe we could dump all functions if no function value is present
            # or maybe add a 'all' function?
            return False
        if debug == 4:
            print('QUERY', function)
        if function == 'pan' or function == 'tilt':
            # pan and tilt are separate properties.
            # If we want to automatically query all properties, we must catch it here
            function = 'pan_tilt'
        # transform the property into its code (located in the __init__file of the package)
        if function in queries:
            subcmd = queries.get(function)
        else:
            if debug:
                # there is no code for this function
                dbg = 'ERROR 42 - function {function} has not yet been implemented'
                print(dbg.format(function=function))
            return False
        # query starts with '\x09'
        query = '\x09' + subcmd
        if debug == 4:
            dbg = 'send {function} query : {query}'
            print(dbg.format(function=function, query=query.encode('hex')))
        # wait for the reply
        reply = self._come_back(query)
        if reply == None:
            return self._query(function)
        if reply:
            if debug == 4:
                dbg = 'receive reply : {function} is {reply}'
                print(dbg.format(function=function, reply=reply.encode('hex')))
            # remove 2 first packets and the last terminator
            # FIX ME : We must remove the first hex number elsewhere if we use multiples camera
            reply = reply[2:-1].encode('hex')

            # transform to a list of int
            # FIX ME : found a nicer solution please, it's ugly !!
            def hex_unpack(value, listt, size=2):
                part = value[:size]
                value = value[size:]
                listt.append(part)
                if value:
                    hex_unpack(value, listt)
                    return listt

            if len(reply) > 2:
                # it's a long answer, convert it to a list
                reply = hex_unpack(reply, [])
            else:
                # it's a single value, just convert it to a valid base 10 integer
                reply = int(reply, 16)
            if function in high_res_params:
                # parameter value is coded on 2 hexa numbers
                reply = hex_to_int(reply)
            elif function in very_high_res_params:
                # parameter value is coded on 4 hexa numbers
                reply = hex_to_int(reply)
            # Check if the function has a special value to be translated
            if function in answers:
                # translate visca code to real life value
                if reply in answers[function]:
                    reply = answers[function][reply]
            elif function == 'NR' or function == 'gamma' or function == 'chromasuppress':
                reply = reply
            elif function == 'color_gain' or function == 'color_hue':
                reply = int(reply[3], 16)
                reply = str(scale(reply, 0, 14, 60, 200))
                if function == 'color_gain':
                    reply = reply + '%'
                else:
                    reply = reply + '°'
            elif function == 'pan_tilt':
                pan = reply[0:4]
                tilt = reply[4:8]
                pan = hex_to_int(pan)
                tilt = hex_to_int(tilt)
                pan = visca_to_degree(pan, 'pan')
                tilt = visca_to_degree(tilt, 'tilt')
                reply = [pan, tilt]
            else:
                if debug == 4:
                    print('FIX ME : is it normal that :', function,
                          'has no translation??')
            if debug:
                dbg = '{function} is {reply}'
                print(dbg.format(function=function, reply=reply))
            return reply