Ejemplo n.º 1
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()
Ejemplo n.º 2
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))
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
def playTestSoundUntilButtonPressed(testsoundpath):
    errorhandler.loginfo("Playing test sound: {}".format(testsoundpath))
    circuitry.turnOnSpeakers()
    circuitry.status_led.on()
    while (True):
        sound_files = SoundFiles(testsoundpath, None, StereoOutputChannel.BOTH,
                                 StereoOutputChannel.NONE)
        sound_files.play()
        while not sound_files.isFinished():
            time.sleep(1)
        if circuitry.isButtonPressed():
            circuitry.turnOffSpeakers()
            errorhandler.loginfo("Stopped test sound.")
            return
    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)
Ejemplo n.º 6
0
def process_pipe(log_database, inputpipepath):
    """
    process incoming information from the pipe and add to the log
    loops eternally until the pipe breaks
    :param db: LogDatabase to write to
    :param fip: pipe for incoming log information
    :return:
    """
    try:
        with open(inputpipepath, "r") as fip:
            while True:
                line = fip.readline()
                if len(line) == 0:  # I'm not sure - does it block or not?
                    errorhandler.logerror(
                        "readline from pipe {} had zero length.".format(
                            args.inputpipe))
                    return
                try:
                    log_database.add_log_entry_string(line)
                except errorhandler.LogDatabaseError as exc:
                    errorhandler.loginfo(exc)

    except IOError as exc:
        errorhandler.logerror(exc)
Ejemplo n.º 7
0
                    while time.time(
                    ) < last_request_time + WAIT_TIME_FOR_REPLY:
                        gotmsg = arduino.check_for_incoming_info()
                        if gotmsg:
                            break
                        time.sleep(1)
                    errorhandler.logdebug(
                        "got reply" if gotmsg else "timeout waiting for reply")

                except IOError as e:
                    errorhandler.logwarn(
                        "I/O error occurred ({0}): {1}".format(
                            e.errno, e.strerror))
                    next_request_time = last_request_time + WAIT_TIME_IO_ERROR
                except errorhandler.ArduinoMessageError as e:
                    errorhandler.loginfo(e)
                    next_request_time = last_request_time + WAIT_TIME_MSG_ERROR
                except ValueError as e:
                    errorhandler.logwarn(repr(e))
                    next_request_time = last_request_time + WAIT_TIME_MSG_ERROR
            time.sleep(1)

    except:
        errorhandler.exception("Caught exception in main")
        raise
"""
    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)
"""