Beispiel #1
0
    def selectNextOutdoor(self, selection_method):
        errorhandler.logdebug("SoundFiles::selectNextOutdoor")
        if self.outdoor_unused:
            return
        errorhandler.logdebug("selection_method:{}".format(selection_method))
        if selection_method == SelectionMethod.RANDOM:
            self.outdoor_file = random.choice(self.outdoor_files)
        elif selection_method == SelectionMethod.SEQUENTIAL:
            with shelve.open(PERSISTENT_INDEX_SHELF) as db:
                if "idx" in db:
                    self.next_outdoor_sound_index = db["idx"]
                    errorhandler.logdebug("retrieved {} from {}".format(
                        db["idx"], PERSISTENT_INDEX_SHELF))
                else:
                    self.next_outdoor_sound_index = 0
                    errorhandler.logdebug("initialised idx to 0")
                if self.next_outdoor_sound_index < 0 or self.next_outdoor_sound_index >= len(
                        self.outdoor_files):
                    self.next_outdoor_sound_index = 0
                self.outdoor_file = self.outdoor_files[
                    self.next_outdoor_sound_index]
                self.next_outdoor_sound_index += 1
                if self.next_outdoor_sound_index >= len(self.outdoor_files):
                    self.next_outdoor_sound_index = 0
                db["idx"] = self.next_outdoor_sound_index
                errorhandler.logdebug("stored {} in {}".format(
                    db["idx"], PERSISTENT_INDEX_SHELF))

        errorhandler.loginfo("outdoor files selected:{}".format(
            self.outdoor_file))
        self.outdoor_sound = pygame.mixer.Sound(str(self.outdoor_file))
Beispiel #2
0
    def __init__(self, indoorsoundfile, outdoorsoundsfolder,
                 indoorstereooutputchannel, outdoorstereooutputchannel):
        """
        define the location of the the sound files
        :param indoorsoundfile: string giving the path to the sound file used for indoor speakers
        :param outdoorsoundsfolder: string giving the path of the folder which contains sound files for outdoor speakers
                                    if None, ignore
        """

        os.system("amixer sset PCM 0dB")  #("amixer sset PCM -- -20dB")
        self.indoor_file = Path(indoorsoundfile)
        self.outdoor_unused = (outdoorsoundsfolder is None)

        if not self.outdoor_unused:
            self.outdoor_folder = Path(outdoorsoundsfolder)
        errorhandler.logdebug("SoundFiles::__init__")
        errorhandler.loginfo("indoor_file: {}".format(self.indoor_file))
        errorhandler.loginfo("outdoor_folder: {}".format(self.outdoor_folder))

        if not self.indoor_file.is_file():
            raise ValueError(
                "Indoor sound file not found or is not a file:{}".format(
                    indoorsoundfile))
        if not self.outdoor_unused:
            if not self.outdoor_folder.is_dir():
                raise ValueError(
                    "Outdoor sounds folder not found or is not a folder:{}".
                    format(outdoorsoundsfolder))

        self.indoor_stereo_output_channel = indoorstereooutputchannel
        self.outdoor_stereo_output_channel = outdoorstereooutputchannel

        self.initialiseMixer()
        self.refreshIndoor()
        self.refreshOutdoor()
Beispiel #3
0
 def playIndoor(self):
     self.indoor_channel.play(self.indoor_sound,
                              loops=0,
                              maxtime=0,
                              fade_ms=0)
     self.indoor_channel.set_volume(
         self.indoor_stereo_output_channel.leftChannelVolume,
         self.indoor_stereo_output_channel.rightChannelVolume)
     errorhandler.logdebug("SoundFiles::playIndoor")
Beispiel #4
0
 def refreshOutdoor(self):
     errorhandler.logdebug("SoundFiles::refreshOutdoor")
     if self.outdoor_unused:
         return
     self.outdoor_channel = pygame.mixer.Channel(self.OUTDOOR_CHANNEL_ID)
     self.outdoor_files = list(self.outdoor_folder.glob("*.wav"))
     errorhandler.loginfo("outdoor files found:{}".format(
         self.outdoor_files))
     self.selectNextOutdoor(SelectionMethod.SEQUENTIAL)
 def parse_message(self, structname, data):
     try:
         structinfo = self.configuration.get[structname]
         message_struct = namedtuple(structname, structinfo["fieldnames"])
         message = message_struct._make(struct.unpack(structinfo["unpackformat"], data))
         errorhandler.logdebug("unpacked message:{}".format(repr(message)))
         return message
     except struct.error as e:
         raise errorhandler.ArduinoMessageError("invalid msg for {}:{}".format(structname, str(e)))
    def check_for_incoming_info(self):
        """
           Checks for any incoming information and processes if found
        :return: true if any information was received, false otherwise
        """

        if self.test_message_response:
            self.parse_incoming_message(self.test_message_response)
            return True

        POLL_ONLY_TIMEOUT_VALUE = 0
        got_at_least_one = False
        while (True):
            readables, writables, errors = select.select([self.socket_datastream], [], [], POLL_ONLY_TIMEOUT_VALUE)
            if not self.socket_datastream in readables:
                return got_at_least_one
            got_at_least_one = True
            data, remote_ip_port = self.socket_datastream.recvfrom(MAX_EXPECTED_MSG_SIZE)
            if remote_ip_port != self.ip_port_arduino_datastream:
                errorhandler.loginfo("Msg from unexpected source {}".format(remote_ip_port))
            else:
                errorhandler.logdebug("msg received:{}".format(data.hex()))
                self.parse_incoming_message(data)
