Exemple #1
0
 def parse_value(self, value):
     if value.endswith("%"):
         percent = int(value[0:-1])
         return percent2amplification(percent)
     elif value.lower().endswith("db"):
         db = int(value[0:-2])
         return decibel2amplification(db)
     elif "." in value:
         return float(value)
     elif value.startswith("0x"):
         return int(value, 16)
     else:
         return int(value)
Exemple #2
0
    def update_dsp(self, value):
        if value is None:
            return

        # convert percent to multiplier
        volume = percent2amplification(value)

        # write multiplier to DSP
        dspdata = datatools.int_data(self.dsp.decimal_repr(volume),
                                     self.volume_register_length)
        self.spi.write(self.volume_register, dspdata)

        self.dspdata = dspdata
        self.dspvol = value
Exemple #3
0
    def string_to_volume(self, strval):
        strval = strval.lower()
        vol = 0
        if strval.endswith("db"):
            try:
                dbval = float(strval[0:-2])
                vol = decibel2amplification(dbval)
            except:
                logging.error("Can't parse db value {}", strval)
                return None
            # TODO
        elif strval.endswith("%"):
            try:
                pval = float(strval[0:-1])
                vol = percent2amplification(pval)
            except:
                logging.error("Can't parse db value {}", strval)
                return None
        else:
            vol = float(strval)

        return vol
Exemple #4
0
    def update_volume(self):

        if self.volume_register is None or self.spdif_register is None:
            return False

        # Read SPDIF status registers
        data = self.spi.read(0xf617, 6)
        if len(data) != 6:
            logging.error("internal error: could not read 6 bytes from SPI")
            return False

        _b1, vol, volid, _b2 = struct.unpack(">BHHB", data)

        if volid != 0x048a:
            return False

        if vol < 0x100f or vol > 0x164f:
            return False

        # Read SPDIF enable register
        data = self.spi.read(self.spdif_register, 4)
        [spdif_active] = struct.unpack(">l", data)
        if spdif_active == 0:
            return False

        volpercent = (vol - 0x100f) / 16
        if volpercent < 0 or volpercent > 100:
            logging.error(
                "internal error, got volume = %s, "
                "but should be in 0-100 range", volpercent)
        # convert percent to multiplier
        volume = percent2amplification(volpercent)

        # write multiplier to DSP
        dspdata = datatools.int_data(self.dsp.decimal_repr(volume),
                                     self.volume_register_length)
        self.spi.write(self.volume_register, dspdata)
        return True
Exemple #5
0
 def write_volume(self, volume):
     assert 0 <= volume <= 100
     dspdata = datatools.int_data(
         self.dsp.decimal_repr(percent2amplification(volume)),
         self.dsp.WORD_LENGTH)
     self.spi.write(self.volume_register, dspdata)