示例#1
0
 def get_dsp_source(self):
     """
     Read DPS source data
     :return:
         0: AUX
         1: RPI
         2: SPDIF
         3: AUTO select (Default)
     """
     with i2c_lock:
         _source = DSP.read_back(InputSelector._DSP_SOURCE_SELECT[0],
                                 InputSelector._DSP_SOURCE_SELECT[0])
     self._dsp_source = _source
     return _source
示例#2
0
 def _get_hw_volume(self):
     """
     Get actual DSP volume if dt > sample freq lim
     else return last true vol
     :return: DSP volume [0-100]
     """
     t_now = time.perf_counter()
     self._new_reading = t_now - self._t_last_dsp_read > 1 / self._dps_sample_freq_lim
     if self._new_reading:
         self._t_last_dsp_read = t_now
         with i2c_lock:  # ensure safe i2s read
             self.true_vol = float(
                 DSP.read_back(_ADD_VOL_READBACK_HIGH,
                               _ADD_VOL_READBACK_LOW)) * 100
     return self.true_vol
示例#3
0
def get_hw_vol():
    global _t_scan, _update_hw_vol_freq, hw_volume, sw_volume, vol_err, emit_volume, rising_vol
    _t_scan = time.time()
    vol = int(float(DSP.read_back(_VOL_READBACK_HIGH, _VOL_READBACK_LOW))*101)

    # Higher sensitively in turning direction and lower in opposite direction.
    if rising_vol and (vol > hw_volume or (vol + 1) < hw_volume) or\
            (vol < hw_volume or (vol - 1) > hw_volume):
        _update_hw_vol_freq = 10
        rising_vol = hw_volume < vol
        hw_volume = vol
        log.info("HW Volume: {}%".format(hw_volume))
        vol_err = abs(sw_volume - hw_volume)
        emit_volume = True
    else:
        _update_hw_vol_freq = 1.9
    return hw_volume
示例#4
0
 def set_dsp_source(self, dsp_source):
     """
     Set DSP source
     :param dsp_source:
         0: AUX
         1: RPI
         2: SPDIF
         3: AUTO select (Default)
     :return: set source if successful, else -1
     """
     if dsp_source not in [
             SOURCE_AUTO, SOURCE_AUX, SOURCE_RPI, SOURCE_SPDIF
     ]:
         log.err('Unsupported source')
         return -1
     with i2c_lock:
         DSP.write_param(DSP_SOURCE_SELECT, dsp_source)
         time.sleep(0.1)
         _source = DSP.read_back(InputSelector._DSP_SOURCE_SELECT[0],
                                 InputSelector._DSP_SOURCE_SELECT[0])
         self._dsp_source = _source
         return _source
示例#5
0
    def run(self):
        global emit_shutdown
        _rpi = _spdif = _aux = False
        GPIO.setmode(GPIO.BCM)
        GPIO.setwarnings(False)
        GPIO.setup(self._spdif_pin, GPIO.IN, GPIO.PUD_UP)
        GPIO.setwarnings(True)
        self.is_alive = True
        while self.is_alive and not emit_shutdown:

            # get state of SPDIF lock
            spdif_lock = not GPIO.input(self._spdif_pin)  # inverted

            # Check for source change
            if self._dsp_source != self.source:
                self.set_dsp_source(self.source)
            if self.source == SOURCE_AUTO:
                en_spdif = not _aux and not _rpi and _spdif
            elif self.source == SOURCE_SPDIF:
                en_spdif = _spdif

            # fixme temporary for PCB rev1, change to en_spdif for rev2
            GPIO.output(SPDIF_ENABLE_PIN,
                        spdif_lock)  # activate spdif relay if spdif lock.

            # check for spdif lock state change
            if self.spdif_lock != spdif_lock:
                with i2c_lock:
                    self.dsp_reset(2)  # reset dsp
                    self.spdif_lock = spdif_lock

            # get source status
            with i2c_lock:
                _aux = bool(
                    DSP.read_back(InputSelector._AUX_DETECT_REG[0],
                                  InputSelector._AUX_DETECT_REG[1]))
                _rpi = bool(
                    DSP.read_back(InputSelector._RPI_DETECT_REG[0],
                                  InputSelector._RPI_DETECT_REG[1]))
                _spdif = self.spdif_lock and bool(
                    DSP.read_back(InputSelector._SPDIF_DETECT_REG[0],
                                  InputSelector._SPDIF_DETECT_REG[1]))

            # amp enable
            if not AMP_ALWAYS_OFF and (_aux or _rpi or _spdif):
                if not self._any_signal:
                    self._any_signal = True
                    self._t_first_signal = time.perf_counter()
                self._t_last_signal = time.perf_counter()
                t_active = self._t_last_signal - self._t_first_signal
                if t_active > self._t_debounce or self.amp_always_on:
                    self.amp_en = True
            else:
                self._any_signal = False
                if time.perf_counter(
                ) > self._t_last_signal + self.signal_timeout and not self.amp_always_on:
                    self.amp_en = False
            GPIO.output(self._amp_pin, self.amp_en)

            self.aux_detected = bool(_aux)
            self.rpi_detected = bool(_rpi)
            self.spdif_detected = bool(_spdif)

            t_sleep = (0.1, 1)[standby]
            time.sleep(t_sleep)

        self.is_alive = False
        GPIO.output(self._amp_pin, 0)