示例#1
0
    def cmd_write_reg(self):
        if len(self.args.parameters) > 1:
            reg = parse_int(self.args.parameters[0])
            value = parse_int(self.args.parameters[1])
        else:
            print("parameter missing, need addr value")

        data = [(value >> 8) & 0xff, value & 0xff]
        self.dsptk.sigmatcp.write_memory(reg, data)
示例#2
0
    def cmd_read(self, display=DISPLAY_FLOAT, loop=False, length=None):
        try:
            addr = parse_int(self.args.parameters[0])
        except:
            print("Can't parse address {}".format(self.args.parameters))
            sys.exit(1)

        while True:
            if display == DISPLAY_FLOAT:
                val = self.dsptk.sigmatcp.read_decimal(addr)
                print("{:.8f}".format(val))
            elif display == DISPLAY_INT:
                val = 0
                for i in self.dsptk.sigmatcp.read_data(addr, length):
                    val *= 256
                    val += i
                print(val)
            elif display == DISPLAY_HEX:
                val = self.dsptk.sigmatcp.read_data(addr, length)
                print(''.join(["%02X " % x for x in val]))

            if not loop:
                break

            try:
                time.sleep(float(self.args.delay) / 1000)
            except KeyboardInterrupt:
                break
示例#3
0
    def __init__(self, alsa_mixer_name="DSPVolume"):
        self.restore = False

        self.server = SigmaTCPServer()
        if "--alsa" in sys.argv:
            logging.info("initializiong ALSA mixer control")
            alsasync = AlsaSync()
            alsasync.set_alsa_control(alsa_mixer_name)
            SigmaTCPHandler.alsasync = alsasync
            volreg = SigmaTCPHandler.get_meta(ATTRIBUTE_VOL_CTL)
            if volreg is not None and len(volreg) > 0:
                reg = datatools.parse_int(volreg)
                alsasync.set_volume_register(reg)
            alsasync.start()
        else:
            logging.info("not using ALSA volume control")
            self.alsa_mixer_name = None

        if "--lgsoundsync" in sys.argv:
            try:
                logging.info("initializing LG SoundSync")
                SigmaTCPHandler.lgsoundsync = SoundSync()
                SigmaTCPHandler.lgsoundsync.start()
                SigmaTCPHandler.update_lgsoundsync()
            except Exception as e:
                logging.exception(e)
        else:
            logging.info("not enabling LG SoundSync")

        if "--restore" in sys.argv:
            self.restore = True

        logging.info("server initialization finished")
示例#4
0
    def get_samplerate(self):
        sr = datatools.parse_int(
            self.sigmatcp.request_metadata(ATTRIBUTE_SAMPLERATE))

        if sr is None or sr == 0:
            return 48000
        else:
            return sr
示例#5
0
    def get_limit(self):
        volctl = datatools.parse_int(
            self.sigmatcp.request_metadata(ATTRIBUTE_VOL_LIMIT))

        if volctl:
            return self.sigmatcp.read_decimal(volctl)
        else:
            logging.info("%s is undefined", ATTRIBUTE_VOL_LIMIT)
示例#6
0
    def get_loudness(self):
        volctl = datatools.parse_int(
            self.sigmatcp.request_metadata(ATTRIBUTE_LOUDNESS))

        if volctl:
            return self.sigmatcp.read_decimal(volctl)
        else:
            logging.info("%s is undefined", ATTRIBUTE_LOUDNESS)
示例#7
0
 def set_loudness(self, volume):
     volctl = datatools.parse_int(
         self.sigmatcp.request_metadata(ATTRIBUTE_LOUDNESS))
     if volctl is not None:
         self.sigmatcp.write_decimal(volctl, volume)
         return True
     else:
         logging.info("%s is undefined", ATTRIBUTE_LOUDNESS)
         return False
示例#8
0
    def cmd_selfboot(self):
        val = 0
        if len(self.args.parameters) > 0:
            val = parse_int(self.args.parameters[0])
            rw = GPIO_WRITE
        else:
            rw = GPIO_READ

        logging.error("dsptk selfboot %s %s", val, rw)

        res = self.dsptk.sigmatcp.readwrite_gpio(rw, GPIO_SELFBOOT, val)
        print(res)
示例#9
0
    def mute(self, mute=True):
        mutereg = datatools.parse_int(
            self.sigmatcp.request_metadata(ATTRIBUTE_MUTE_REG))

        if mutereg is not None:
            if mute:
                self.sigmatcp.write_memory(mutereg, self.sigmatcp.int_data(1))
            else:
                self.sigmatcp.write_memory(mutereg, self.sigmatcp.int_data(0))
            return True
        else:
            return False