Beispiel #7
0
                        help="path to indoor sound effect file",
                        default="indoorsound")
    parser.add_argument("-o",
                        "--outdoorsoundsfolder",
                        help="path to outdoor sound effects folder ",
                        default="outdoorsounds")
    parser.add_argument("-t",
                        "--testsound",
                        help="play this sound continuously, if provided",
                        default="")
    args = parser.parse_args()

    errorhandler.initialise("doorbell", DEBUG_LOG_PATH,
                            logging.DEBUG if args.debug else logging.INFO)

    errorhandler.logdebug("Arguments provided:")
    errorhandler.logdebug(args)

    try:
        if circuitry.isButtonPressed():
            if len(args.testsound) == 0:
                args.testsound = DEFAULT_TEST_SOUND

        if len(args.testsound) > 0:
            playTestSoundUntilButtonPressed(args.testsound)

        sound_files = SoundFiles(
            args.indoorsoundfile,
            args.outdoorsoundsfolder,
            indoorstereooutputchannel=(StereoOutputChannel.LEFT
                                       if args.indoorleftchannel else
Beispiel #8
0
                        default=TESTPORT)
    parser.add_argument("-pw",
                        "--password",
                        help="the database password",
                        default="TESTREADONLY")
    parser.add_argument("-user",
                        "--username",
                        help="the database username",
                        default="testreadonly")
    args = parser.parse_args()

    errorhandler.initialise("ebtablerulegen", DEBUG_LOG_PATH,
                            logging.DEBUG if args.debug else logging.INFO)

    with DBaccess(host=args.host,
                  port=args.port,
                  dbname=args.databasename,
                  username=args.username,
                  dbpassword=args.password) as db:
        ebtables = EbTables(db)
        eblist = ebtables.completeupdate(args.atomiccommitfilename)

    if args.debug:
        #        print("wrote temp script to {}".format(DEBUG_LOG_PATH), file=sys.stderr)
        #        with open(DEBUG_LOG_PATH, "w+t") as f:
        for singleline in eblist:
            errorhandler.logdebug(singleline)

    for singleline in eblist:
        print(singleline)
Beispiel #9
0
 def refreshIndoor(self):
     errorhandler.logdebug("SoundFiles::refreshIndoor")
     self.indoor_channel = pygame.mixer.Channel(self.INDOOR_CHANNEL_ID)
     self.indoor_sound = pygame.mixer.Sound(str(self.indoor_file))
Beispiel #10
0
 def initialiseMixer(self):
     pygame.mixer.init(frequency=44100, size=-16, channels=2, buffer=65536)
     pygame.mixer.set_num_channels(2)
     pygame.mixer.set_reserved(2)
     errorhandler.logdebug("SoundFiles::initialiseMixer")
Beispiel #11
0
        #     Configuration.generate_file_if_doesnt_exist(args.initfile)
        configuration.initialise_from_file(args.initfile)
        templogginglevel = logging.DEBUG if args.debug else logging.INFO
        errorhandler.initialise(
            "automationwebserver",
            temppath=configuration.get["General"]["TempLogPath"],
            permpath=configuration.get["General"]["PermanentLogPath"],
            templevel=templogginglevel,
            permlevel=logging.ERROR)

    except:
        errorhandler.exception("caught exception while processing config file")
        raise

    try:
        errorhandler.logdebug("Arguments provided:")
        errorhandler.logdebug(args)
        errorhandler.logdebug("Config file used {}:".format(
            configuration.get_file_path()))
        errorhandler.logdebug(configuration.listall())
    except:
        errorhandler.exception("Caught exception in main")
        raise

    try:
        arduino = arduinointerface.Arduino(configuration)

        if args.testresponse:
            arduino.set_test_response(args.testresponse)

        WAIT_TIME_FOR_REPLY = 10  # seconds to wait for a reply to our request