示例#1
0
    def _pause_resume_callback(self, *args):
        self.logger.info(f"Pause/Resume song.")

        state = util.exec_mpc_func(self.mpc, self.mpc.status)["state"]
        if state == "stop":
            util.exec_mpc_func(self.mpc, self.mpc.play)
        else:
            util.exec_mpc_func(self.mpc, self.mpc.pause)
示例#2
0
 def _dec(self, counter):
     vol = int(util.exec_mpc_func(self.mpc, self.mpc.status)["volume"])
     new_vol = vol
     i = 0
     while vol - self.volume_steps <= new_vol and i < 4:
         new_vol = vol - self.volume_steps - i
         util.exec_mpc_func(self.mpc, self.mpc.setvol, new_vol)
         i += 1
         new_vol = int(
             util.exec_mpc_func(self.mpc, self.mpc.status)["volume"])
     self.logger.info(f"Decreasing volume to {new_vol}.")
示例#3
0
 def _prev_callback(self, *args):
     self.logger.info(f"Play previous song.")
     status = util.exec_mpc_func(self.mpc, self.mpc.status)
     state = status["state"]
     if state == "play":
         playlist_length = int(status["playlistlength"])
         current_song_number = int(status["song"])
         if current_song_number == 0:
             util.exec_mpc_func(self.mpc, self.mpc.play, playlist_length-1)
         else:
             util.exec_mpc_func(self.mpc, self.mpc.previous)
示例#4
0
文件: rfid.py 项目: phaked/musicbox
    def watch(self):
        self.logger.info("Starting RFID.")
        try:
            while not self.end:
                status , _ = self.reader.MFRC522_Request(self.reader.PICC_REQIDL)
                if status == self.reader.MI_OK:
                    status, uid = self.reader.MFRC522_Anticoll()
                if status == self.reader.MI_OK:
                    id = self._convert_uid(uid)
                else:
                    id = 0

                if id != self.last_card_id:
                    self.logger.info(f"Card with id={id} read.")
                    exec_mpc_func(self.mpc, self.mpc.stop)
                    exec_mpc_func(self.mpc, self.mpc.clear)
                    if id != 0:
                        if id in self.playlist_map:
                            playlist = self.playlist_map[id]
                            self.logger.info(f"Play {playlist}")
                            exec_mpc_func(self.mpc, self.mpc.load, playlist)
                            exec_mpc_func(self.mpc, self.mpc.play)
                        else:
                            self.logger.info(f"RFID with uid {id} is not mapped to a playlist.")
                self.last_card_id = id
                self.reader.MFRC522_Request(self.reader.PICC_HALT)
                sleep(1)
        except:
            pass
        GPIO.cleanup()
        self.logger.info("Exiting RFID.")
        return