示例#10
0
    def get_volume(self):
        volctl = None
        try:
            volctl = datatools.parse_int(
                self.sigmatcp.request_metadata(ATTRIBUTE_VOL_CTL))
        except:
            pass

        if volctl is not None:
            return self.sigmatcp.read_decimal(volctl)
        else:
            logging.info("%s is undefined", ATTRIBUTE_VOL_CTL)
示例#11
0
    def update_lgsoundsync(clear=False):
        if SigmaTCPHandler.lgsoundsync is None:
            logging.debug("LG SoundSync instance is None")
            return

        if clear:
            SigmaTCPHandler.lgsoundsync.set_registers(None, None)
            return

        logging.debug("checking profile for SPDIF state and volume control support")
        volreg = SigmaTCPHandler.get_meta(ATTRIBUTE_VOL_CTL)
        spdifreg = SigmaTCPHandler.get_meta(ATTRIBUTE_SPDIF_ACTIVE)
        if volreg is None or len(volreg) == 0 or \
            spdifreg is None or len(spdifreg) == 0:
            SigmaTCPHandler.lgsoundsync.set_registers(None, None)
            logging.debug("disabled LG SoundSync")

        logging.info("enabling LG SoundSync")
        volr = datatools.parse_int(volreg)
        spdifr = datatools.parse_int(spdifreg)
        SigmaTCPHandler.lgsoundsync.set_registers(volr, spdifr)
示例#12
0
    def update_alsasync(clear=False):
        if SigmaTCPHandler.alsasync is None:
            return

        if clear:
            SigmaTCPHandler.alsasync.set_volume_register(None)
            return

        volreg = SigmaTCPHandler.get_meta(ATTRIBUTE_VOL_CTL)
        if volreg is None or len(volreg) == 0:
            SigmaTCPHandler.alsasync.set_volume_register(None)

        reg = datatools.parse_int(volreg)
        SigmaTCPHandler.alsasync.set_volume_register(reg)
示例#13
0
    def set_balance(self, value):
        '''
        Sets the balance of left/right channels.
        Value ranges from 0 (only left channel) to 2 (only right channel)
        at balance=1 the volume setting on both channels is equal
        '''
        if (value < 0) or (value > 2):
            raise RuntimeError("Balance value must be between 0 and 2")

        balctl = datatools.parse_int(
            self.sigmatcp.request_metadata(ATTRIBUTE_BALANCE))

        if balctl is not None:
            self.sigmatcp.write_decimal(balctl, value)
示例#14
0
    def __init__(self, alsa_mixer_name="DSPVolume"):
        self.restore = False
        self.abort = False
        self.zeroconf = None

        self.server = SigmaTCPServer()

        params = self.parse_config()
        if params["alsa"]:
            logging.info("initializing ALSA mixer control %s", alsa_mixer_name)
            alsasync = AlsaSync()
            if alsasync.set_alsa_control(alsa_mixer_name):
                SigmaTCPHandler.alsasync = alsasync
                volreg = SigmaTCPHandler.get_meta(ATTRIBUTE_VOL_CTL)
                if volreg is not None and len(volreg) > 0:
                    reg = datatools.parse_int(volreg)
                    alsasync.set_volume_register(reg)
                alsasync.start()
            else:
                logging.error("can't create mixer control - aborting")
                self.abort = True
        else:
            logging.info("not using ALSA volume control")
            self.alsa_mixer_name = None

        if params["lgsoundsync"]:
            try:
                logging.info("initializing LG Sound Sync")
                SigmaTCPHandler.lgsoundsync = SoundSync()
                SigmaTCPHandler.lgsoundsync.start()
                SigmaTCPHandler.update_lgsoundsync()
            except Exception as e:
                logging.exception(e)
        else:
            logging.info("not enabling LG Sound Sync")

        if this.notify_on_updates is not None:
            logging.info("Sending notifies on program updates to %s",
                         this.notify_on_updates)

        if params["restore"]:
            self.restore = True
示例#15
0
    def __init__(self, alsa_mixer_name="DSPVolume"):
        self.restore = False

        self.server = SigmaTCPServer()
        if "--alsa" in sys.argv:
            logging.info("initializiong ALSA mixer control")
            alsasync = AlsaSync()
            alsasync.set_alsa_control(alsa_mixer_name)
            SigmaTCPHandler.alsasync = alsasync
            volreg = SigmaTCPHandler.get_meta(ATTRIBUTE_VOL_CTL)
            if volreg is not None and len(volreg) > 0:
                reg = datatools.parse_int(volreg)
                alsasync.set_volume_register(reg)
            alsasync.start()
        else:
            logging.info("not using ALSA volume control")
            self.alsa_mixer_name = None

        if "--restore" in sys.argv:
            self.restore = False