コード例 #1
0
 def _safeStop(self, shutdown=False):
     """
     This function should never be called directelly. The programm might be stopped by ending the _main io loop : io.goOn=False
     :param shutdown:
     :return:
     """
     system.logInfo("finishing")
     self.io.writeText("Exiting", 1)
     system.startCommand("mpc stop")
     system.startCommand("mpc clear")
     self.io.closeIO()
     system.closeShelf()
     self.io.writeText("power off", 1)
     system.logInfo("finished safely")
     if shutdown:
         system.startCommand("sudo reboot")
コード例 #2
0
    def removeRemoteControls(self,name):
        if name in self.remoteControls:
            self.remoteControls.remove(name)
            logInfo("remotes controls (removing) : ", self.remoteControls)

        if len(self.remoteControls)==0 :
            # do something when last subscriber left
            pass

        stillOneActiveRemoteControls=False
        for d in self.remoteControls:
            if "local" not in d:
                stillOneActiveRemoteControls=True
        if not stillOneActiveRemoteControls:
            # in this case there is no more active listener (i.e. using snapcast).
            if self.os.mode==MODE_SNAPSTREAM_OUT :
                self.os.stopOutputtingToSnapCast()
            pass
コード例 #3
0
    def updatingRemotesList(self,remotes):
        """
        This function is called whenever there is a known change in the remote devices
        WARNING : a remote present in this list might be disconnected at the moment this function is called.
        :param remotes: dictionnary containing information about the remote devices.
        :return: nothing
        """
        self.remoteNames=list(remotes.keys())
        if name in self.remoteNames:
            self.remoteNames.remove(name) # is it modifying remoteNames ?
        ####################################################################### TODO : in case of streaming, one can stop the stream if all host disconnected or sent a stop message

        # remove a remote controls if it disconnects
        toKill=[]
        for title in self.remoteControls:
            if title not in self.remoteNames:
                toKill.append(title)
        for title in toKill:
            self.removeRemoteControls(title)

        logInfo("known hosts : ",self.remoteNames)
コード例 #4
0
    def mainLoop(self):
        """
        _main loop of os
        outputs to devices and lcds should only be performed from this thread to prevent concurrency
        Other thread might ask for an output refresh
        :return: nothing
        """
        self.goOn = True
        count = 0

        while self.goOn:
            begin=time()

            # change volume
            dec=self.volumeCtl.getDec()
            if dec!=0 :
                self.os.takeAction(MSG_VOL, dec)
                count = 1

            # change menu
            dec=self.menuCtl.getDec()
            if dec!=0 :
                self.os.takeAction(MSG_MENU, dec)
                count = 1

            # back button status
            if self.volumeCtl.getSwitch():
                self.os.takeAction(MSG_BACK, 0)
                count = 1

            # select button status
            if self.menuCtl.getSwitch():
                self.os.takeAction(MSG_SELECT, 0)
                count = 1

            # front buttons
            for id in self.faceButtons.getPressed():
                self.os.takeAction(MSG_BUTTON,id)
                count = 1


            # not very often
            if count % int(180/self.loopTime) == 0:
                count = 1
                self.updateRotariesStates()



            # not often
            if count % int(2.5/self.loopTime) == 0:

                self.os.considerStoppingRebooting()

                # this test is now done less often than before to prevent sd card corruption and overflow.

                # alarms
                now = datetime.datetime.now(tz=tz)
                for alarm in self.os.menu.getActiveAlarms():
                    if int(now.hour) == int(alarm.hour) and int(now.minute) >= int(alarm.minute) and alarm.reseted:
                        alarm.reseted = False
                        logInfo("alarm found in io_mr")
                        self.os.menu.forceRadio()

                if int(now.hour) == 0 and int(now.minute) == 0:
                    for alarm in self.os.menu.getActiveAlarms():
                        alarm.reseted = True  # reset all alarms at midnight

                self.os.dealWithBluetoothCon()
                self.backlight.test()



            # refresh view if any changes occurred
            self.updateScreens()

            count += 1
            end=time()

            sleep(max(self.loopTime  - (end-begin),0.01))
コード例 #5
0
 def appendRemoteControls(self,name):
     if name not in self.remoteControls:
         self.remoteControls.append(name)
         self.askResendTexts()
         logInfo("remotes controls (adding)  : ",self.remoteControls)
コード例 #6
0
        system.startCommand("mpc clear")
        self.io.closeIO()
        system.closeShelf()
        self.io.writeText("power off", 1)
        system.logInfo("finished safely")
        if shutdown:
            system.startCommand("sudo reboot")


################ Launching app and dealing with sigterm, control-c


def sigterm_handler(signal, frame):
    # save the state here or do whatever you want
    os.io.goOn = False


signal.signal(signal.SIGTERM, sigterm_handler)

# start os !
global os
os = Os()
try:
    os.run()
except KeyboardInterrupt:
    system.logInfo("received keyboard interrupt, exiting")
    pass

finally:
    os._safeStop(shutdown)